Update app.py
Browse files
app.py
CHANGED
@@ -574,9 +574,10 @@ def generate_report(title, info, progress=gr.Progress()):
|
|
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'\*\*(.*?)
|
|
|
580 |
|
581 |
progress(0.3, desc="ํ๋กฌํํธ ์์ฑ ์ค...")
|
582 |
|
@@ -598,25 +599,13 @@ def generate_report(title, info, progress=gr.Progress()):
|
|
598 |
repetition_penalty=1.2
|
599 |
)
|
600 |
|
601 |
-
progress(0
|
|
|
|
|
602 |
|
603 |
-
if response:
|
604 |
-
return [
|
605 |
-
gr.update(value=response, visible=True),
|
606 |
-
gr.update(value="์ ๊ธฐ", visible=True)
|
607 |
-
]
|
608 |
-
else:
|
609 |
-
return [
|
610 |
-
gr.update(value="๋ฆฌํฌํ
์์ฑ์ ์คํจํ์ต๋๋ค.", visible=True),
|
611 |
-
gr.update(value="์ ๊ธฐ", visible=True)
|
612 |
-
]
|
613 |
-
|
614 |
except Exception as e:
|
615 |
print(f"Report generation error: {str(e)}")
|
616 |
-
return
|
617 |
-
gr.update(value="๋ฆฌํฌํ
์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.", visible=True),
|
618 |
-
gr.update(value="์ ๊ธฐ", visible=True)
|
619 |
-
]
|
620 |
|
621 |
def toggle_report(report_content):
|
622 |
"""๋ฆฌํฌํธ ํ์/์จ๊น ํ ๊ธ"""
|
@@ -677,9 +666,15 @@ footer {visibility: hidden;}
|
|
677 |
border: 1px solid #ddd !important;
|
678 |
border-radius: 4px !important;
|
679 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
680 |
|
681 |
.hn-article-group {
|
682 |
-
height: auto;
|
683 |
min-height: 250px;
|
684 |
margin-bottom: 20px;
|
685 |
padding: 15px;
|
@@ -687,7 +682,7 @@ footer {visibility: hidden;}
|
|
687 |
border-radius: 5px;
|
688 |
background: white;
|
689 |
}
|
690 |
-
.report-
|
691 |
margin-top: 15px;
|
692 |
padding: 15px;
|
693 |
border-top: 1px solid #eee;
|
@@ -695,7 +690,6 @@ footer {visibility: hidden;}
|
|
695 |
}
|
696 |
"""
|
697 |
|
698 |
-
|
699 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as iface:
|
700 |
with gr.Tabs():
|
701 |
# ๊ตญ๊ฐ๋ณ ํญ
|
@@ -781,25 +775,24 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
781 |
with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
|
782 |
title = gr.Markdown()
|
783 |
info = gr.Markdown()
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
show_report = gr.Button("ํผ์ณ ๋ณด๊ธฐ", size="sm")
|
788 |
-
report_content = gr.Markdown()
|
789 |
|
790 |
hn_article_components.append({
|
791 |
'group': article_group,
|
792 |
'title': title,
|
793 |
'info': info,
|
794 |
'report_button': report_button,
|
795 |
-
'report_section': report_section,
|
796 |
-
'show_report': show_report,
|
797 |
'report_content': report_content,
|
|
|
798 |
'index': i,
|
799 |
})
|
800 |
|
801 |
|
802 |
|
|
|
|
|
803 |
|
804 |
|
805 |
# ๊ธฐ์กด ํจ์๋ค
|
@@ -971,24 +964,27 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
971 |
]
|
972 |
|
973 |
|
974 |
-
|
975 |
-
# AI ๋ฆฌํฌํฐ ํญ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
976 |
for comp in hn_article_components:
|
977 |
comp['report_button'].click(
|
978 |
-
generate_report,
|
979 |
-
inputs=[
|
980 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
981 |
show_progress=True
|
982 |
)
|
983 |
|
984 |
comp['show_report'].click(
|
985 |
-
toggle_report,
|
986 |
inputs=[comp['report_content']],
|
987 |
outputs=[comp['report_content']]
|
988 |
)
|
989 |
|
990 |
-
|
991 |
-
|
992 |
hn_outputs = [status_message_hn]
|
993 |
for comp in hn_article_components:
|
994 |
hn_outputs.extend([
|
@@ -996,12 +992,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
996 |
comp['title'],
|
997 |
comp['info'],
|
998 |
comp['report_button'],
|
999 |
-
comp['
|
1000 |
-
comp['
|
1001 |
])
|
1002 |
|
1003 |
refresh_button.click(
|
1004 |
-
refresh_hn_stories,
|
1005 |
outputs=hn_outputs
|
1006 |
)
|
1007 |
|
|
|
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'\*\*(.*?)\*\*|\n|AI ์์ฝ:|์์ฑ์:|์๊ฐ:|์ ์:|๋๊ธ:', ' ', info)
|
580 |
+
info_text = ' '.join(info_text.split())
|
581 |
|
582 |
progress(0.3, desc="ํ๋กฌํํธ ์์ฑ ์ค...")
|
583 |
|
|
|
599 |
repetition_penalty=1.2
|
600 |
)
|
601 |
|
602 |
+
progress(1.0, desc="์๋ฃ!")
|
603 |
+
|
604 |
+
return response, gr.update(visible=True)
|
605 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
606 |
except Exception as e:
|
607 |
print(f"Report generation error: {str(e)}")
|
608 |
+
return "๋ฆฌํฌํ
์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.", gr.update(visible=True)
|
|
|
|
|
|
|
609 |
|
610 |
def toggle_report(report_content):
|
611 |
"""๋ฆฌํฌํธ ํ์/์จ๊น ํ ๊ธ"""
|
|
|
666 |
border: 1px solid #ddd !important;
|
667 |
border-radius: 4px !important;
|
668 |
}
|
669 |
+
.report-section {
|
670 |
+
margin-top: 15px;
|
671 |
+
padding: 15px;
|
672 |
+
border-top: 1px solid #eee;
|
673 |
+
background: #f9f9f9;
|
674 |
+
}
|
675 |
|
676 |
.hn-article-group {
|
677 |
+
height: auto !important;
|
678 |
min-height: 250px;
|
679 |
margin-bottom: 20px;
|
680 |
padding: 15px;
|
|
|
682 |
border-radius: 5px;
|
683 |
background: white;
|
684 |
}
|
685 |
+
.report-content {
|
686 |
margin-top: 15px;
|
687 |
padding: 15px;
|
688 |
border-top: 1px solid #eee;
|
|
|
690 |
}
|
691 |
"""
|
692 |
|
|
|
693 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as iface:
|
694 |
with gr.Tabs():
|
695 |
# ๊ตญ๊ฐ๋ณ ํญ
|
|
|
775 |
with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
|
776 |
title = gr.Markdown()
|
777 |
info = gr.Markdown()
|
778 |
+
report_button = gr.Button("๋ฆฌํฌํ
์์ฑ", size="sm", variant="primary")
|
779 |
+
report_content = gr.Markdown(visible=False)
|
780 |
+
show_report = gr.Button("ํผ์ณ ๋ณด๊ธฐ", size="sm", visible=False)
|
|
|
|
|
781 |
|
782 |
hn_article_components.append({
|
783 |
'group': article_group,
|
784 |
'title': title,
|
785 |
'info': info,
|
786 |
'report_button': report_button,
|
|
|
|
|
787 |
'report_content': report_content,
|
788 |
+
'show_report': show_report,
|
789 |
'index': i,
|
790 |
})
|
791 |
|
792 |
|
793 |
|
794 |
+
|
795 |
+
|
796 |
|
797 |
|
798 |
# ๊ธฐ์กด ํจ์๋ค
|
|
|
964 |
]
|
965 |
|
966 |
|
967 |
+
# AI ๋ฆฌํฌํฐ ํญ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
|
|
968 |
for comp in hn_article_components:
|
969 |
comp['report_button'].click(
|
970 |
+
fn=generate_report,
|
971 |
+
inputs=[
|
972 |
+
comp['title'],
|
973 |
+
comp['info']
|
974 |
+
],
|
975 |
+
outputs=[
|
976 |
+
comp['report_content'],
|
977 |
+
comp['show_report']
|
978 |
+
],
|
979 |
show_progress=True
|
980 |
)
|
981 |
|
982 |
comp['show_report'].click(
|
983 |
+
fn=toggle_report,
|
984 |
inputs=[comp['report_content']],
|
985 |
outputs=[comp['report_content']]
|
986 |
)
|
987 |
|
|
|
|
|
988 |
hn_outputs = [status_message_hn]
|
989 |
for comp in hn_article_components:
|
990 |
hn_outputs.extend([
|
|
|
992 |
comp['title'],
|
993 |
comp['info'],
|
994 |
comp['report_button'],
|
995 |
+
comp['report_content'],
|
996 |
+
comp['show_report']
|
997 |
])
|
998 |
|
999 |
refresh_button.click(
|
1000 |
+
fn=refresh_hn_stories,
|
1001 |
outputs=hn_outputs
|
1002 |
)
|
1003 |
|