Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -135,7 +135,7 @@ footer {
|
|
135 |
"""
|
136 |
|
137 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
138 |
-
with gr.Blocks(
|
139 |
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ๊ตญ๊ฐ๋ฅผ ์ ํํ๋ฉด, ๊ฒ์์ด์ ์ผ์นํ๋ 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ์ต๋ 10๊ฐ ์ถ๋ ฅํฉ๋๋ค.")
|
140 |
|
141 |
with gr.Column():
|
@@ -144,6 +144,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
144 |
country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ", value="South Korea")
|
145 |
search_button = gr.Button("๊ฒ์")
|
146 |
|
|
|
|
|
|
|
147 |
# ๊ธฐ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ์ํ ๋ณ์
|
148 |
articles_state = gr.State([]) # ์ด๊ธฐ๊ฐ์ ๋น ๋ฆฌ์คํธ๋ก ์ค์
|
149 |
|
@@ -170,47 +173,14 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
170 |
})
|
171 |
|
172 |
def search_and_display(query, country, articles_state):
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
if error_message:
|
182 |
-
outputs.append(gr.update(value=error_message, visible=True))
|
183 |
-
for comp in article_components:
|
184 |
-
outputs.extend([
|
185 |
-
gr.update(visible=False), # group
|
186 |
-
gr.update(), # title
|
187 |
-
gr.update(), # image
|
188 |
-
gr.update(), # snippet
|
189 |
-
gr.update(), # info
|
190 |
-
gr.update(visible=False), # summary_output
|
191 |
-
])
|
192 |
-
articles_state = []
|
193 |
-
else:
|
194 |
-
outputs.append(gr.update(value="", visible=False))
|
195 |
-
for idx, comp in enumerate(article_components):
|
196 |
-
if idx < len(articles):
|
197 |
-
article = articles[idx]
|
198 |
-
# ์ด๋ฏธ์ง ์ฒ๋ฆฌ ์์
|
199 |
-
image_url = article['image_url']
|
200 |
-
if image_url and not image_url.startswith('data:image'):
|
201 |
-
image_update = gr.update(value=image_url, visible=True)
|
202 |
-
else:
|
203 |
-
image_update = gr.update(value=None, visible=False)
|
204 |
-
|
205 |
-
outputs.extend([
|
206 |
-
gr.update(visible=True), # group
|
207 |
-
gr.update(value=f"### [{article['title']}]({article['link']})"), # title
|
208 |
-
image_update, # image
|
209 |
-
gr.update(value=f"**์์ฝ:** {article['snippet']}"), # snippet
|
210 |
-
gr.update(value=f"**์ถ์ฒ:** {article['channel']} | **์๊ฐ:** {article['time']}"), # info
|
211 |
-
gr.update(visible=False), # summary_output
|
212 |
-
])
|
213 |
-
else:
|
214 |
outputs.extend([
|
215 |
gr.update(visible=False), # group
|
216 |
gr.update(), # title
|
@@ -219,9 +189,39 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
219 |
gr.update(), # info
|
220 |
gr.update(visible=False), # summary_output
|
221 |
])
|
222 |
-
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
return outputs
|
226 |
|
227 |
# search_button ํด๋ฆญ ์ ์
๋ฐ์ดํธ๋ ์ถ๋ ฅ ์ปดํฌ๋ํธ ๋ชฉ๋ก ์์ฑ
|
@@ -236,6 +236,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
236 |
search_outputs.append(comp['info'])
|
237 |
search_outputs.append(comp['summary_output'])
|
238 |
search_outputs.append(articles_state)
|
|
|
239 |
|
240 |
search_button.click(
|
241 |
search_and_display,
|
@@ -247,16 +248,14 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
247 |
for idx, comp in enumerate(article_components):
|
248 |
def create_analyze_function(index=idx):
|
249 |
def analyze_article(articles):
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
progress(100) # ์งํ๋ฅ 100%๋ก ์
๋ฐ์ดํธ
|
259 |
-
return gr.update(value="๊ธฐ์ฌ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.", visible=True)
|
260 |
return analyze_article
|
261 |
|
262 |
comp['analyze_button'].click(
|
|
|
135 |
"""
|
136 |
|
137 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
138 |
+
with gr.Blocks(css=css, title="NewsAI ์๋น์ค") as iface:
|
139 |
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ๊ตญ๊ฐ๋ฅผ ์ ํํ๋ฉด, ๊ฒ์์ด์ ์ผ์นํ๋ 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ์ต๋ 10๊ฐ ์ถ๋ ฅํฉ๋๋ค.")
|
140 |
|
141 |
with gr.Column():
|
|
|
144 |
country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ", value="South Korea")
|
145 |
search_button = gr.Button("๊ฒ์")
|
146 |
|
147 |
+
# ์ํ ๋ฉ์์ง ์ปดํฌ๋ํธ ์ ๊ฑฐ (Progress๋ฅผ ์ฌ์ฉํ๋ฏ๋ก ๋ถํ์)
|
148 |
+
# status_message = gr.Markdown(visible=False)
|
149 |
+
|
150 |
# ๊ธฐ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ์ํ ๋ณ์
|
151 |
articles_state = gr.State([]) # ์ด๊ธฐ๊ฐ์ ๋น ๋ฆฌ์คํธ๋ก ์ค์
|
152 |
|
|
|
173 |
})
|
174 |
|
175 |
def search_and_display(query, country, articles_state):
|
176 |
+
with gr.Progress() as progress:
|
177 |
+
progress(0, desc="์ฒ๋ฆฌ์ค์
๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ฆฌ์ธ์.")
|
178 |
+
|
179 |
+
error_message, articles = serphouse_search(query, country)
|
180 |
+
outputs = []
|
181 |
+
if error_message:
|
182 |
+
outputs.append(gr.update(value=error_message, visible=True))
|
183 |
+
for comp in article_components:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
outputs.extend([
|
185 |
gr.update(visible=False), # group
|
186 |
gr.update(), # title
|
|
|
189 |
gr.update(), # info
|
190 |
gr.update(visible=False), # summary_output
|
191 |
])
|
192 |
+
articles_state = []
|
193 |
+
else:
|
194 |
+
outputs.append(gr.update(value="", visible=False))
|
195 |
+
for idx, comp in enumerate(article_components):
|
196 |
+
if idx < len(articles):
|
197 |
+
article = articles[idx]
|
198 |
+
# ์ด๋ฏธ์ง ์ฒ๋ฆฌ ์์
|
199 |
+
image_url = article['image_url']
|
200 |
+
if image_url and not image_url.startswith('data:image'):
|
201 |
+
image_update = gr.update(value=image_url, visible=True)
|
202 |
+
else:
|
203 |
+
image_update = gr.update(value=None, visible=False)
|
204 |
+
|
205 |
+
outputs.extend([
|
206 |
+
gr.update(visible=True), # group
|
207 |
+
gr.update(value=f"### [{article['title']}]({article['link']})"), # title
|
208 |
+
image_update, # image
|
209 |
+
gr.update(value=f"**์์ฝ:** {article['snippet']}"), # snippet
|
210 |
+
gr.update(value=f"**์ถ์ฒ:** {article['channel']} | **์๊ฐ:** {article['time']}"), # info
|
211 |
+
gr.update(visible=False), # summary_output
|
212 |
+
])
|
213 |
+
else:
|
214 |
+
outputs.extend([
|
215 |
+
gr.update(visible=False), # group
|
216 |
+
gr.update(), # title
|
217 |
+
gr.update(), # image
|
218 |
+
gr.update(), # snippet
|
219 |
+
gr.update(), # info
|
220 |
+
gr.update(visible=False), # summary_output
|
221 |
+
])
|
222 |
+
articles_state = articles # articles_state ์
๋ฐ์ดํธ
|
223 |
+
outputs.append(articles_state)
|
224 |
+
# ์ํ ๋ฉ์์ง ์จ๊น (Progress๋ ์๋์ผ๋ก ์ฌ๋ผ์ง๋๋ค)
|
225 |
return outputs
|
226 |
|
227 |
# search_button ํด๋ฆญ ์ ์
๋ฐ์ดํธ๋ ์ถ๋ ฅ ์ปดํฌ๋ํธ ๋ชฉ๋ก ์์ฑ
|
|
|
236 |
search_outputs.append(comp['info'])
|
237 |
search_outputs.append(comp['summary_output'])
|
238 |
search_outputs.append(articles_state)
|
239 |
+
# status_message ์ปดํฌ๋ํธ ์ ๊ฑฐ
|
240 |
|
241 |
search_button.click(
|
242 |
search_and_display,
|
|
|
248 |
for idx, comp in enumerate(article_components):
|
249 |
def create_analyze_function(index=idx):
|
250 |
def analyze_article(articles):
|
251 |
+
with gr.Progress() as progress:
|
252 |
+
progress(0, desc="์ฒ๋ฆฌ์ค์
๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ฆฌ์ธ์.")
|
253 |
+
if articles and index < len(articles):
|
254 |
+
article = articles[index]
|
255 |
+
summary = summarize_article(article['title'], article['snippet'])
|
256 |
+
return gr.update(value=summary, visible=True)
|
257 |
+
else:
|
258 |
+
return gr.update(value="๊ธฐ์ฌ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.", visible=True)
|
|
|
|
|
259 |
return analyze_article
|
260 |
|
261 |
comp['analyze_button'].click(
|