openfree commited on
Commit
7be2df4
ยท
verified ยท
1 Parent(s): 3d2be9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -12
app.py CHANGED
@@ -436,7 +436,7 @@ def process_hn_story(story, progress=None):
436
  return story, None
437
 
438
  def refresh_hn_stories():
439
- """Hacker News ์Šคํ† ๋ฆฌ ์ƒˆ๋กœ๊ณ ์นจ (๊ฐœ์„ ๋œ ๋ฒ„์ „)"""
440
  status_msg = "Hacker News ํฌ์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘..."
441
  outputs = [gr.update(value=status_msg, visible=True)]
442
 
@@ -452,27 +452,57 @@ def refresh_hn_stories():
452
 
453
  # ์ตœ์‹  ์Šคํ† ๋ฆฌ ๊ฐ€์ ธ์˜ค๊ธฐ
454
  stories = get_recent_stories()
 
455
 
456
- # ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋กœ ์š”์•ฝ ์ƒ์„ฑ
457
  processed_stories = []
458
- with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: # worker ์ˆ˜ ์ฆ๊ฐ€
 
459
  future_to_story = {executor.submit(process_hn_story, story): story
460
- for story in stories[:100]} # 100๊ฐœ๋กœ ์ˆ˜์ •
461
 
462
  for future in concurrent.futures.as_completed(future_to_story):
463
  story, summary = future.result()
 
 
464
  if summary:
465
- processed_stories.append((story, summary))
466
-
467
- # ๊ฒฐ๊ณผ ์ •๋ ฌ ๋ฐ ์ถœ๋ ฅ
468
- processed_stories.sort(key=lambda x: x[0].get('time', 0), reverse=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
 
470
- outputs = [gr.update(value=f"์ด {len(processed_stories)}๊ฐœ์˜ ํฌ์ŠคํŠธ๊ฐ€ ์ฒ˜๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", visible=True)]
 
471
 
472
  for idx, comp in enumerate(hn_article_components):
473
  if idx < len(processed_stories):
474
  story, summary = processed_stories[idx]
475
- outputs.extend([
476
  gr.update(visible=True),
477
  gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
478
  gr.update(value=f"""
@@ -484,13 +514,13 @@ def refresh_hn_stories():
484
  """)
485
  ])
486
  else:
487
- outputs.extend([
488
  gr.update(visible=False),
489
  gr.update(),
490
  gr.update()
491
  ])
492
 
493
- yield outputs
494
 
495
  css = """
496
  footer {visibility: hidden;}
 
436
  return story, None
437
 
438
  def refresh_hn_stories():
439
+ """Hacker News ์Šคํ† ๋ฆฌ ์ƒˆ๋กœ๊ณ ์นจ (์‹ค์‹œ๊ฐ„ ์ถœ๋ ฅ ๋ฒ„์ „)"""
440
  status_msg = "Hacker News ํฌ์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘..."
441
  outputs = [gr.update(value=status_msg, visible=True)]
442
 
 
452
 
453
  # ์ตœ์‹  ์Šคํ† ๋ฆฌ ๊ฐ€์ ธ์˜ค๊ธฐ
454
  stories = get_recent_stories()
455
+ processed_count = 0
456
 
457
+ # ์‹ค์‹œ๊ฐ„ ์ฒ˜๋ฆฌ ๋ฐ ์ถœ๋ ฅ์„ ์œ„ํ•œ ๋ฆฌ์ŠคํŠธ
458
  processed_stories = []
459
+
460
+ with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
461
  future_to_story = {executor.submit(process_hn_story, story): story
462
+ for story in stories[:100]}
463
 
464
  for future in concurrent.futures.as_completed(future_to_story):
465
  story, summary = future.result()
466
+ processed_count += 1
467
+
468
  if summary:
469
+ # ์ƒˆ๋กœ์šด ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌ์ŠคํŠธ ๋งจ ์•ž์— ์ถ”๊ฐ€
470
+ processed_stories.insert(0, (story, summary))
471
+
472
+ # ํ˜„์žฌ๊นŒ์ง€์˜ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
473
+ outputs = [gr.update(value=f"์ฒ˜๋ฆฌ ์ค‘... ({processed_count}/{len(stories)})", visible=True)]
474
+
475
+ # ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ ์—…๋ฐ์ดํŠธ
476
+ for idx, comp in enumerate(hn_article_components):
477
+ if idx < len(processed_stories):
478
+ current_story, current_summary = processed_stories[idx]
479
+ outputs.extend([
480
+ gr.update(visible=True),
481
+ gr.update(value=f"### [{current_story.get('title', 'Untitled')}]({current_story.get('url', '#')})"),
482
+ gr.update(value=f"""
483
+ **์ž‘์„ฑ์ž:** {current_story.get('by', 'unknown')} |
484
+ **์‹œ๊ฐ„:** {format_hn_time(current_story.get('time', 0))} |
485
+ **์ ์ˆ˜:** {current_story.get('score', 0)} |
486
+ **๋Œ“๊ธ€:** {len(current_story.get('kids', []))}๊ฐœ\n
487
+ **AI ์š”์•ฝ:** {current_summary}
488
+ """)
489
+ ])
490
+ else:
491
+ outputs.extend([
492
+ gr.update(visible=False),
493
+ gr.update(),
494
+ gr.update()
495
+ ])
496
+
497
+ yield outputs
498
 
499
+ # ์ตœ์ข… ์ƒํƒœ ์—…๋ฐ์ดํŠธ
500
+ final_outputs = [gr.update(value=f"์ด {len(processed_stories)}๊ฐœ์˜ ํฌ์ŠคํŠธ๊ฐ€ ์ฒ˜๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", visible=True)]
501
 
502
  for idx, comp in enumerate(hn_article_components):
503
  if idx < len(processed_stories):
504
  story, summary = processed_stories[idx]
505
+ final_outputs.extend([
506
  gr.update(visible=True),
507
  gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
508
  gr.update(value=f"""
 
514
  """)
515
  ])
516
  else:
517
+ final_outputs.extend([
518
  gr.update(visible=False),
519
  gr.update(),
520
  gr.update()
521
  ])
522
 
523
+ yield final_outputs
524
 
525
  css = """
526
  footer {visibility: hidden;}