Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -145,6 +145,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
145 |
country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ", value="South Korea")
|
146 |
search_button = gr.Button("๊ฒ์")
|
147 |
|
|
|
|
|
|
|
148 |
# ๊ธฐ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ์ํ ๋ณ์
|
149 |
articles_state = gr.State([]) # ์ด๊ธฐ๊ฐ์ ๋น ๋ฆฌ์คํธ๋ก ์ค์
|
150 |
|
@@ -171,6 +174,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
171 |
})
|
172 |
|
173 |
def search_and_display(query, country, articles_state):
|
|
|
|
|
|
|
174 |
error_message, articles = serphouse_search(query, country)
|
175 |
outputs = []
|
176 |
if error_message:
|
@@ -216,6 +222,8 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
216 |
])
|
217 |
articles_state = articles # articles_state ์
๋ฐ์ดํธ
|
218 |
outputs.append(articles_state)
|
|
|
|
|
219 |
return outputs
|
220 |
|
221 |
# search_button ํด๋ฆญ ์ ์
๋ฐ์ดํธ๋ ์ถ๋ ฅ ์ปดํฌ๋ํธ ๋ชฉ๋ก ์์ฑ
|
@@ -230,29 +238,37 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
230 |
search_outputs.append(comp['info'])
|
231 |
search_outputs.append(comp['summary_output'])
|
232 |
search_outputs.append(articles_state)
|
|
|
233 |
|
234 |
search_button.click(
|
235 |
search_and_display,
|
236 |
inputs=[query, country, articles_state],
|
237 |
-
outputs=search_outputs
|
|
|
238 |
)
|
239 |
|
240 |
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์ค์
|
241 |
for idx, comp in enumerate(article_components):
|
242 |
def create_analyze_function(index=idx):
|
243 |
def analyze_article(articles):
|
|
|
|
|
244 |
if articles and index < len(articles):
|
245 |
article = articles[index]
|
246 |
summary = summarize_article(article['title'], article['snippet'])
|
247 |
-
|
|
|
248 |
else:
|
249 |
-
|
|
|
250 |
return analyze_article
|
251 |
|
|
|
252 |
comp['analyze_button'].click(
|
253 |
create_analyze_function(),
|
254 |
inputs=[articles_state],
|
255 |
-
outputs=comp['summary_output']
|
|
|
256 |
)
|
257 |
|
258 |
iface.launch(auth=("gini", "pick"))
|
|
|
145 |
country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ", value="South Korea")
|
146 |
search_button = gr.Button("๊ฒ์")
|
147 |
|
148 |
+
# ์ํ ๋ฉ์์ง ์ปดํฌ๋ํธ ์ถ๊ฐ
|
149 |
+
status_message = gr.Markdown(visible=False)
|
150 |
+
|
151 |
# ๊ธฐ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ์ํ ๋ณ์
|
152 |
articles_state = gr.State([]) # ์ด๊ธฐ๊ฐ์ ๋น ๋ฆฌ์คํธ๋ก ์ค์
|
153 |
|
|
|
174 |
})
|
175 |
|
176 |
def search_and_display(query, country, articles_state):
|
177 |
+
# ์ํ ๋ฉ์์ง ํ์
|
178 |
+
status_update = gr.update(value="์ฒ๋ฆฌ์ค์
๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ฆฌ์ธ์.", visible=True)
|
179 |
+
|
180 |
error_message, articles = serphouse_search(query, country)
|
181 |
outputs = []
|
182 |
if error_message:
|
|
|
222 |
])
|
223 |
articles_state = articles # articles_state ์
๋ฐ์ดํธ
|
224 |
outputs.append(articles_state)
|
225 |
+
# ์ํ ๋ฉ์์ง ์จ๊น
|
226 |
+
outputs.append(gr.update(visible=False))
|
227 |
return outputs
|
228 |
|
229 |
# search_button ํด๋ฆญ ์ ์
๋ฐ์ดํธ๋ ์ถ๋ ฅ ์ปดํฌ๋ํธ ๋ชฉ๋ก ์์ฑ
|
|
|
238 |
search_outputs.append(comp['info'])
|
239 |
search_outputs.append(comp['summary_output'])
|
240 |
search_outputs.append(articles_state)
|
241 |
+
search_outputs.append(status_message) # ์ํ ๋ฉ์์ง ์ถ๋ ฅ์ ์ถ๊ฐ
|
242 |
|
243 |
search_button.click(
|
244 |
search_and_display,
|
245 |
inputs=[query, country, articles_state],
|
246 |
+
outputs=search_outputs,
|
247 |
+
show_progress=False # Gradio์ ๊ธฐ๋ณธ ๋ก๋ฉ ํ์๋ฅผ ๋๋๋ค.
|
248 |
)
|
249 |
|
250 |
# ๋ถ์ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ ์ค์
|
251 |
for idx, comp in enumerate(article_components):
|
252 |
def create_analyze_function(index=idx):
|
253 |
def analyze_article(articles):
|
254 |
+
# ์ํ ๋ฉ์์ง ํ์
|
255 |
+
status_update = gr.update(value="์ฒ๋ฆฌ์ค์
๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ฆฌ์ธ์.", visible=True)
|
256 |
if articles and index < len(articles):
|
257 |
article = articles[index]
|
258 |
summary = summarize_article(article['title'], article['snippet'])
|
259 |
+
# ์ํ ๋ฉ์์ง ์จ๊น
|
260 |
+
return gr.update(value=summary, visible=True), gr.update(visible=False)
|
261 |
else:
|
262 |
+
# ์ํ ๋ฉ์์ง ์จ๊น
|
263 |
+
return gr.update(value="๊ธฐ์ฌ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.", visible=True), gr.update(visible=False)
|
264 |
return analyze_article
|
265 |
|
266 |
+
# ๋ถ์ ๋ฒํผ์ ์ถ๋ ฅ์ ์ํ ๋ฉ์์ง๋ฅผ ์ถ๊ฐํฉ๋๋ค.
|
267 |
comp['analyze_button'].click(
|
268 |
create_analyze_function(),
|
269 |
inputs=[articles_state],
|
270 |
+
outputs=[comp['summary_output'], status_message],
|
271 |
+
show_progress=False # Gradio์ ๊ธฐ๋ณธ ๋ก๋ฉ ํ์๋ฅผ ๋๋๋ค.
|
272 |
)
|
273 |
|
274 |
iface.launch(auth=("gini", "pick"))
|