Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -964,117 +964,6 @@ footer {visibility: hidden;}
|
|
964 |
|
965 |
|
966 |
|
967 |
-
|
968 |
-
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as iface:
|
969 |
-
with gr.Tabs():
|
970 |
-
# ๊ตญ๊ฐ๋ณ ํญ
|
971 |
-
with gr.Tab("๊ตญ๊ฐ๋ณ"):
|
972 |
-
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ๊ตญ๊ฐ(ํ๊ตญ ์ ์ธ)๋ฅผ๋ฅผ ์ ํํ๋ฉด, ๊ฒ์์ด์ ์ผ์นํ๋ 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ์ต๋ 100๊ฐ ์ถ๋ ฅํฉ๋๋ค.")
|
973 |
-
gr.Markdown("๊ตญ๊ฐ ์ ํํ ๊ฒ์์ด์ 'ํ๊ธ'์ ์
๋ ฅํ๋ฉด ํ์ง ์ธ์ด๋ก ๋ฒ์ญ๋์ด ๊ฒ์ํฉ๋๋ค. ์: 'Taiwan' ๊ตญ๊ฐ ์ ํํ '์ผ์ฑ' ์
๋ ฅ์ 'ไธๆ'์ผ๋ก ์๋ ๊ฒ์")
|
974 |
-
|
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)
|
986 |
-
search_button = gr.Button("๊ฒ์", variant="primary")
|
987 |
-
|
988 |
-
progress = gr.Progress()
|
989 |
-
articles_state = gr.State([])
|
990 |
-
|
991 |
-
article_components = []
|
992 |
-
for i in range(100):
|
993 |
-
with gr.Group(visible=False) as article_group:
|
994 |
-
title = gr.Markdown()
|
995 |
-
image = gr.Image(width=200, height=150)
|
996 |
-
snippet = gr.Markdown()
|
997 |
-
info = gr.Markdown()
|
998 |
-
|
999 |
-
article_components.append({
|
1000 |
-
'group': article_group,
|
1001 |
-
'title': title,
|
1002 |
-
'image': image,
|
1003 |
-
'snippet': snippet,
|
1004 |
-
'info': info,
|
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():
|
1015 |
-
query_global = gr.Textbox(label="๊ฒ์์ด")
|
1016 |
-
region_select = gr.Dropdown(
|
1017 |
-
choices=REGIONS,
|
1018 |
-
label="์ง์ญ ์ ํ",
|
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:
|
1031 |
-
title = gr.Markdown()
|
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,
|
1039 |
-
'image': image,
|
1040 |
-
'snippet': snippet,
|
1041 |
-
'info': info,
|
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 |
# ๊ธฐ์กด ํจ์๋ค
|
@@ -1246,78 +1135,180 @@ def search_global(query, region, articles_state_global):
|
|
1246 |
|
1247 |
|
1248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1251 |
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1269 |
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1278 |
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
|
|
|
|
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 |
-
|
1317 |
-
fn=
|
1318 |
-
|
1319 |
-
|
|
|
1320 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1321 |
|
1322 |
iface.launch(
|
1323 |
server_name="0.0.0.0",
|
|
|
964 |
|
965 |
|
966 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
967 |
|
968 |
|
969 |
# ๊ธฐ์กด ํจ์๋ค
|
|
|
1135 |
|
1136 |
|
1137 |
|
1138 |
+
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as iface:
|
1139 |
+
with gr.Tabs():
|
1140 |
+
# ๊ตญ๊ฐ๋ณ ํญ
|
1141 |
+
with gr.Tab("๊ตญ๊ฐ๋ณ"):
|
1142 |
+
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ๊ตญ๊ฐ(ํ๊ตญ ์ ์ธ)๋ฅผ๋ฅผ ์ ํํ๋ฉด, ๊ฒ์์ด์ ์ผ์นํ๋ 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ์ต๋ 100๊ฐ ์ถ๋ ฅํฉ๋๋ค.")
|
1143 |
+
gr.Markdown("๊ตญ๊ฐ ์ ํํ ๊ฒ์์ด์ 'ํ๊ธ'์ ์
๋ ฅํ๋ฉด ํ์ง ์ธ์ด๋ก ๋ฒ์ญ๋์ด ๊ฒ์ํฉ๋๋ค. ์: 'Taiwan' ๊ตญ๊ฐ ์ ํํ '์ผ์ฑ' ์
๋ ฅ์ 'ไธๆ'์ผ๋ก ์๋ ๊ฒ์")
|
1144 |
+
|
1145 |
+
with gr.Column():
|
1146 |
+
with gr.Row():
|
1147 |
+
query = gr.Textbox(label="๊ฒ์์ด")
|
1148 |
+
country = gr.Dropdown(
|
1149 |
+
choices=sorted(list(COUNTRY_LOCATIONS.keys())),
|
1150 |
+
label="๊ตญ๊ฐ",
|
1151 |
+
value="United States"
|
1152 |
+
)
|
1153 |
+
|
1154 |
+
status_message = gr.Markdown("", visible=True)
|
1155 |
+
translated_query_display = gr.Markdown(visible=False)
|
1156 |
+
search_button = gr.Button("๊ฒ์", variant="primary")
|
1157 |
+
|
1158 |
+
progress = gr.Progress()
|
1159 |
+
articles_state = gr.State([])
|
1160 |
|
1161 |
+
article_components = []
|
1162 |
+
for i in range(100):
|
1163 |
+
with gr.Group(visible=False) as article_group:
|
1164 |
+
title = gr.Markdown()
|
1165 |
+
image = gr.Image(width=200, height=150)
|
1166 |
+
snippet = gr.Markdown()
|
1167 |
+
info = gr.Markdown()
|
1168 |
+
|
1169 |
+
article_components.append({
|
1170 |
+
'group': article_group,
|
1171 |
+
'title': title,
|
1172 |
+
'image': image,
|
1173 |
+
'snippet': snippet,
|
1174 |
+
'info': info,
|
1175 |
+
'index': i,
|
1176 |
+
})
|
1177 |
|
1178 |
+
# ์ ์ธ๊ณ ํญ
|
1179 |
+
with gr.Tab("์ ์ธ๊ณ"):
|
1180 |
+
gr.Markdown("๋๋ฅ๋ณ๋ก 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ๊ฒ์ํฉ๋๋ค.")
|
1181 |
+
|
1182 |
+
with gr.Column():
|
1183 |
+
with gr.Column(elem_id="status_area"):
|
1184 |
+
with gr.Row():
|
1185 |
+
query_global = gr.Textbox(label="๊ฒ์์ด")
|
1186 |
+
region_select = gr.Dropdown(
|
1187 |
+
choices=REGIONS,
|
1188 |
+
label="์ง์ญ ์ ํ",
|
1189 |
+
value="๋์์์"
|
1190 |
+
)
|
1191 |
+
search_button_global = gr.Button("๊ฒ์", variant="primary")
|
1192 |
+
|
1193 |
+
status_message_global = gr.Markdown("")
|
1194 |
+
translated_query_display_global = gr.Markdown("")
|
1195 |
+
|
1196 |
+
with gr.Column(elem_id="results_area"):
|
1197 |
+
articles_state_global = gr.State([])
|
1198 |
+
global_article_components = []
|
1199 |
+
for i in range(MAX_GLOBAL_RESULTS):
|
1200 |
+
with gr.Group(visible=False) as article_group:
|
1201 |
+
title = gr.Markdown()
|
1202 |
+
image = gr.Image(width=200, height=150)
|
1203 |
+
snippet = gr.Markdown()
|
1204 |
+
info = gr.Markdown()
|
1205 |
+
|
1206 |
+
global_article_components.append({
|
1207 |
+
'group': article_group,
|
1208 |
+
'title': title,
|
1209 |
+
'image': image,
|
1210 |
+
'snippet': snippet,
|
1211 |
+
'info': info,
|
1212 |
+
'index': i,
|
1213 |
+
})
|
1214 |
|
1215 |
+
# AI ๋ฆฌํฌํฐ ํญ
|
1216 |
+
with gr.Tab("AI ๋ฆฌํฌํฐ"):
|
1217 |
+
gr.Markdown("์ง๋ 24์๊ฐ ๋์์ Hacker News ํฌ์คํธ๋ฅผ AI๊ฐ ์์ฝํ์ฌ ๋ณด์ฌ์ค๋๋ค.")
|
1218 |
+
|
1219 |
+
with gr.Column():
|
1220 |
+
refresh_button = gr.Button("์๋ก๊ณ ์นจ", variant="primary")
|
1221 |
+
status_message_hn = gr.Markdown("")
|
1222 |
+
|
1223 |
+
with gr.Column(elem_id="hn_results_area"):
|
1224 |
+
hn_articles_state = gr.State([])
|
1225 |
+
hn_article_components = []
|
1226 |
+
for i in range(100):
|
1227 |
+
with gr.Group(visible=False, elem_classes="hn-article-group") as article_group:
|
1228 |
+
title = gr.Markdown()
|
1229 |
+
info = gr.Markdown()
|
1230 |
+
with gr.Row():
|
1231 |
+
report_button = gr.Button("๋ฆฌํฌํ
์์ฑ", size="sm", variant="primary")
|
1232 |
+
show_report = gr.Button("ํผ์ณ ๋ณด๊ธฐ", size="sm", visible=False)
|
1233 |
+
report_content = gr.Markdown(visible=False)
|
1234 |
+
|
1235 |
+
hn_article_components.append({
|
1236 |
+
'group': article_group,
|
1237 |
+
'title': title,
|
1238 |
+
'info': info,
|
1239 |
+
'report_button': report_button,
|
1240 |
+
'show_report': show_report,
|
1241 |
+
'report_content': report_content,
|
1242 |
+
'index': i,
|
1243 |
+
})
|
1244 |
|
1245 |
+
# ๊ตญ๊ฐ๋ณ ํญ ์ด๋ฒคํธ
|
1246 |
+
search_outputs = [status_message, translated_query_display, gr.Markdown(visible=False)]
|
1247 |
+
for comp in article_components:
|
1248 |
+
search_outputs.extend([
|
1249 |
+
comp['group'], comp['title'], comp['image'],
|
1250 |
+
comp['snippet'], comp['info']
|
1251 |
+
])
|
1252 |
+
search_outputs.append(articles_state)
|
1253 |
+
|
1254 |
+
search_button.click(
|
1255 |
+
fn=search_and_display,
|
1256 |
+
inputs=[query, country, articles_state],
|
1257 |
+
outputs=search_outputs,
|
1258 |
+
show_progress=True
|
1259 |
+
)
|
1260 |
+
|
1261 |
+
# ์ ์ธ๊ณ ํญ ์ด๋ฒคํธ
|
1262 |
+
global_search_outputs = [status_message_global, translated_query_display_global]
|
1263 |
+
for comp in global_article_components:
|
1264 |
+
global_search_outputs.extend([
|
1265 |
+
comp['group'], comp['title'], comp['image'],
|
1266 |
+
comp['snippet'], comp['info']
|
1267 |
+
])
|
1268 |
+
global_search_outputs.append(articles_state_global)
|
1269 |
+
|
1270 |
+
search_button_global.click(
|
1271 |
+
fn=search_global,
|
1272 |
+
inputs=[query_global, region_select, articles_state_global],
|
1273 |
+
outputs=global_search_outputs,
|
1274 |
+
show_progress=True
|
1275 |
+
)
|
1276 |
+
|
1277 |
+
# AI ๋ฆฌํฌํฐ ํญ ์ด๋ฒคํธ
|
1278 |
+
hn_outputs = [status_message_hn]
|
1279 |
+
for comp in hn_article_components:
|
1280 |
+
hn_outputs.extend([
|
1281 |
+
comp['group'],
|
1282 |
+
comp['title'],
|
1283 |
+
comp['info'],
|
1284 |
+
comp['report_button'],
|
1285 |
+
comp['report_content'],
|
1286 |
+
comp['show_report']
|
1287 |
+
])
|
1288 |
|
1289 |
+
# ๋ฆฌํฌํ
์์ฑ ๋ฒํผ ์ด๋ฒคํธ
|
1290 |
+
comp['report_button'].click(
|
1291 |
+
fn=generate_report,
|
1292 |
+
inputs=[comp['title'], comp['info']],
|
1293 |
+
outputs=[comp['report_content'], comp['show_report']],
|
1294 |
+
api_name=f"generate_report_{comp['index']}",
|
1295 |
show_progress=True
|
1296 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1297 |
|
1298 |
+
# ํผ์ณ๋ณด๊ธฐ/์ ๊ธฐ ๋ฒํผ ์ด๋ฒคํธ
|
1299 |
+
comp['show_report'].click(
|
1300 |
+
fn=toggle_report,
|
1301 |
+
inputs=[comp['report_content'], comp['show_report']],
|
1302 |
+
outputs=[comp['report_content'], comp['show_report']],
|
1303 |
+
api_name=f"toggle_report_{comp['index']}"
|
1304 |
)
|
1305 |
+
|
1306 |
+
# ์๋ก๊ณ ์นจ ๋ฒํผ ์ด๋ฒคํธ
|
1307 |
+
refresh_button.click(
|
1308 |
+
fn=refresh_hn_stories,
|
1309 |
+
outputs=hn_outputs,
|
1310 |
+
show_progress=True
|
1311 |
+
)
|
1312 |
|
1313 |
iface.launch(
|
1314 |
server_name="0.0.0.0",
|