openfree commited on
Commit
4c7687e
ยท
verified ยท
1 Parent(s): cdfc55c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -376,7 +376,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
376
  gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด 67๊ฐœ๊ตญ์˜ 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ์ตœ๋Œ€ 1000๊ฐœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
377
 
378
  with gr.Column():
379
- # ์ƒ๋‹จ ๊ณ ์ • ์˜์—ญ
380
  with gr.Column(elem_id="status_area"):
381
  with gr.Row():
382
  query_global = gr.Textbox(label="๊ฒ€์ƒ‰์–ด")
@@ -384,9 +384,8 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
384
 
385
  status_message_global = gr.Markdown("")
386
  translated_query_display_global = gr.Markdown("")
387
- progress_global = gr.Progress(track_tqdm=True)
388
 
389
- # ๊ฒฐ๊ณผ ์ถœ๋ ฅ ์˜์—ญ (์Šคํฌ๋กค ๊ฐ€๋Šฅ)
390
  with gr.Column(elem_id="results_area"):
391
  articles_state_global = gr.State([])
392
 
@@ -407,7 +406,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
407
  'index': i,
408
  })
409
 
410
-
411
  def search_and_display(query, country, articles_state, progress=gr.Progress()):
412
  status_msg = "๊ฒ€์ƒ‰์„ ์ง„ํ–‰์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ฆฌ์„ธ์š”..."
413
 
@@ -463,13 +461,13 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
463
 
464
  return outputs
465
 
466
- def search_global(query, articles_state_global, progress=gr.Progress()):
467
- status_msg = "์ „์„ธ๊ณ„ ๊ฒ€์ƒ‰์„ ์ง„ํ–‰์ค‘์ž…๋‹ˆ๋‹ค. ์‹ค์‹œ๊ฐ„์œผ๋กœ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค..."
468
  all_results = []
469
 
470
  outputs = [
471
  gr.update(value=status_msg, visible=True),
472
- gr.update(value="", visible=False),
473
  ]
474
 
475
  for _ in global_article_components:
@@ -481,10 +479,13 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
481
 
482
  yield outputs
483
 
484
- for idx, (country, location) in enumerate(COUNTRY_LOCATIONS.items()):
485
- progress((idx + 1) / len(COUNTRY_LOCATIONS), f"์ง„ํ–‰ ์ƒํ™ฉ: {idx + 1}/{len(COUNTRY_LOCATIONS)} ๊ตญ๊ฐ€ ๊ฒ€์ƒ‰ ์ค‘... (ํ˜„์žฌ: {country})")
486
-
487
  try:
 
 
 
 
488
  error_message, articles = serphouse_search(query, country)
489
  if not error_message and articles:
490
  for article in articles:
@@ -503,12 +504,10 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
503
 
504
  unique_results = unique_results[:1000]
505
 
506
- outputs = []
507
- outputs.append(gr.update(
508
- value=f"๊ฒ€์ƒ‰ ์ง„ํ–‰ ์ค‘... ({idx + 1}/{len(COUNTRY_LOCATIONS)} ๊ตญ๊ฐ€ ์™„๋ฃŒ)\nํ˜„์žฌ๊นŒ์ง€ ๋ฐœ๊ฒฌ๋œ ๋‰ด์Šค: {len(unique_results)}๊ฑด",
509
- visible=True
510
- ))
511
- outputs.append(gr.update(value=f"**๊ฒ€์ƒ‰์–ด:** {query}", visible=True))
512
 
513
  for idx, comp in enumerate(global_article_components):
514
  if idx < len(unique_results):
@@ -562,12 +561,11 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
562
  show_progress=True
563
  )
564
 
565
- # global_search_outputs ๋ถ€๋ถ„์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •
566
  global_search_outputs = [
567
  status_message_global,
568
- translated_query_display_global, # ์ด์ œ ์ •์˜๋œ ์ปดํฌ๋„ŒํŠธ ์‚ฌ์šฉ
569
  ]
570
-
571
  for comp in global_article_components:
572
  global_search_outputs.extend([
573
  comp['group'], comp['title'], comp['image'],
@@ -578,8 +576,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
578
  search_button_global.click(
579
  search_global,
580
  inputs=[query_global, articles_state_global],
581
- outputs=global_search_outputs,
582
- show_progress=True
583
  )
584
 
585
  iface.launch(auth=("it1","chosun1"))
 
376
  gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด 67๊ฐœ๊ตญ์˜ 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ์ตœ๋Œ€ 1000๊ฐœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
377
 
378
  with gr.Column():
379
+ # ์ƒ๋‹จ ์˜์—ญ
380
  with gr.Column(elem_id="status_area"):
381
  with gr.Row():
382
  query_global = gr.Textbox(label="๊ฒ€์ƒ‰์–ด")
 
384
 
385
  status_message_global = gr.Markdown("")
386
  translated_query_display_global = gr.Markdown("")
 
387
 
388
+ # ๊ฒฐ๊ณผ ์ถœ๋ ฅ ์˜์—ญ
389
  with gr.Column(elem_id="results_area"):
390
  articles_state_global = gr.State([])
391
 
 
406
  'index': i,
407
  })
408
 
 
409
  def search_and_display(query, country, articles_state, progress=gr.Progress()):
410
  status_msg = "๊ฒ€์ƒ‰์„ ์ง„ํ–‰์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ฆฌ์„ธ์š”..."
411
 
 
461
 
462
  return outputs
463
 
464
+ def search_global(query, articles_state_global):
465
+ status_msg = "์ „์„ธ๊ณ„ ๊ฒ€์ƒ‰์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค..."
466
  all_results = []
467
 
468
  outputs = [
469
  gr.update(value=status_msg, visible=True),
470
+ gr.update(value=f"**๊ฒ€์ƒ‰์–ด:** {query}", visible=True),
471
  ]
472
 
473
  for _ in global_article_components:
 
479
 
480
  yield outputs
481
 
482
+ total_countries = len(COUNTRY_LOCATIONS)
483
+ for idx, (country, location) in enumerate(COUNTRY_LOCATIONS.items(), 1):
 
484
  try:
485
+ status_msg = f"{country} ๊ฒ€์ƒ‰ ์ค‘... ({idx}/{total_countries} ๊ตญ๊ฐ€)"
486
+ outputs[0] = gr.update(value=status_msg, visible=True)
487
+ yield outputs
488
+
489
  error_message, articles = serphouse_search(query, country)
490
  if not error_message and articles:
491
  for article in articles:
 
504
 
505
  unique_results = unique_results[:1000]
506
 
507
+ outputs = [
508
+ gr.update(value=f"{idx}/{total_countries} ๊ตญ๊ฐ€ ๊ฒ€์ƒ‰ ์™„๋ฃŒ\nํ˜„์žฌ๊นŒ์ง€ ๋ฐœ๊ฒฌ๋œ ๋‰ด์Šค: {len(unique_results)}๊ฑด", visible=True),
509
+ gr.update(value=f"**๊ฒ€์ƒ‰์–ด:** {query}", visible=True),
510
+ ]
 
 
511
 
512
  for idx, comp in enumerate(global_article_components):
513
  if idx < len(unique_results):
 
561
  show_progress=True
562
  )
563
 
 
564
  global_search_outputs = [
565
  status_message_global,
566
+ translated_query_display_global,
567
  ]
568
+
569
  for comp in global_article_components:
570
  global_search_outputs.extend([
571
  comp['group'], comp['title'], comp['image'],
 
576
  search_button_global.click(
577
  search_global,
578
  inputs=[query_global, articles_state_global],
579
+ outputs=global_search_outputs
 
580
  )
581
 
582
  iface.launch(auth=("it1","chosun1"))