Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app-backup-HN.py
Browse files- app-backup-HN.py +99 -19
app-backup-HN.py
CHANGED
@@ -497,30 +497,78 @@ def refresh_hn_stories():
|
|
497 |
|
498 |
# ์ต์ข
์ํ ์
๋ฐ์ดํธ
|
499 |
final_outputs = [gr.update(value=f"์ด {len(processed_stories)}๊ฐ์ ํฌ์คํธ๊ฐ ์ฒ๋ฆฌ๋์์ต๋๋ค.", visible=True)]
|
500 |
-
|
501 |
for idx, comp in enumerate(hn_article_components):
|
502 |
if idx < len(processed_stories):
|
503 |
story, summary = processed_stories[idx]
|
504 |
-
|
505 |
gr.update(visible=True),
|
506 |
gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
|
507 |
gr.update(value=f"""
|
508 |
**์์ฑ์:** {story.get('by', 'unknown')} |
|
509 |
**์๊ฐ:** {format_hn_time(story.get('time', 0))} |
|
510 |
**์ ์:** {story.get('score', 0)} |
|
511 |
-
**๋๊ธ:** {len(story.get('kids', []))}
|
512 |
-
|
513 |
-
""
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
gr.update(
|
518 |
-
gr.update(),
|
519 |
-
gr.update()
|
520 |
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
|
522 |
yield final_outputs
|
523 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
css = """
|
525 |
footer {visibility: hidden;}
|
526 |
#status_area {
|
@@ -575,6 +623,28 @@ footer {visibility: hidden;}
|
|
575 |
border: 1px solid #ddd !important;
|
576 |
border-radius: 4px !important;
|
577 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
"""
|
579 |
|
580 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as iface:
|
@@ -647,33 +717,43 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
647 |
'index': i,
|
648 |
})
|
649 |
|
650 |
-
|
651 |
-
# AI ๋ฆฌํฌํฐ ํญ
|
652 |
with gr.Tab("AI ๋ฆฌํฌํฐ"):
|
653 |
gr.Markdown("์ง๋ 24์๊ฐ ๋์์ Hacker News ํฌ์คํธ๋ฅผ AI๊ฐ ์์ฝํ์ฌ ๋ณด์ฌ์ค๋๋ค.")
|
654 |
-
|
655 |
with gr.Column():
|
656 |
refresh_button = gr.Button("์๋ก๊ณ ์นจ", variant="primary")
|
657 |
status_message_hn = gr.Markdown("")
|
658 |
-
|
659 |
with gr.Column(elem_id="hn_results_area"):
|
660 |
hn_articles_state = gr.State([])
|
661 |
-
|
662 |
hn_article_components = []
|
663 |
-
for i in range(100):
|
664 |
-
with gr.Group(visible=False) as article_group:
|
665 |
title = gr.Markdown()
|
666 |
info = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
|
668 |
hn_article_components.append({
|
669 |
'group': article_group,
|
670 |
'title': title,
|
671 |
'info': info,
|
|
|
|
|
|
|
|
|
|
|
672 |
'index': i,
|
673 |
})
|
674 |
|
675 |
|
676 |
|
|
|
677 |
|
678 |
# ๊ธฐ์กด ํจ์๋ค
|
679 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
|
|
497 |
|
498 |
# ์ต์ข
์ํ ์
๋ฐ์ดํธ
|
499 |
final_outputs = [gr.update(value=f"์ด {len(processed_stories)}๊ฐ์ ํฌ์คํธ๊ฐ ์ฒ๋ฆฌ๋์์ต๋๋ค.", visible=True)]
|
500 |
+
|
501 |
for idx, comp in enumerate(hn_article_components):
|
502 |
if idx < len(processed_stories):
|
503 |
story, summary = processed_stories[idx]
|
504 |
+
outputs.extend([
|
505 |
gr.update(visible=True),
|
506 |
gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
|
507 |
gr.update(value=f"""
|
508 |
**์์ฑ์:** {story.get('by', 'unknown')} |
|
509 |
**์๊ฐ:** {format_hn_time(story.get('time', 0))} |
|
510 |
**์ ์:** {story.get('score', 0)} |
|
511 |
+
**๋๊ธ:** {len(story.get('kids', []))}๊ฐ
|
512 |
+
"""),
|
513 |
+
gr.update(value=f"**AI ์์ฝ:**\n{summary}"),
|
514 |
+
gr.update(visible=True), # report_button
|
515 |
+
gr.update(visible=False), # report_section
|
516 |
+
gr.update(value=""), # report_content
|
517 |
+
gr.update(value="ํผ์ณ ๋ณด๊ธฐ") # show_report
|
|
|
|
|
518 |
])
|
519 |
+
|
520 |
+
# ๋ฆฌํฌํ
์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
521 |
+
comp['report_button'].click(
|
522 |
+
generate_report,
|
523 |
+
inputs=[comp['title'], comp['summary']],
|
524 |
+
outputs=[comp['report_content']],
|
525 |
+
_js="() => {document.querySelector('.reporting-section').style.display='block';}"
|
526 |
+
)
|
527 |
+
|
528 |
+
# ํผ์ณ๋ณด๊ธฐ/์ ๊ธฐ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
529 |
+
comp['show_report'].click(
|
530 |
+
toggle_report,
|
531 |
+
inputs=[comp['report_section'], comp['report_content'], comp['show_report']],
|
532 |
+
outputs=[comp['report_section'], comp['show_report']]
|
533 |
+
)
|
534 |
|
535 |
yield final_outputs
|
536 |
+
|
537 |
+
|
538 |
+
|
539 |
+
|
540 |
+
def generate_report(title, summary):
|
541 |
+
"""๋ฆฌํฌํ
์์ฑ"""
|
542 |
+
prompt = f"""๋๋ Hacker News ํฌ์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ณด๋ ๊ธฐ์ฌ ํํ์ ๋ฆฌํฌํ
์ ์์ฑํ๋ ์ญํ ์ด๋ค.
|
543 |
+
๋๋ ๋ฐ๋์ ํ๊ธ๋ก ๋ฆฌํฌํ
ํ์์ ๊ฐ๊ด์ ๊ธฐ์ฌ ํํ๋ก ์์ฑํ์ฌ์ผ ํ๋ค.
|
544 |
+
์์ฑ์ 6ํ์์น์ ์
๊ฐํ๊ณ ๊ธธ์ด๋ 4000ํ ํฐ์ ๋์ง ์์๊ฒ.
|
545 |
+
๋์ ์ถ์ฒ๋ ๋ชจ๋ธ, ์ง์๋ฌธ ๋ฑ์ ๋
ธ์ถํ์ง ๋ง๊ฒ
|
546 |
+
|
547 |
+
์ ๋ชฉ: {title}
|
548 |
+
๋ด์ฉ ์์ฝ: {summary}
|
549 |
+
"""
|
550 |
+
|
551 |
+
try:
|
552 |
+
response = hf_client.text_generation(
|
553 |
+
prompt,
|
554 |
+
max_new_tokens=4000,
|
555 |
+
temperature=0.7,
|
556 |
+
repetition_penalty=1.2
|
557 |
+
)
|
558 |
+
return response
|
559 |
+
except Exception as e:
|
560 |
+
print(f"Report generation error: {str(e)}")
|
561 |
+
return None
|
562 |
+
|
563 |
+
def toggle_report(report_section, report_content, show_report):
|
564 |
+
"""๋ฆฌํฌํธ ํ์/์จ๊น ํ ๊ธ"""
|
565 |
+
is_visible = report_section.visible
|
566 |
+
return {
|
567 |
+
report_section: gr.update(visible=not is_visible),
|
568 |
+
show_report: gr.update(value="์ ๊ธฐ" if not is_visible else "ํผ์ณ ๋ณด๊ธฐ")
|
569 |
+
}
|
570 |
+
|
571 |
+
|
572 |
css = """
|
573 |
footer {visibility: hidden;}
|
574 |
#status_area {
|
|
|
623 |
border: 1px solid #ddd !important;
|
624 |
border-radius: 4px !important;
|
625 |
}
|
626 |
+
|
627 |
+
.hn-article-group {
|
628 |
+
height: 250px; /* ๊ณ ์ ๋์ด ์ค์ */
|
629 |
+
overflow: hidden; /* ๋ด์ฉ์ด ๋์น๋ฉด ์จ๊น */
|
630 |
+
margin-bottom: 20px;
|
631 |
+
padding: 15px;
|
632 |
+
border: 1px solid #eee;
|
633 |
+
border-radius: 5px;
|
634 |
+
}
|
635 |
+
.hn-summary {
|
636 |
+
height: 100px; /* ์์ฝ ํ
์คํธ ์์ญ ๊ณ ์ ๋์ด */
|
637 |
+
overflow: hidden;
|
638 |
+
text-overflow: ellipsis;
|
639 |
+
display: -webkit-box;
|
640 |
+
-webkit-line-clamp: 4; /* ์ต๋ 4์ค๊น์ง ํ์ */
|
641 |
+
-webkit-box-orient: vertical;
|
642 |
+
}
|
643 |
+
.reporting-section {
|
644 |
+
margin-top: 10px;
|
645 |
+
border-top: 1px solid #eee;
|
646 |
+
padding-top: 10px;
|
647 |
+
}
|
648 |
"""
|
649 |
|
650 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as iface:
|
|
|
717 |
'index': i,
|
718 |
})
|
719 |
|
|
|
|
|
720 |
with gr.Tab("AI ๋ฆฌํฌํฐ"):
|
721 |
gr.Markdown("์ง๋ 24์๊ฐ ๋์์ Hacker News ํฌ์คํธ๋ฅผ AI๊ฐ ์์ฝํ์ฌ ๋ณด์ฌ์ค๋๋ค.")
|
722 |
+
|
723 |
with gr.Column():
|
724 |
refresh_button = gr.Button("์๋ก๊ณ ์นจ", variant="primary")
|
725 |
status_message_hn = gr.Markdown("")
|
726 |
+
|
727 |
with gr.Column(elem_id="hn_results_area"):
|
728 |
hn_articles_state = gr.State([])
|
729 |
+
|
730 |
hn_article_components = []
|
731 |
+
for i in range(100):
|
732 |
+
with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
|
733 |
title = gr.Markdown()
|
734 |
info = gr.Markdown()
|
735 |
+
with gr.Column(elem_classes="hn-summary"):
|
736 |
+
summary = gr.Markdown()
|
737 |
+
report_button = gr.Button("๋ฆฌํฌํ
์์ฑ", size="sm")
|
738 |
+
with gr.Column(visible=False, elem_classes="reporting-section") as report_section:
|
739 |
+
report_content = gr.Markdown()
|
740 |
+
show_report = gr.Button("ํผ์ณ ๋ณด๊ธฐ")
|
741 |
|
742 |
hn_article_components.append({
|
743 |
'group': article_group,
|
744 |
'title': title,
|
745 |
'info': info,
|
746 |
+
'summary': summary,
|
747 |
+
'report_button': report_button,
|
748 |
+
'report_section': report_section,
|
749 |
+
'report_content': report_content,
|
750 |
+
'show_report': show_report,
|
751 |
'index': i,
|
752 |
})
|
753 |
|
754 |
|
755 |
|
756 |
+
|
757 |
|
758 |
# ๊ธฐ์กด ํจ์๋ค
|
759 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|