Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
11 |
HF_API_KEY = "glhf_9ea0e0babe1e45353dd03b44cb979e22"
|
12 |
-
|
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 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
29 |
{"role": "user", "content": text}
|
30 |
],
|
31 |
-
temperature
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
except Exception as e:
|
35 |
print(f"Error summarizing: {e}")
|
36 |
-
|
37 |
|
38 |
def display_news():
|
39 |
-
|
40 |
-
|
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 |
-
|
52 |
-
|
53 |
-
<div class="headline-
|
54 |
-
|
55 |
-
|
|
|
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()
|