Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app2.py +135 -0
- requirements.txt +4 -0
app2.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
68 |
+
background-color: rgba(255, 255, 255, 0.9);
|
69 |
+
padding: 15px 20px;
|
70 |
+
margin: 15px 0;
|
71 |
+
border-radius: 3px;
|
72 |
+
text-align: center;
|
73 |
+
}
|
74 |
+
.headline-text {
|
75 |
+
color: #000000;
|
76 |
+
font-size: 40px;
|
77 |
+
font-weight: bold;
|
78 |
+
font-family: 'Noto Sans KR', sans-serif;
|
79 |
+
}
|
80 |
+
.stApp {
|
81 |
+
background-image: url("https://huggingface.co/spaces/JAMESPARK3/headlineai/resolve/main/news.jpg");
|
82 |
+
background-size: cover;
|
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()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
requests
|
3 |
+
httpx
|
4 |
+
openai
|