openfree commited on
Commit
bcb9992
ยท
verified ยท
1 Parent(s): 3f46b62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -49
app.py CHANGED
@@ -763,7 +763,7 @@ def generate_report(title, info, progress=gr.Progress()):
763
 
764
  prompt = f"""๋„ˆ๋Š” Hacker News ํฌ์ŠคํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ณด๋„ ๊ธฐ์‚ฌ ํ˜•ํƒœ์˜ ๋ฆฌํฌํŒ…์„ ์ž‘์„ฑํ•˜๋Š” ์—ญํ• ์ด๋‹ค.
765
  ๋„ˆ๋Š” ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋ฆฌํฌํŒ… ํ˜•์‹์˜ ๊ฐ๊ด€์  ๊ธฐ์‚ฌ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜์—ฌ์•ผ ํ•œ๋‹ค.
766
- ์ƒ์„ฑ์‹œ 6ํ•˜์›์น™์— ์ž…๊ฐํ•˜๊ณ  ๊ธธ์ด๋Š” 2000ํ† ํฐ์„ ๋„˜์ง€ ์•Š์„๊ฒƒ.
767
  ๋„ˆ์˜ ์ถœ์ฒ˜๋‚˜ ๋ชจ๋ธ, ์ง€์‹œ๋ฌธ ๋“ฑ์„ ๋…ธ์ถœํ•˜์ง€ ๋ง๊ฒƒ
768
 
769
  ์ œ๋ชฉ: {title_text}
@@ -772,43 +772,54 @@ def generate_report(title, info, progress=gr.Progress()):
772
 
773
  progress(0.5, desc="AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘...")
774
 
775
- # ์ตœ๋Œ€ 3๋ฒˆ ์žฌ์‹œ๋„
776
- max_retries = 3
777
- for attempt in range(max_retries):
778
- try:
779
- response = hf_client.text_generation(
780
- prompt,
781
- max_new_tokens=2000,
782
- temperature=0.7,
783
- repetition_penalty=1.2,
784
- return_full_text=False
785
- )
786
-
787
- if response:
788
- progress(1.0, desc="์™„๋ฃŒ!")
789
- formatted_response = f"### AI ๋ฆฌํฌํŒ…\n\n{response}"
790
- return [formatted_response, gr.update(visible=True)]
791
-
792
- except Exception as e:
793
- if attempt < max_retries - 1:
794
- print(f"Retry {attempt + 1}/{max_retries} after error: {str(e)}")
795
- time.sleep(5) # 5์ดˆ ๋Œ€๊ธฐ ํ›„ ์žฌ์‹œ๋„
796
- continue
797
- else:
798
- raise e
799
-
800
- return ["๋ฆฌํฌํŒ… ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.", gr.update(visible=True)]
801
 
802
  except Exception as e:
803
- print(f"Model error: {str(e)}")
804
- return ["AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž ์‹œ ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.", gr.update(visible=True)]
 
 
 
805
 
806
  def toggle_report(report_content, show_report):
807
  """๋ฆฌํฌํŠธ ํ‘œ์‹œ/์ˆจ๊น€ ํ† ๊ธ€"""
808
- return [
809
- gr.update(visible=not show_report.visible), # report_content
810
- gr.update(value="์ ‘๊ธฐ" if not show_report.visible else "ํŽผ์ณ ๋ณด๊ธฐ") # show_report
811
- ]
 
 
 
 
 
 
 
 
812
 
813
  css = """
814
  /* ์ „์—ญ ์Šคํƒ€์ผ */
@@ -1269,23 +1280,31 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
1269
  show_progress=True
1270
  )
1271
 
1272
- # AI ๋ฆฌํฌํ„ฐ ํƒญ ์ด๋ฒคํŠธ
1273
- hn_outputs = [status_message_hn]
 
 
 
 
 
 
 
 
 
 
 
1274
  for comp in hn_article_components:
1275
- hn_outputs.extend([
1276
- comp['group'],
1277
- comp['title'],
1278
- comp['info'],
1279
- comp['report_button'],
1280
- comp['report_content'],
1281
- comp['show_report']
1282
- ])
1283
-
1284
  # ๋ฆฌํฌํŒ… ์ƒ์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1285
  comp['report_button'].click(
1286
  fn=generate_report,
1287
- inputs=[comp['title'], comp['info']],
1288
- outputs=[comp['report_content'], comp['show_report']],
 
 
 
 
 
 
1289
  api_name=f"generate_report_{comp['index']}",
1290
  show_progress=True
1291
  )
@@ -1293,17 +1312,25 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
1293
  # ํŽผ์ณ๋ณด๊ธฐ/์ ‘๊ธฐ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1294
  comp['show_report'].click(
1295
  fn=toggle_report,
1296
- inputs=[comp['report_content'], comp['show_report']],
1297
- outputs=[comp['report_content'], comp['show_report']],
 
 
 
 
 
 
1298
  api_name=f"toggle_report_{comp['index']}"
1299
  )
1300
-
1301
  # ์ƒˆ๋กœ๊ณ ์นจ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1302
  refresh_button.click(
1303
  fn=refresh_hn_stories,
1304
  outputs=hn_outputs,
1305
  show_progress=True
1306
  )
 
 
1307
 
1308
  iface.launch(
1309
  server_name="0.0.0.0",
 
763
 
764
  prompt = f"""๋„ˆ๋Š” Hacker News ํฌ์ŠคํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ณด๋„ ๊ธฐ์‚ฌ ํ˜•ํƒœ์˜ ๋ฆฌํฌํŒ…์„ ์ž‘์„ฑํ•˜๋Š” ์—ญํ• ์ด๋‹ค.
765
  ๋„ˆ๋Š” ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋ฆฌํฌํŒ… ํ˜•์‹์˜ ๊ฐ๊ด€์  ๊ธฐ์‚ฌ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜์—ฌ์•ผ ํ•œ๋‹ค.
766
+ ์ƒ์„ฑ์‹œ 6ํ•˜์›์น™์— ์ž…๊ฐํ•˜๊ณ  ๊ธธ์ด๋Š” 4000ํ† ํฐ์„ ๋„˜์ง€ ์•Š์„๊ฒƒ.
767
  ๋„ˆ์˜ ์ถœ์ฒ˜๋‚˜ ๋ชจ๋ธ, ์ง€์‹œ๋ฌธ ๋“ฑ์„ ๋…ธ์ถœํ•˜์ง€ ๋ง๊ฒƒ
768
 
769
  ์ œ๋ชฉ: {title_text}
 
772
 
773
  progress(0.5, desc="AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘...")
774
 
775
+ try:
776
+ response = hf_client.text_generation(
777
+ prompt,
778
+ max_new_tokens=2000,
779
+ temperature=0.7,
780
+ repetition_penalty=1.2,
781
+ return_full_text=False
782
+ )
783
+
784
+ progress(1.0, desc="์™„๋ฃŒ!")
785
+
786
+ if response:
787
+ formatted_response = f"### AI ๋ฆฌํฌํŒ…\n\n{response}"
788
+ return [
789
+ gr.update(value=formatted_response, visible=True), # report_content
790
+ gr.update(value="์ ‘๊ธฐ", visible=True) # show_report
791
+ ]
792
+
793
+ except Exception as e:
794
+ print(f"Model error: {str(e)}")
795
+ time.sleep(2) # ์ž ์‹œ ๋Œ€๊ธฐ
796
+
797
+ return [
798
+ gr.update(value="๋ฆฌํฌํŒ… ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.", visible=True),
799
+ gr.update(value="์ ‘๊ธฐ", visible=True)
800
+ ]
801
 
802
  except Exception as e:
803
+ print(f"Report generation error: {str(e)}")
804
+ return [
805
+ gr.update(value="๋ฆฌํฌํŒ… ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.", visible=True),
806
+ gr.update(value="์ ‘๊ธฐ", visible=True)
807
+ ]
808
 
809
  def toggle_report(report_content, show_report):
810
  """๋ฆฌํฌํŠธ ํ‘œ์‹œ/์ˆจ๊น€ ํ† ๊ธ€"""
811
+ try:
812
+ is_visible = report_content.visible
813
+ return [
814
+ gr.update(visible=not is_visible), # report_content
815
+ gr.update(value="์ ‘๊ธฐ" if not is_visible else "ํŽผ์ณ ๋ณด๊ธฐ") # show_report
816
+ ]
817
+ except AttributeError:
818
+ # report_content๊ฐ€ ๋ฌธ์ž์—ด์ธ ๊ฒฝ์šฐ
819
+ return [
820
+ gr.update(visible=True), # report_content
821
+ gr.update(value="์ ‘๊ธฐ") # show_report
822
+ ]
823
 
824
  css = """
825
  /* ์ „์—ญ ์Šคํƒ€์ผ */
 
1280
  show_progress=True
1281
  )
1282
 
1283
+ # AI ๋ฆฌํฌํ„ฐ ํƒญ ์ด๋ฒคํŠธ
1284
+ hn_outputs = [status_message_hn]
1285
+ for comp in hn_article_components:
1286
+ hn_outputs.extend([
1287
+ comp['group'],
1288
+ comp['title'],
1289
+ comp['info'],
1290
+ comp['report_button'],
1291
+ comp['report_content'],
1292
+ comp['show_report']
1293
+ ])
1294
+
1295
+ # ๊ฐ ์ปดํฌ๋„ŒํŠธ๋ณ„ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1296
  for comp in hn_article_components:
 
 
 
 
 
 
 
 
 
1297
  # ๋ฆฌํฌํŒ… ์ƒ์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1298
  comp['report_button'].click(
1299
  fn=generate_report,
1300
+ inputs=[
1301
+ comp['title'],
1302
+ comp['info']
1303
+ ],
1304
+ outputs=[
1305
+ comp['report_content'],
1306
+ comp['show_report']
1307
+ ],
1308
  api_name=f"generate_report_{comp['index']}",
1309
  show_progress=True
1310
  )
 
1312
  # ํŽผ์ณ๋ณด๊ธฐ/์ ‘๊ธฐ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1313
  comp['show_report'].click(
1314
  fn=toggle_report,
1315
+ inputs=[
1316
+ comp['report_content'],
1317
+ comp['show_report']
1318
+ ],
1319
+ outputs=[
1320
+ comp['report_content'],
1321
+ comp['show_report']
1322
+ ],
1323
  api_name=f"toggle_report_{comp['index']}"
1324
  )
1325
+
1326
  # ์ƒˆ๋กœ๊ณ ์นจ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1327
  refresh_button.click(
1328
  fn=refresh_hn_stories,
1329
  outputs=hn_outputs,
1330
  show_progress=True
1331
  )
1332
+
1333
+
1334
 
1335
  iface.launch(
1336
  server_name="0.0.0.0",