Spaces:
openfree
/
Running on CPU Upgrade

openfree commited on
Commit
e40f945
Β·
verified Β·
1 Parent(s): e4a465f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -18
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): # μƒμœ„ 20개 포슀트만 처리
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
- # AI 리포터 νƒ­ 이벀트 μ—°κ²°
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(