openfree commited on
Commit
08d910a
Β·
verified Β·
1 Parent(s): 56e62ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -17
app.py CHANGED
@@ -569,28 +569,55 @@ def refresh_hn_stories():
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_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
- report_content = gr.Markdown(visible=False)
 
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
  # κΈ°μ‘΄ ν•¨μˆ˜λ“€