Spaces:
Building
Building
Update app.py
Browse files
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 |
-
|
|
|
459 |
future_to_story = {executor.submit(process_hn_story, story): story
|
460 |
-
for story in stories[:100]}
|
461 |
|
462 |
for future in concurrent.futures.as_completed(future_to_story):
|
463 |
story, summary = future.result()
|
|
|
|
|
464 |
if summary:
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
|
470 |
-
|
|
|
471 |
|
472 |
for idx, comp in enumerate(hn_article_components):
|
473 |
if idx < len(processed_stories):
|
474 |
story, summary = processed_stories[idx]
|
475 |
-
|
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 |
-
|
488 |
gr.update(visible=False),
|
489 |
gr.update(),
|
490 |
gr.update()
|
491 |
])
|
492 |
|
493 |
-
yield
|
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;}
|