Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -763,7 +763,7 @@ def generate_report(title, info, progress=gr.Progress()):
|
|
763 |
|
764 |
prompt = f"""๋๋ Hacker News ํฌ์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ณด๋ ๊ธฐ์ฌ ํํ์ ๋ฆฌํฌํ
์ ์์ฑํ๋ ์ญํ ์ด๋ค.
|
765 |
๋๋ ๋ฐ๋์ ํ๊ธ๋ก ๋ฆฌํฌํ
ํ์์ ๊ฐ๊ด์ ๊ธฐ์ฌ ํํ๋ก ์์ฑํ์ฌ์ผ ํ๋ค.
|
766 |
-
์์ฑ์ 6ํ์์น์ ์
๊ฐํ๊ณ ๊ธธ์ด๋
|
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 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
formatted_response =
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
|
802 |
except Exception as e:
|
803 |
-
print(f"
|
804 |
-
return [
|
|
|
|
|
|
|
805 |
|
806 |
def toggle_report(report_content, show_report):
|
807 |
"""๋ฆฌํฌํธ ํ์/์จ๊น ํ ๊ธ"""
|
808 |
-
|
809 |
-
|
810 |
-
|
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 |
-
|
1273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=[
|
1288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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=[
|
1297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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",
|