Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -445,7 +445,10 @@ def refresh_hn_stories():
|
|
| 445 |
outputs.extend([
|
| 446 |
gr.update(visible=False),
|
| 447 |
gr.update(),
|
| 448 |
-
gr.update()
|
|
|
|
|
|
|
|
|
|
| 449 |
])
|
| 450 |
|
| 451 |
yield outputs
|
|
@@ -485,13 +488,19 @@ def refresh_hn_stories():
|
|
| 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
|
|
@@ -511,17 +520,82 @@ def refresh_hn_stories():
|
|
| 511 |
**μ μ:** {story.get('score', 0)} |
|
| 512 |
**λκΈ:** {len(story.get('kids', []))}κ°\n
|
| 513 |
**AI μμ½:** {summary}
|
| 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;}
|
| 527 |
#status_area {
|
|
@@ -648,33 +722,37 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI μλΉμ€") as
|
|
| 648 |
'index': i,
|
| 649 |
})
|
| 650 |
|
| 651 |
-
|
| 652 |
-
# AI 리ν¬ν° ν
|
| 653 |
with gr.Tab("AI 리ν¬ν°"):
|
| 654 |
gr.Markdown("μ§λ 24μκ° λμμ Hacker News ν¬μ€νΈλ₯Ό AIκ° μμ½νμ¬ λ³΄μ¬μ€λλ€.")
|
| 655 |
-
|
| 656 |
with gr.Column():
|
| 657 |
refresh_button = gr.Button("μλ‘κ³ μΉ¨", variant="primary")
|
| 658 |
status_message_hn = gr.Markdown("")
|
| 659 |
-
|
| 660 |
with gr.Column(elem_id="hn_results_area"):
|
| 661 |
hn_articles_state = gr.State([])
|
| 662 |
-
|
| 663 |
hn_article_components = []
|
| 664 |
-
for i in range(100):
|
| 665 |
-
with gr.Group(visible=False) as article_group:
|
| 666 |
title = gr.Markdown()
|
| 667 |
info = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
|
| 669 |
hn_article_components.append({
|
| 670 |
'group': article_group,
|
| 671 |
'title': title,
|
| 672 |
'info': info,
|
|
|
|
|
|
|
|
|
|
| 673 |
'index': i,
|
| 674 |
})
|
| 675 |
|
| 676 |
-
|
| 677 |
-
|
| 678 |
|
| 679 |
# κΈ°μ‘΄ ν¨μλ€
|
| 680 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
|
@@ -857,19 +935,24 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI μλΉμ€") as
|
|
| 857 |
outputs=global_search_outputs
|
| 858 |
)
|
| 859 |
|
| 860 |
-
|
| 861 |
hn_outputs = [status_message_hn]
|
| 862 |
for comp in hn_article_components:
|
| 863 |
hn_outputs.extend([
|
| 864 |
comp['group'],
|
| 865 |
comp['title'],
|
| 866 |
-
comp['info']
|
|
|
|
|
|
|
|
|
|
| 867 |
])
|
| 868 |
|
| 869 |
refresh_button.click(
|
| 870 |
refresh_hn_stories,
|
| 871 |
outputs=hn_outputs
|
| 872 |
-
)
|
|
|
|
|
|
|
| 873 |
|
| 874 |
|
| 875 |
iface.launch(
|
|
|
|
| 445 |
outputs.extend([
|
| 446 |
gr.update(visible=False),
|
| 447 |
gr.update(),
|
| 448 |
+
gr.update(),
|
| 449 |
+
gr.update(visible=False), # report_button
|
| 450 |
+
gr.update(visible=False), # show_report
|
| 451 |
+
gr.update(visible=False) # report_content
|
| 452 |
])
|
| 453 |
|
| 454 |
yield outputs
|
|
|
|
| 488 |
**μ μ:** {current_story.get('score', 0)} |
|
| 489 |
**λκΈ:** {len(current_story.get('kids', []))}κ°\n
|
| 490 |
**AI μμ½:** {current_summary}
|
| 491 |
+
"""),
|
| 492 |
+
gr.update(visible=True), # report_button
|
| 493 |
+
gr.update(visible=False), # show_report
|
| 494 |
+
gr.update(visible=False) # report_content
|
| 495 |
])
|
| 496 |
else:
|
| 497 |
outputs.extend([
|
| 498 |
gr.update(visible=False),
|
| 499 |
gr.update(),
|
| 500 |
+
gr.update(),
|
| 501 |
+
gr.update(visible=False),
|
| 502 |
+
gr.update(visible=False),
|
| 503 |
+
gr.update(visible=False)
|
| 504 |
])
|
| 505 |
|
| 506 |
yield outputs
|
|
|
|
| 520 |
**μ μ:** {story.get('score', 0)} |
|
| 521 |
**λκΈ:** {len(story.get('kids', []))}κ°\n
|
| 522 |
**AI μμ½:** {summary}
|
| 523 |
+
"""),
|
| 524 |
+
gr.update(visible=True), # report_button
|
| 525 |
+
gr.update(visible=False), # show_report
|
| 526 |
+
gr.update(visible=False) # report_content
|
| 527 |
])
|
| 528 |
else:
|
| 529 |
final_outputs.extend([
|
| 530 |
gr.update(visible=False),
|
| 531 |
gr.update(),
|
| 532 |
+
gr.update(),
|
| 533 |
+
gr.update(visible=False),
|
| 534 |
+
gr.update(visible=False),
|
| 535 |
+
gr.update(visible=False)
|
| 536 |
])
|
| 537 |
|
| 538 |
yield final_outputs
|
| 539 |
+
|
| 540 |
+
# μ΅μ’
μν μ
λ°μ΄νΈ
|
| 541 |
+
final_outputs = [gr.update(value=f"μ΄ {len(processed_stories)}κ°μ ν¬μ€νΈκ° μ²λ¦¬λμμ΅λλ€.", visible=True)]
|
| 542 |
+
|
| 543 |
+
for idx, comp in enumerate(hn_article_components):
|
| 544 |
+
if idx < len(processed_stories):
|
| 545 |
+
story, summary = processed_stories[idx]
|
| 546 |
+
final_outputs.extend([
|
| 547 |
+
gr.update(visible=True),
|
| 548 |
+
gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
|
| 549 |
+
gr.update(value=f"""
|
| 550 |
+
**μμ±μ:** {story.get('by', 'unknown')} |
|
| 551 |
+
**μκ°:** {format_hn_time(story.get('time', 0))} |
|
| 552 |
+
**μ μ:** {story.get('score', 0)} |
|
| 553 |
+
**λκΈ:** {len(story.get('kids', []))}κ°\n
|
| 554 |
+
**AI μμ½:** {summary}
|
| 555 |
+
"""),
|
| 556 |
+
gr.update(visible=True), # report_button
|
| 557 |
+
gr.update(visible=False), # show_report
|
| 558 |
+
gr.update(visible=False) # report_content
|
| 559 |
+
])
|
| 560 |
+
else:
|
| 561 |
+
final_outputs.extend([
|
| 562 |
+
gr.update(visible=False),
|
| 563 |
+
gr.update(),
|
| 564 |
+
gr.update(),
|
| 565 |
+
gr.update(visible=False),
|
| 566 |
+
gr.update(visible=False),
|
| 567 |
+
gr.update(visible=False)
|
| 568 |
+
])
|
| 569 |
+
|
| 570 |
+
yield final_outputs
|
| 571 |
+
|
| 572 |
+
def generate_report(title, summary):
|
| 573 |
+
"""리ν¬ν
μμ±"""
|
| 574 |
+
prompt = f"""λλ Hacker News ν¬μ€νΈλ₯Ό κΈ°λ°μΌλ‘ 보λ κΈ°μ¬ ννμ 리ν¬ν
μ μμ±νλ μν μ΄λ€.
|
| 575 |
+
λλ λ°λμ νκΈλ‘ 리ν¬ν
νμμ κ°κ΄μ κΈ°μ¬ ννλ‘ μμ±νμ¬μΌ νλ€.
|
| 576 |
+
μμ±μ 6νμμΉμ μ
κ°νκ³ κΈΈμ΄λ 4000ν ν°μ λμ§ μμκ².
|
| 577 |
+
λμ μΆμ²λ λͺ¨λΈ, μ§μλ¬Έ λ±μ λ
ΈμΆνμ§ λ§κ²
|
| 578 |
+
|
| 579 |
+
μ λͺ©: {title}
|
| 580 |
+
λ΄μ©: {summary}
|
| 581 |
+
"""
|
| 582 |
+
|
| 583 |
+
try:
|
| 584 |
+
response = hf_client.text_generation(
|
| 585 |
+
prompt,
|
| 586 |
+
max_new_tokens=4000,
|
| 587 |
+
temperature=0.7,
|
| 588 |
+
repetition_penalty=1.2
|
| 589 |
+
)
|
| 590 |
+
return response
|
| 591 |
+
except Exception as e:
|
| 592 |
+
print(f"Report generation error: {str(e)}")
|
| 593 |
+
return "리ν¬ν
μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€."
|
| 594 |
+
|
| 595 |
+
def toggle_report(report_visible):
|
| 596 |
+
"""리ν¬νΈ νμ/μ¨κΉ ν κΈ"""
|
| 597 |
+
return not report_visible
|
| 598 |
+
|
| 599 |
css = """
|
| 600 |
footer {visibility: hidden;}
|
| 601 |
#status_area {
|
|
|
|
| 722 |
'index': i,
|
| 723 |
})
|
| 724 |
|
|
|
|
|
|
|
| 725 |
with gr.Tab("AI 리ν¬ν°"):
|
| 726 |
gr.Markdown("μ§λ 24μκ° λμμ Hacker News ν¬μ€νΈλ₯Ό AIκ° μμ½νμ¬ λ³΄μ¬μ€λλ€.")
|
| 727 |
+
|
| 728 |
with gr.Column():
|
| 729 |
refresh_button = gr.Button("μλ‘κ³ μΉ¨", variant="primary")
|
| 730 |
status_message_hn = gr.Markdown("")
|
| 731 |
+
|
| 732 |
with gr.Column(elem_id="hn_results_area"):
|
| 733 |
hn_articles_state = gr.State([])
|
| 734 |
+
|
| 735 |
hn_article_components = []
|
| 736 |
+
for i in range(100):
|
| 737 |
+
with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
|
| 738 |
title = gr.Markdown()
|
| 739 |
info = gr.Markdown()
|
| 740 |
+
with gr.Row():
|
| 741 |
+
report_button = gr.Button("리ν¬ν
μμ±", size="sm")
|
| 742 |
+
show_report = gr.Button("νΌμ³ 보기", visible=False)
|
| 743 |
+
report_content = gr.Markdown(visible=False)
|
| 744 |
|
| 745 |
hn_article_components.append({
|
| 746 |
'group': article_group,
|
| 747 |
'title': title,
|
| 748 |
'info': info,
|
| 749 |
+
'report_button': report_button,
|
| 750 |
+
'show_report': show_report,
|
| 751 |
+
'report_content': report_content,
|
| 752 |
'index': i,
|
| 753 |
})
|
| 754 |
|
| 755 |
+
|
|
|
|
| 756 |
|
| 757 |
# κΈ°μ‘΄ ν¨μλ€
|
| 758 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
|
|
|
| 935 |
outputs=global_search_outputs
|
| 936 |
)
|
| 937 |
|
| 938 |
+
# AI 리ν¬ν° ν μ΄λ²€νΈ μ°κ²°
|
| 939 |
hn_outputs = [status_message_hn]
|
| 940 |
for comp in hn_article_components:
|
| 941 |
hn_outputs.extend([
|
| 942 |
comp['group'],
|
| 943 |
comp['title'],
|
| 944 |
+
comp['info'],
|
| 945 |
+
comp['report_button'],
|
| 946 |
+
comp['show_report'],
|
| 947 |
+
comp['report_content']
|
| 948 |
])
|
| 949 |
|
| 950 |
refresh_button.click(
|
| 951 |
refresh_hn_stories,
|
| 952 |
outputs=hn_outputs
|
| 953 |
+
)
|
| 954 |
+
|
| 955 |
+
|
| 956 |
|
| 957 |
|
| 958 |
iface.launch(
|