Spaces:
openfree
/
Running on CPU Upgrade

openfree commited on
Commit
e4a465f
ยท
verified ยท
1 Parent(s): 67522dc

Update app-backup-HN.py

Browse files
Files changed (1) hide show
  1. 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
- final_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', []))}๊ฐœ\n
512
- **AI ์š”์•ฝ:** {summary}
513
- """)
514
- ])
515
- else:
516
- final_outputs.extend([
517
- gr.update(visible=False),
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): # ์ƒ์œ„ 20๊ฐœ ํฌ์ŠคํŠธ๏ฟฝ๏ฟฝ ์ฒ˜๋ฆฌ
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()):