Spaces:
openfree
/
Running on CPU Upgrade

openfree commited on
Commit
4270b77
ยท
verified ยท
1 Parent(s): d7d50ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -101
app.py CHANGED
@@ -962,6 +962,9 @@ footer {visibility: hidden;}
962
  }
963
  """
964
 
 
 
 
965
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
966
  with gr.Tabs():
967
  # ๊ตญ๊ฐ€๋ณ„ ํƒญ
@@ -972,7 +975,11 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
972
  with gr.Column():
973
  with gr.Row():
974
  query = gr.Textbox(label="๊ฒ€์ƒ‰์–ด")
975
- country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ€", value="United States")
 
 
 
 
976
 
977
  status_message = gr.Markdown("", visible=True)
978
  translated_query_display = gr.Markdown(visible=False)
@@ -998,9 +1005,10 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
998
  'index': i,
999
  })
1000
 
 
1001
  with gr.Tab("์ „์„ธ๊ณ„"):
1002
  gr.Markdown("๋Œ€๋ฅ™๋ณ„๋กœ 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.")
1003
-
1004
  with gr.Column():
1005
  with gr.Column(elem_id="status_area"):
1006
  with gr.Row():
@@ -1011,14 +1019,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
1011
  value="๋™์•„์‹œ์•„"
1012
  )
1013
  search_button_global = gr.Button("๊ฒ€์ƒ‰", variant="primary")
1014
-
1015
  status_message_global = gr.Markdown("")
1016
  translated_query_display_global = gr.Markdown("")
1017
-
1018
  with gr.Column(elem_id="results_area"):
1019
  articles_state_global = gr.State([])
1020
-
1021
- # ๊ธ€๋กœ๋ฒŒ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ์œ„ํ•œ ์ปดํฌ๋„ŒํŠธ ์ƒ์„ฑ
1022
  global_article_components = []
1023
  for i in range(MAX_GLOBAL_RESULTS):
1024
  with gr.Group(visible=False) as article_group:
@@ -1026,7 +1032,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
1026
  image = gr.Image(width=200, height=150)
1027
  snippet = gr.Markdown()
1028
  info = gr.Markdown()
1029
-
1030
  global_article_components.append({
1031
  'group': article_group,
1032
  'title': title,
@@ -1036,41 +1042,39 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
1036
  'index': i,
1037
  })
1038
 
1039
-
1040
-
1041
  with gr.Tab("AI ๋ฆฌํฌํ„ฐ"):
1042
  gr.Markdown("์ง€๋‚œ 24์‹œ๊ฐ„ ๋™์•ˆ์˜ Hacker News ํฌ์ŠคํŠธ๋ฅผ AI๊ฐ€ ์š”์•ฝํ•˜์—ฌ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.")
1043
-
1044
  with gr.Column():
1045
  refresh_button = gr.Button("์ƒˆ๋กœ๊ณ ์นจ", variant="primary")
1046
  status_message_hn = gr.Markdown("")
1047
-
1048
  with gr.Column(elem_id="hn_results_area"):
1049
  hn_articles_state = gr.State([])
1050
-
1051
  hn_article_components = []
1052
  for i in range(100):
1053
  with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
1054
  title = gr.Markdown()
1055
  info = gr.Markdown()
1056
- report_button = gr.Button("๋ฆฌํฌํŒ… ์ƒ์„ฑ", size="sm", variant="primary")
 
 
1057
  report_content = gr.Markdown(visible=False)
1058
- show_report = gr.Button("ํŽผ์ณ ๋ณด๊ธฐ", size="sm", visible=False)
1059
-
1060
  hn_article_components.append({
1061
  'group': article_group,
1062
  'title': title,
1063
  'info': info,
1064
  'report_button': report_button,
1065
- 'report_content': report_content,
1066
  'show_report': show_report,
 
1067
  'index': i,
1068
  })
1069
 
1070
 
1071
 
1072
 
1073
-
1074
 
1075
 
1076
  # ๊ธฐ์กด ํ•จ์ˆ˜๋“ค
@@ -1235,105 +1239,85 @@ def search_global(query, region, articles_state_global):
1235
  yield outputs
1236
 
1237
 
 
 
1238
 
1239
 
1240
 
1241
 
1242
 
1243
- # ๊ตญ๊ฐ€๋ณ„ ํƒญ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1244
- search_outputs = [
1245
- status_message,
1246
- translated_query_display,
1247
- gr.Markdown(visible=False)
1248
- ]
1249
-
1250
- for comp in article_components:
1251
- search_outputs.extend([
1252
- comp['group'], comp['title'], comp['image'],
1253
- comp['snippet'], comp['info']
1254
- ])
1255
- search_outputs.append(articles_state)
1256
-
1257
- search_button.click(
1258
- search_and_display,
1259
- inputs=[query, country, articles_state],
1260
- outputs=search_outputs,
1261
- show_progress=True
1262
- )
1263
 
1264
 
1265
- # ์ „์„ธ๊ณ„ ํƒญ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1266
- global_search_outputs = [
1267
- status_message_global,
1268
- translated_query_display_global,
1269
- ]
1270
-
1271
- for comp in global_article_components:
1272
- global_search_outputs.extend([
1273
- comp['group'], comp['title'], comp['image'],
1274
- comp['snippet'], comp['info']
1275
- ])
1276
- global_search_outputs.append(articles_state_global)
1277
-
1278
- search_button_global.click(
1279
- fn=search_global,
1280
- inputs=[query_global, region_select, articles_state_global],
1281
- outputs=global_search_outputs
1282
- )
1283
-
1284
 
1285
- # AI ๋ฆฌํฌํ„ฐ ํƒญ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1286
- hn_outputs = [status_message_hn]
1287
- for comp in hn_article_components:
1288
- hn_outputs.extend([
1289
- comp['group'],
1290
- comp['title'],
1291
- comp['info'],
1292
- comp['report_button'],
1293
- comp['report_content'],
1294
- comp['show_report']
1295
- ])
1296
 
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
  )
 
 
 
 
 
 
 
 
 
1311
 
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
- )
1331
-
1332
-
1333
-
1334
-
1335
-
1336
-
1337
 
1338
  iface.launch(
1339
  server_name="0.0.0.0",
 
962
  }
963
  """
964
 
965
+
966
+
967
+
968
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
969
  with gr.Tabs():
970
  # ๊ตญ๊ฐ€๋ณ„ ํƒญ
 
975
  with gr.Column():
976
  with gr.Row():
977
  query = gr.Textbox(label="๊ฒ€์ƒ‰์–ด")
978
+ country = gr.Dropdown(
979
+ choices=sorted(list(COUNTRY_LOCATIONS.keys())),
980
+ label="๊ตญ๊ฐ€",
981
+ value="United States"
982
+ )
983
 
984
  status_message = gr.Markdown("", visible=True)
985
  translated_query_display = gr.Markdown(visible=False)
 
1005
  'index': i,
1006
  })
1007
 
1008
+ # ์ „์„ธ๊ณ„ ํƒญ
1009
  with gr.Tab("์ „์„ธ๊ณ„"):
1010
  gr.Markdown("๋Œ€๋ฅ™๋ณ„๋กœ 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.")
1011
+
1012
  with gr.Column():
1013
  with gr.Column(elem_id="status_area"):
1014
  with gr.Row():
 
1019
  value="๋™์•„์‹œ์•„"
1020
  )
1021
  search_button_global = gr.Button("๊ฒ€์ƒ‰", variant="primary")
1022
+
1023
  status_message_global = gr.Markdown("")
1024
  translated_query_display_global = gr.Markdown("")
1025
+
1026
  with gr.Column(elem_id="results_area"):
1027
  articles_state_global = gr.State([])
 
 
1028
  global_article_components = []
1029
  for i in range(MAX_GLOBAL_RESULTS):
1030
  with gr.Group(visible=False) as article_group:
 
1032
  image = gr.Image(width=200, height=150)
1033
  snippet = gr.Markdown()
1034
  info = gr.Markdown()
1035
+
1036
  global_article_components.append({
1037
  'group': article_group,
1038
  'title': title,
 
1042
  'index': i,
1043
  })
1044
 
1045
+ # AI ๋ฆฌํฌํ„ฐ ํƒญ
 
1046
  with gr.Tab("AI ๋ฆฌํฌํ„ฐ"):
1047
  gr.Markdown("์ง€๋‚œ 24์‹œ๊ฐ„ ๋™์•ˆ์˜ Hacker News ํฌ์ŠคํŠธ๋ฅผ AI๊ฐ€ ์š”์•ฝํ•˜์—ฌ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.")
1048
+
1049
  with gr.Column():
1050
  refresh_button = gr.Button("์ƒˆ๋กœ๊ณ ์นจ", variant="primary")
1051
  status_message_hn = gr.Markdown("")
1052
+
1053
  with gr.Column(elem_id="hn_results_area"):
1054
  hn_articles_state = gr.State([])
 
1055
  hn_article_components = []
1056
  for i in range(100):
1057
  with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
1058
  title = gr.Markdown()
1059
  info = gr.Markdown()
1060
+ with gr.Row():
1061
+ report_button = gr.Button("๋ฆฌํฌํŒ… ์ƒ์„ฑ", size="sm", variant="primary")
1062
+ show_report = gr.Button("ํŽผ์ณ ๋ณด๊ธฐ", size="sm", visible=False)
1063
  report_content = gr.Markdown(visible=False)
1064
+
 
1065
  hn_article_components.append({
1066
  'group': article_group,
1067
  'title': title,
1068
  'info': info,
1069
  'report_button': report_button,
 
1070
  'show_report': show_report,
1071
+ 'report_content': report_content,
1072
  'index': i,
1073
  })
1074
 
1075
 
1076
 
1077
 
 
1078
 
1079
 
1080
  # ๊ธฐ์กด ํ•จ์ˆ˜๋“ค
 
1239
  yield outputs
1240
 
1241
 
1242
+
1243
+
1244
 
1245
 
1246
 
1247
 
1248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1249
 
1250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1251
 
1252
+ # ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1253
+ with iface:
1254
+ # ๊ตญ๊ฐ€๋ณ„ ํƒญ ์ด๋ฒคํŠธ
1255
+ search_outputs = [status_message, translated_query_display, gr.Markdown(visible=False)]
1256
+ for comp in article_components:
1257
+ search_outputs.extend([
1258
+ comp['group'], comp['title'], comp['image'],
1259
+ comp['snippet'], comp['info']
1260
+ ])
1261
+ search_outputs.append(articles_state)
 
1262
 
1263
+ search_button.click(
1264
+ fn=search_and_display,
1265
+ inputs=[query, country, articles_state],
1266
+ outputs=search_outputs,
 
 
 
 
 
 
 
 
1267
  show_progress=True
1268
  )
1269
+
1270
+ # ์ „์„ธ๊ณ„ ํƒญ ์ด๋ฒคํŠธ
1271
+ global_search_outputs = [status_message_global, translated_query_display_global]
1272
+ for comp in global_article_components:
1273
+ global_search_outputs.extend([
1274
+ comp['group'], comp['title'], comp['image'],
1275
+ comp['snippet'], comp['info']
1276
+ ])
1277
+ global_search_outputs.append(articles_state_global)
1278
 
1279
+ search_button_global.click(
1280
+ fn=search_global,
1281
+ inputs=[query_global, region_select, articles_state_global],
1282
+ outputs=global_search_outputs,
1283
+ show_progress=True
1284
+ )
1285
+
1286
+ # AI ๋ฆฌํฌํ„ฐ ํƒญ ์ด๋ฒคํŠธ
1287
+ hn_outputs = [status_message_hn]
1288
+ for comp in hn_article_components:
1289
+ hn_outputs.extend([
1290
+ comp['group'],
1291
+ comp['title'],
1292
+ comp['info'],
1293
+ comp['report_button'],
1294
  comp['report_content'],
1295
  comp['show_report']
1296
+ ])
1297
+
1298
+ # ๋ฆฌํฌํŒ… ์ƒ์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1299
+ comp['report_button'].click(
1300
+ fn=generate_report,
1301
+ inputs=[comp['title'], comp['info']],
1302
+ outputs=[comp['report_content'], comp['show_report']],
1303
+ api_name=f"generate_report_{comp['index']}",
1304
+ show_progress=True
1305
+ )
1306
+
1307
+ # ํŽผ์ณ๋ณด๊ธฐ/์ ‘๊ธฐ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1308
+ comp['show_report'].click(
1309
+ fn=toggle_report,
1310
+ inputs=[comp['report_content'], comp['show_report']],
1311
+ outputs=[comp['report_content'], comp['show_report']],
1312
+ api_name=f"toggle_report_{comp['index']}"
1313
+ )
1314
+
1315
+ # ์ƒˆ๋กœ๊ณ ์นจ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1316
+ refresh_button.click(
1317
+ fn=refresh_hn_stories,
1318
+ outputs=hn_outputs,
1319
+ show_progress=True
1320
  )
 
 
 
 
 
 
 
 
 
 
 
 
1321
 
1322
  iface.launch(
1323
  server_name="0.0.0.0",