Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -569,28 +569,55 @@ def refresh_hn_stories():
|
|
569 |
|
570 |
yield final_outputs
|
571 |
|
572 |
-
def generate_report(title,
|
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.
|
588 |
-
repetition_penalty=1.2
|
|
|
589 |
)
|
590 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
except Exception as e:
|
592 |
print(f"Report generation error: {str(e)}")
|
593 |
-
return
|
|
|
|
|
|
|
594 |
|
595 |
def toggle_report(report_content):
|
596 |
"""리ν¬νΈ νμ/μ¨κΉ ν κΈ"""
|
@@ -739,9 +766,10 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI μλΉμ€") as
|
|
739 |
title = gr.Markdown()
|
740 |
info = gr.Markdown()
|
741 |
with gr.Row():
|
742 |
-
report_button = gr.Button("리ν¬ν
μμ±", size="sm")
|
743 |
-
show_report = gr.Button("νΌμ³ 보기", visible=False)
|
744 |
-
|
|
|
745 |
|
746 |
hn_article_components.append({
|
747 |
'group': article_group,
|
@@ -749,10 +777,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI μλΉμ€") as
|
|
749 |
'info': info,
|
750 |
'report_button': report_button,
|
751 |
'show_report': show_report,
|
|
|
752 |
'report_content': report_content,
|
753 |
'index': i,
|
754 |
})
|
755 |
|
|
|
756 |
|
757 |
|
758 |
# κΈ°μ‘΄ ν¨μλ€
|
|
|
569 |
|
570 |
yield final_outputs
|
571 |
|
572 |
+
def generate_report(title, info, progress=gr.Progress()):
|
573 |
"""리ν¬ν
μμ±"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
574 |
try:
|
575 |
+
progress(0.1, desc="리ν¬ν
μμ± μ€λΉ μ€...")
|
576 |
+
|
577 |
+
# HTML νκ·Έ μ κ±°
|
578 |
+
title_text = re.sub(r'#*\s*\[(.*?)\].*', r'\1', title)
|
579 |
+
info_text = re.sub(r'\*\*(.*?)\*\*', r'\1', info)
|
580 |
+
|
581 |
+
progress(0.3, desc="ν둬ννΈ μμ± μ€...")
|
582 |
+
|
583 |
+
prompt = f"""λλ Hacker News ν¬μ€νΈλ₯Ό κΈ°λ°μΌλ‘ 보λ κΈ°μ¬ ννμ 리ν¬ν
μ μμ±νλ μν μ΄λ€.
|
584 |
+
λλ λ°λμ νκΈλ‘ 리ν¬ν
νμμ κ°κ΄μ κΈ°μ¬ ννλ‘ μμ±νμ¬μΌ νλ€.
|
585 |
+
μμ±μ 6νμμΉμ μ
κ°νκ³ κΈΈμ΄λ 4000ν ν°μ λμ§ μμκ².
|
586 |
+
λμ μΆμ²λ λͺ¨λΈ, μ§μλ¬Έ λ±μ λ
ΈμΆνμ§ λ§κ²
|
587 |
+
|
588 |
+
μ λͺ©: {title_text}
|
589 |
+
λ΄μ©: {info_text}
|
590 |
+
"""
|
591 |
+
|
592 |
+
progress(0.5, desc="AI λͺ¨λΈ μ²λ¦¬ μ€...")
|
593 |
+
|
594 |
response = hf_client.text_generation(
|
595 |
prompt,
|
596 |
max_new_tokens=4000,
|
597 |
+
temperature=0.3,
|
598 |
+
repetition_penalty=1.2,
|
599 |
+
timeout=300 # νμμμ 5λΆμΌλ‘ μ¦κ°
|
600 |
)
|
601 |
+
|
602 |
+
progress(0.8, desc="κ²°κ³Ό μ²λ¦¬ μ€...")
|
603 |
+
|
604 |
+
if response:
|
605 |
+
return {
|
606 |
+
report_content: gr.update(value=response, visible=True),
|
607 |
+
show_report: gr.update(value="μ κΈ°", visible=True)
|
608 |
+
}
|
609 |
+
else:
|
610 |
+
return {
|
611 |
+
report_content: gr.update(value="리ν¬ν
μμ±μ μ€ν¨νμ΅λλ€.", visible=True),
|
612 |
+
show_report: gr.update(value="μ κΈ°", visible=True)
|
613 |
+
}
|
614 |
+
|
615 |
except Exception as e:
|
616 |
print(f"Report generation error: {str(e)}")
|
617 |
+
return {
|
618 |
+
report_content: gr.update(value="리ν¬ν
μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€.", visible=True),
|
619 |
+
show_report: gr.update(value="μ κΈ°", visible=True)
|
620 |
+
}
|
621 |
|
622 |
def toggle_report(report_content):
|
623 |
"""리ν¬νΈ νμ/μ¨κΉ ν κΈ"""
|
|
|
766 |
title = gr.Markdown()
|
767 |
info = gr.Markdown()
|
768 |
with gr.Row():
|
769 |
+
report_button = gr.Button("리ν¬ν
μμ±", size="sm", variant="primary")
|
770 |
+
show_report = gr.Button("νΌμ³ 보기", size="sm", visible=False)
|
771 |
+
with gr.Column(visible=False) as report_section:
|
772 |
+
report_content = gr.Markdown()
|
773 |
|
774 |
hn_article_components.append({
|
775 |
'group': article_group,
|
|
|
777 |
'info': info,
|
778 |
'report_button': report_button,
|
779 |
'show_report': show_report,
|
780 |
+
'report_section': report_section,
|
781 |
'report_content': report_content,
|
782 |
'index': i,
|
783 |
})
|
784 |
|
785 |
+
|
786 |
|
787 |
|
788 |
# κΈ°μ‘΄ ν¨μλ€
|