Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
e800db0
ยท
verified ยท
1 Parent(s): 1ac6a1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
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
- return gr.update(value=summary, visible=True)
 
248
  else:
249
- return gr.update(value="๊ธฐ์‚ฌ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", visible=True)
 
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"))