JAMESPARK3 commited on
Commit
459055d
ยท
verified ยท
1 Parent(s): cd00e68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -26
app.py CHANGED
@@ -1,61 +1,67 @@
1
- import os
2
  import streamlit as st
3
- import openai
4
  import requests
 
5
 
6
- # Mediastack API ์„ค์ •
7
  MEDIASTACK_API_KEY = "4b15f5b4bc2d12500c65817f202c500c"
8
  MEDIASTACK_URL = f"https://api.mediastack.com/v1/news?access_key={MEDIASTACK_API_KEY}&countries=kr"
9
 
10
- # GLHF API ์„ค์ •
11
  HF_API_KEY = "glhf_9ea0e0babe1e45353dd03b44cb979e22"
12
- openai.api_key = HF_API_KEY
13
- openai.api_base = "https://glhf.chat/api/openai/v1"
14
 
15
  def get_news():
16
- """๋‰ด์Šค ๊ฐ€์ ธ์˜ค๊ธฐ"""
17
  response = requests.get(MEDIASTACK_URL)
18
  if response.status_code == 200:
19
  return response.json().get('data', [])
20
  return []
21
 
22
  def summarize_with_hf(text):
23
- """๋‰ด์Šค ์ œ๋ชฉ ์š”์•ฝ"""
24
  try:
25
- completion = openai.ChatCompletion.create(
26
- model="hf:Nexusflow/Athene-V2-Chat",
27
- messages=[
28
- {"role": "system", "content": "๋‰ด์Šค ์ œ๋ชฉ์„ 20์ž ์ด๋‚ด์˜ ํ•œ๊ตญ์–ด๋กœ ์š”์•ฝํ•ด ์ฃผ์„ธ์š”. ์ค‘๊ตญ์–ด๋Š” ์ ˆ๋Œ€ ์‚ฌ์šฉํ•˜์ง€ ๋ง๊ณ , Note๋ฅผ ํ‘œ์‹œํ•˜์ง€ ๋งˆ์„ธ์š”."},
 
29
  {"role": "user", "content": text}
30
  ],
31
- temperature=0.5
32
- )
33
- return completion.choices[0].message['content'].strip()
 
 
 
 
 
 
34
  except Exception as e:
35
  print(f"Error summarizing: {e}")
36
- return "์š”์•ฝ ์‹คํŒจ"
37
 
38
  def display_news():
39
- """๋‰ด์Šค ์ถœ๋ ฅ"""
40
- news_items = get_news()[:5] # ์ƒ์œ„ 5๊ฐœ์˜ ๋‰ด์Šค๋งŒ ํ‘œ์‹œ
41
  if not news_items:
42
  st.warning("๋‰ด์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
43
  return
44
-
45
  for item in news_items:
46
  original_title = item.get('title', '')
47
  if not original_title:
48
  continue
49
-
50
  summarized_title = summarize_with_hf(original_title)
51
- st.markdown(f'''
52
- <div class="headline-container">
53
- <div class="headline-text">{summarized_title}</div>
54
- </div>
55
- ''', unsafe_allow_html=True)
 
56
 
57
  def main():
58
  st.set_page_config(layout="wide")
 
59
  st.markdown("""
60
  <style>
61
  .headline-container {
@@ -77,10 +83,53 @@ def main():
77
  background-repeat: no-repeat;
78
  background-position: center;
79
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  </style>
81
  """, unsafe_allow_html=True)
82
 
83
  display_news()
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  if __name__ == "__main__":
86
- main()
 
 
1
  import streamlit as st
 
2
  import requests
3
+ import httpx
4
 
5
+ # Mediastack API configuration
6
  MEDIASTACK_API_KEY = "4b15f5b4bc2d12500c65817f202c500c"
7
  MEDIASTACK_URL = f"https://api.mediastack.com/v1/news?access_key={MEDIASTACK_API_KEY}&countries=kr"
8
 
9
+ # HF Nexusflow API configuration
10
  HF_API_KEY = "glhf_9ea0e0babe1e45353dd03b44cb979e22"
11
+ HF_BASE_URL = "https://glhf.chat/api/openai/v1"
 
12
 
13
  def get_news():
 
14
  response = requests.get(MEDIASTACK_URL)
15
  if response.status_code == 200:
16
  return response.json().get('data', [])
17
  return []
18
 
19
  def summarize_with_hf(text):
20
+ """์š”์•ฝ ์ž‘์—…์„ ์œ„ํ•ด HF Nexusflow ๋ชจ๋ธ ํ˜ธ์ถœ"""
21
  try:
22
+ client = httpx.Client(follow_redirects=True, timeout=30.0)
23
+ payload = {
24
+ "model": "hf:Nexusflow/Athene-V2-Chat",
25
+ "messages": [
26
+ {"role": "system", "content": "๋‰ด์Šค ์ œ๋ชฉ์„ 20์ž ์ด๋‚ด์˜ ํ•œ๊ตญ์–ด๋กœ ์š”์•ฝํ•ด ์ฃผ์„ธ์š”.์ค‘๊ตญ์–ด๋Š” ์ ˆ๋Œ€ ์‚ฌ์šฉํ•˜์ง€ ๋ง๊ณ , Note๋ฅผ ํ‘œ์‹œํ•˜์ง€ ๋งˆ์„ธ์š”"},
27
  {"role": "user", "content": text}
28
  ],
29
+ "temperature": 0.5
30
+ }
31
+ headers = {
32
+ "Authorization": f"Bearer {HF_API_KEY}",
33
+ "Content-Type": "application/json"
34
+ }
35
+ response = client.post(f"{HF_BASE_URL}/chat/completions", json=payload, headers=headers)
36
+ if response.status_code == 200:
37
+ return response.json()["choices"][0]["message"]["content"].strip()
38
  except Exception as e:
39
  print(f"Error summarizing: {e}")
40
+ return "์š”์•ฝ ์‹คํŒจ"
41
 
42
  def display_news():
43
+ news_items = get_news()[:5] # Limit to 5 news items
44
+
45
  if not news_items:
46
  st.warning("๋‰ด์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
47
  return
48
+
49
  for item in news_items:
50
  original_title = item.get('title', '')
51
  if not original_title:
52
  continue
53
+
54
  summarized_title = summarize_with_hf(original_title)
55
+ if summarized_title:
56
+ st.markdown(f'''
57
+ <div class="headline-container">
58
+ <div class="headline-text">{summarized_title}</div>
59
+ </div>
60
+ ''', unsafe_allow_html=True)
61
 
62
  def main():
63
  st.set_page_config(layout="wide")
64
+
65
  st.markdown("""
66
  <style>
67
  .headline-container {
 
83
  background-repeat: no-repeat;
84
  background-position: center;
85
  }
86
+ #clock-container {
87
+ position: fixed;
88
+ bottom: 0;
89
+ left: 0;
90
+ right: 0;
91
+ z-index: 1000;
92
+ width: 100%;
93
+ max-width: 1200px;
94
+ margin: 0 auto;
95
+ padding: 0 20px;
96
+ text-align: center;
97
+ height: 300px;
98
+ display: flex;
99
+ align-items: center;
100
+ justify-content: center;
101
+ }
102
+ #clock {
103
+ font-size: 15em;
104
+ font-weight: bold;
105
+ color: black;
106
+ line-height: 1.2;
107
+ white-space: nowrap;
108
+ }
109
  </style>
110
  """, unsafe_allow_html=True)
111
 
112
  display_news()
113
 
114
+ st.markdown("""
115
+ <div id="clock-container">
116
+ <span id="clock"></span>
117
+ </div>
118
+ <script>
119
+ function updateClock() {
120
+ const now = new Date();
121
+ const options = {
122
+ timeZone: 'Asia/Seoul',
123
+ hour12: true,
124
+ hour: 'numeric',
125
+ minute: '2-digit'
126
+ };
127
+ document.getElementById('clock').textContent = now.toLocaleTimeString('ko-KR', options);
128
+ }
129
+ setInterval(updateClock, 1000);
130
+ updateClock();
131
+ </script>
132
+ """, unsafe_allow_html=True)
133
+
134
  if __name__ == "__main__":
135
+ main()