Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app-backup2.py
Browse files- app-backup2.py +205 -31
app-backup2.py
CHANGED
@@ -10,7 +10,74 @@ from requests.packages.urllib3.util.retry import Retry
|
|
10 |
from openai import OpenAI
|
11 |
from bs4 import BeautifulSoup
|
12 |
import re # re ๋ชจ๋ ์ถ๊ฐ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
15 |
if not ACCESS_TOKEN:
|
16 |
raise ValueError("HF_TOKEN environment variable is not set")
|
@@ -725,6 +792,7 @@ def search_global(query, region, articles_state_global):
|
|
725 |
css = """
|
726 |
/* ์ ์ญ ์คํ์ผ */
|
727 |
footer {visibility: hidden;}
|
|
|
728 |
/* ๋ ์ด์์ ์ปจํ
์ด๋ */
|
729 |
#status_area {
|
730 |
background: rgba(255, 255, 255, 0.9);
|
@@ -733,33 +801,40 @@ footer {visibility: hidden;}
|
|
733 |
margin-bottom: 20px;
|
734 |
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
735 |
}
|
|
|
736 |
#results_area {
|
737 |
padding: 10px;
|
738 |
margin-top: 10px;
|
739 |
}
|
|
|
740 |
/* ํญ ์คํ์ผ */
|
741 |
.tabs {
|
742 |
border-bottom: 2px solid #ddd !important;
|
743 |
margin-bottom: 20px !important;
|
744 |
}
|
|
|
745 |
.tab-nav {
|
746 |
border-bottom: none !important;
|
747 |
margin-bottom: 0 !important;
|
748 |
}
|
|
|
749 |
.tab-nav button {
|
750 |
font-weight: bold !important;
|
751 |
padding: 10px 20px !important;
|
752 |
}
|
|
|
753 |
.tab-nav button.selected {
|
754 |
border-bottom: 2px solid #1f77b4 !important;
|
755 |
color: #1f77b4 !important;
|
756 |
}
|
|
|
757 |
/* ์ํ ๋ฉ์์ง */
|
758 |
#status_area .markdown-text {
|
759 |
font-size: 1.1em;
|
760 |
color: #2c3e50;
|
761 |
padding: 10px 0;
|
762 |
}
|
|
|
763 |
/* ๊ธฐ๋ณธ ์ปจํ
์ด๋ */
|
764 |
.group {
|
765 |
border: 1px solid #eee;
|
@@ -768,16 +843,19 @@ footer {visibility: hidden;}
|
|
768 |
border-radius: 5px;
|
769 |
background: white;
|
770 |
}
|
|
|
771 |
/* ๋ฒํผ ์คํ์ผ */
|
772 |
.primary-btn {
|
773 |
background: #1f77b4 !important;
|
774 |
border: none !important;
|
775 |
}
|
|
|
776 |
/* ์
๋ ฅ ํ๋ */
|
777 |
.textbox {
|
778 |
border: 1px solid #ddd !important;
|
779 |
border-radius: 4px !important;
|
780 |
}
|
|
|
781 |
/* ํ๋ก๊ทธ๋ ์ค๋ฐ ์ปจํ
์ด๋ */
|
782 |
.progress-container {
|
783 |
position: fixed;
|
@@ -788,6 +866,7 @@ footer {visibility: hidden;}
|
|
788 |
background: #e0e0e0;
|
789 |
z-index: 1000;
|
790 |
}
|
|
|
791 |
/* ํ๋ก๊ทธ๋ ์ค๋ฐ */
|
792 |
.progress-bar {
|
793 |
height: 100%;
|
@@ -796,6 +875,7 @@ footer {visibility: hidden;}
|
|
796 |
transition: width 0.3s ease;
|
797 |
animation: progress-glow 1.5s ease-in-out infinite;
|
798 |
}
|
|
|
799 |
/* ํ๋ก๊ทธ๋ ์ค ํ
์คํธ */
|
800 |
.progress-text {
|
801 |
position: fixed;
|
@@ -810,6 +890,7 @@ footer {visibility: hidden;}
|
|
810 |
z-index: 1001;
|
811 |
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
812 |
}
|
|
|
813 |
/* ํ๋ก๊ทธ๋ ์ค๋ฐ ์ ๋๋ฉ์ด์
*/
|
814 |
@keyframes progress-glow {
|
815 |
0% {
|
@@ -822,6 +903,7 @@ footer {visibility: hidden;}
|
|
822 |
box-shadow: 0 0 5px rgba(33, 150, 243, 0.5);
|
823 |
}
|
824 |
}
|
|
|
825 |
/* ๋ฐ์ํ ๋์์ธ */
|
826 |
@media (max-width: 768px) {
|
827 |
.group {
|
@@ -834,27 +916,32 @@ footer {visibility: hidden;}
|
|
834 |
padding: 3px 10px;
|
835 |
}
|
836 |
}
|
|
|
837 |
/* ๋ก๋ฉ ์ํ ํ์ ๊ฐ์ */
|
838 |
.loading {
|
839 |
opacity: 0.7;
|
840 |
pointer-events: none;
|
841 |
transition: opacity 0.3s ease;
|
842 |
}
|
|
|
843 |
/* ๊ฒฐ๊ณผ ์ปจํ
์ด๋ ์ ๋๋ฉ์ด์
*/
|
844 |
.group {
|
845 |
transition: all 0.3s ease;
|
846 |
opacity: 0;
|
847 |
transform: translateY(20px);
|
848 |
}
|
|
|
849 |
.group.visible {
|
850 |
opacity: 1;
|
851 |
transform: translateY(0);
|
852 |
}
|
|
|
853 |
/* Examples ์คํ์ผ๋ง */
|
854 |
.examples-table {
|
855 |
margin-top: 10px !important;
|
856 |
margin-bottom: 20px !important;
|
857 |
}
|
|
|
858 |
.examples-table button {
|
859 |
background-color: #f0f0f0 !important;
|
860 |
border: 1px solid #ddd !important;
|
@@ -863,11 +950,13 @@ footer {visibility: hidden;}
|
|
863 |
margin: 2px !important;
|
864 |
transition: all 0.3s ease !important;
|
865 |
}
|
|
|
866 |
.examples-table button:hover {
|
867 |
background-color: #e0e0e0 !important;
|
868 |
transform: translateY(-1px) !important;
|
869 |
box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
|
870 |
}
|
|
|
871 |
.examples-table .label {
|
872 |
font-weight: bold !important;
|
873 |
color: #444 !important;
|
@@ -946,17 +1035,21 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
|
|
946 |
article_content = get_article_content(url)
|
947 |
|
948 |
translation_prompt = f"""๋ค์ ์๋ฌธ ๊ธฐ์ฌ๋ฅผ ํ๊ตญ์ด๋ก ๋ฒ์ญํ๊ณ ๊ธฐ์ฌ๋ฅผ ์์ฑํด์ฃผ์ธ์.
|
|
|
949 |
1๋จ๊ณ: ์ ๋ฌธ ๋ฒ์ญ
|
950 |
===๋ฒ์ญ ์์===
|
951 |
{article_content}
|
952 |
===๋ฒ์ญ ๋===
|
|
|
953 |
2๋จ๊ณ: ๊ธฐ์ฌ ์์ฑ ๊ฐ์ด๋๋ผ์ธ
|
954 |
๋ค์ ์๊ตฌ์ฌํญ์ ๋ฐ๋ผ ํ๊ตญ์ด ๊ธฐ์ฌ๋ฅผ ์์ฑํ์ธ์:
|
|
|
955 |
1. ๊ตฌ์กฐ
|
956 |
- ํค๋๋ผ์ธ: ํต์ฌ ๋ด์ฉ์ ๋ด์ ๊ฐ๋ ฅํ ์ ๋ชฉ
|
957 |
- ๋ถ์ ๋ชฉ: ํค๋๋ผ์ธ ๋ณด์ ์ค๋ช
|
958 |
- ๋ฆฌ๋๋ฌธ: ๊ธฐ์ฌ์ ํต์ฌ์ ์์ฝํ ์ฒซ ๋ฌธ๋จ
|
959 |
- ๋ณธ๋ฌธ: ์์ธ ๋ด์ฉ ์ ๊ฐ
|
|
|
960 |
2. ์์ฑ ๊ท์น
|
961 |
- ๊ฐ๊ด์ ์ด๊ณ ์ ํํ ์ฌ์ค ์ ๋ฌ
|
962 |
- ๋ฌธ์ฅ์ '๋ค.'๋ก ์ข
๊ฒฐ
|
@@ -964,10 +1057,12 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
|
|
964 |
- ์ธ์ฉ๊ตฌ๋ ๋ฐ์ดํ ์ฒ๋ฆฌ
|
965 |
- ํต์ฌ ์ ๋ณด๋ฅผ ์๋ถ๋ถ์ ๋ฐฐ์น
|
966 |
- ์ ๋ฌธ ์ฉ์ด๋ ์ ์ ํ ์ค๋ช
์ถ๊ฐ
|
|
|
967 |
3. ํ์
|
968 |
- ์ ์ ํ ๋จ๋ฝ ๊ตฌ๋ถ
|
969 |
- ์ฝ๊ธฐ ์ฌ์ด ๋ฌธ์ฅ ๊ธธ์ด
|
970 |
- ๋
ผ๋ฆฌ์ ์ธ ์ ๋ณด ๊ตฌ์ฑ
|
|
|
971 |
๊ฐ ๋จ๊ณ๋ '===๋ฒ์ญ===', '===๊ธฐ์ฌ==='๋ก ๋ช
ํํ ๊ตฌ๋ถํ์ฌ ์ถ๋ ฅํ์ธ์.
|
972 |
"""
|
973 |
|
@@ -1004,9 +1099,81 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
|
|
1004 |
|
1005 |
return history
|
1006 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1007 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น์ค") as iface:
|
|
|
|
|
1008 |
with gr.Tabs():
|
1009 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1010 |
with gr.Tab("๊ตญ๊ฐ๋ณ"):
|
1011 |
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ๊ตญ๊ฐ(ํ๊ตญ ์ ์ธ)๋ฅผ๋ฅผ ์ ํํ๋ฉด, ๊ฒ์์ด์ ์ผ์นํ๋ 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ์ต๋ 100๊ฐ ์ถ๋ ฅํฉ๋๋ค.")
|
1012 |
gr.Markdown("๊ตญ๊ฐ ์ ํํ ๊ฒ์์ด์ 'ํ๊ธ'์ ์
๋ ฅํ๋ฉด ํ์ง ์ธ์ด๋ก ๋ฒ์ญ๋์ด ๊ฒ์ํฉ๋๋ค. ์: 'Taiwan' ๊ตญ๊ฐ ์ ํํ '์ผ์ฑ' ์
๋ ฅ์ 'ไธๆ'์ผ๋ก ์๋ ๊ฒ์")
|
@@ -1049,7 +1216,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
1049 |
translated_query_display = gr.Markdown(visible=False)
|
1050 |
search_button = gr.Button("๊ฒ์", variant="primary")
|
1051 |
|
1052 |
-
|
1053 |
progress = gr.Progress()
|
1054 |
articles_state = gr.State([])
|
1055 |
|
@@ -1107,8 +1273,7 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
1107 |
'index': i,
|
1108 |
})
|
1109 |
|
1110 |
-
|
1111 |
-
# AI ๋ฒ์ญ ํญ ์ถ๊ฐ
|
1112 |
with gr.Tab("AI ๊ธฐ์ฌ ์์ฑ"):
|
1113 |
gr.Markdown("๋ด์ค URL์ ์
๋ ฅํ๋ฉด AI๊ฐ ํ๊ตญ์ด๋ก ๋ฒ์ญํ์ฌ ๊ธฐ์ฌ ํ์์ผ๋ก ์์ฑํฉ๋๋ค.")
|
1114 |
gr.Markdown("์ด๋ฏธ์ง ์์ฑ: https://huggingface.co/spaces/ginipick/FLUXllama ")
|
@@ -1122,10 +1287,13 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
1122 |
placeholder="https://..."
|
1123 |
)
|
1124 |
|
1125 |
-
with gr.
|
|
|
|
|
1126 |
|
|
|
1127 |
system_message = gr.Textbox(
|
1128 |
-
|
1129 |
1. TRANSLATION
|
1130 |
- Start with ===๋ฒ์ญ=== marker
|
1131 |
- Provide accurate Korean translation
|
@@ -1155,14 +1323,12 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
1155 |
- Clearly separate each section with markers
|
1156 |
- Never skip or combine steps
|
1157 |
- Ensure image prompts align with article content""",
|
1158 |
-
|
1159 |
-
|
1160 |
|
1161 |
-
|
1162 |
-
|
1163 |
max_tokens = gr.Slider(
|
1164 |
minimum=1,
|
1165 |
-
|
1166 |
value=7624,
|
1167 |
step=1,
|
1168 |
label="Max new tokens"
|
@@ -1181,26 +1347,7 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
1181 |
step=0.05,
|
1182 |
label="Top-P"
|
1183 |
)
|
1184 |
-
|
1185 |
-
translate_button = gr.Button("๊ธฐ์ฌ ์์ฑ", variant="primary")
|
1186 |
-
|
1187 |
-
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
1188 |
-
translate_button.click(
|
1189 |
-
fn=respond,
|
1190 |
-
inputs=[
|
1191 |
-
url_input,
|
1192 |
-
chatbot,
|
1193 |
-
system_message,
|
1194 |
-
max_tokens,
|
1195 |
-
temperature,
|
1196 |
-
top_p,
|
1197 |
-
],
|
1198 |
-
outputs=chatbot
|
1199 |
-
)
|
1200 |
-
|
1201 |
-
|
1202 |
|
1203 |
-
|
1204 |
# ์ด๋ฒคํธ ์ฐ๊ฒฐ ๋ถ๋ถ
|
1205 |
# ๊ตญ๊ฐ๋ณ ํญ ์ด๋ฒคํธ
|
1206 |
search_outputs = [status_message, translated_query_display, gr.Markdown(visible=False)]
|
@@ -1234,6 +1381,33 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
1234 |
show_progress=True
|
1235 |
)
|
1236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1237 |
iface.launch(
|
1238 |
server_name="0.0.0.0",
|
1239 |
server_port=7860,
|
@@ -1241,4 +1415,4 @@ iface.launch(
|
|
1241 |
auth=("gini","pick"),
|
1242 |
ssl_verify=False,
|
1243 |
show_error=True
|
1244 |
-
)
|
|
|
10 |
from openai import OpenAI
|
11 |
from bs4 import BeautifulSoup
|
12 |
import re # re ๋ชจ๋ ์ถ๊ฐ
|
13 |
+
import json
|
14 |
+
import os
|
15 |
+
from datetime import datetime
|
16 |
+
import sqlite3
|
17 |
+
import pathlib
|
18 |
+
|
19 |
+
# DB ์ด๊ธฐํ ํจ์
|
20 |
+
def init_db():
|
21 |
+
db_path = pathlib.Path("search_results.db")
|
22 |
+
conn = sqlite3.connect(db_path)
|
23 |
+
c = conn.cursor()
|
24 |
+
c.execute('''CREATE TABLE IF NOT EXISTS searches
|
25 |
+
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
26 |
+
keyword TEXT,
|
27 |
+
country TEXT,
|
28 |
+
results TEXT,
|
29 |
+
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)''')
|
30 |
+
conn.commit()
|
31 |
+
conn.close()
|
32 |
+
|
33 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ ์ ์ฅ ํจ์
|
34 |
+
def save_to_db(keyword, country, results):
|
35 |
+
conn = sqlite3.connect("search_results.db")
|
36 |
+
c = conn.cursor()
|
37 |
+
c.execute("INSERT INTO searches (keyword, country, results) VALUES (?, ?, ?)",
|
38 |
+
(keyword, country, json.dumps(results)))
|
39 |
+
conn.commit()
|
40 |
+
conn.close()
|
41 |
+
|
42 |
+
# DB์์ ๊ฒ์ ๊ฒฐ๊ณผ ๋ถ๋ฌ์ค๊ธฐ ํจ์
|
43 |
+
def load_from_db(keyword, country):
|
44 |
+
conn = sqlite3.connect("search_results.db")
|
45 |
+
c = conn.cursor()
|
46 |
+
c.execute("SELECT results, timestamp FROM searches WHERE keyword=? AND country=? ORDER BY timestamp DESC LIMIT 1",
|
47 |
+
(keyword, country))
|
48 |
+
result = c.fetchone()
|
49 |
+
conn.close()
|
50 |
+
if result:
|
51 |
+
return json.loads(result[0]), result[1]
|
52 |
+
return None, None
|
53 |
+
|
54 |
+
# ์ผ์ฑ/๋ฏธ๊ตญ ๊ฒ์ ํจ์
|
55 |
+
def search_samsung_us():
|
56 |
+
error_message, articles = serphouse_search("samsung", "United States")
|
57 |
+
if not error_message and articles:
|
58 |
+
save_to_db("samsung", "United States", articles)
|
59 |
+
return display_results(articles)
|
60 |
+
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
61 |
|
62 |
+
# DB์์ ์ผ์ฑ/๋ฏธ๊ตญ ๊ฒฐ๊ณผ ๋ถ๋ฌ์ค๊ธฐ ํจ์
|
63 |
+
def load_samsung_us():
|
64 |
+
results, timestamp = load_from_db("samsung", "United States")
|
65 |
+
if results:
|
66 |
+
return f"์ ์ฅ ์๊ฐ: {timestamp}\n\n" + display_results(results)
|
67 |
+
return "์ ์ฅ๋ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
68 |
+
|
69 |
+
# ๊ฒฐ๊ณผ ํ์ ํจ์
|
70 |
+
def display_results(articles):
|
71 |
+
output = ""
|
72 |
+
for idx, article in enumerate(articles, 1):
|
73 |
+
output += f"### {idx}. {article['title']}\n"
|
74 |
+
output += f"์ถ์ฒ: {article['channel']}\n"
|
75 |
+
output += f"์๊ฐ: {article['time']}\n"
|
76 |
+
output += f"๋งํฌ: {article['link']}\n"
|
77 |
+
output += f"์์ฝ: {article['snippet']}\n\n"
|
78 |
+
return output
|
79 |
+
|
80 |
+
|
81 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
82 |
if not ACCESS_TOKEN:
|
83 |
raise ValueError("HF_TOKEN environment variable is not set")
|
|
|
792 |
css = """
|
793 |
/* ์ ์ญ ์คํ์ผ */
|
794 |
footer {visibility: hidden;}
|
795 |
+
|
796 |
/* ๋ ์ด์์ ์ปจํ
์ด๋ */
|
797 |
#status_area {
|
798 |
background: rgba(255, 255, 255, 0.9);
|
|
|
801 |
margin-bottom: 20px;
|
802 |
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
803 |
}
|
804 |
+
|
805 |
#results_area {
|
806 |
padding: 10px;
|
807 |
margin-top: 10px;
|
808 |
}
|
809 |
+
|
810 |
/* ํญ ์คํ์ผ */
|
811 |
.tabs {
|
812 |
border-bottom: 2px solid #ddd !important;
|
813 |
margin-bottom: 20px !important;
|
814 |
}
|
815 |
+
|
816 |
.tab-nav {
|
817 |
border-bottom: none !important;
|
818 |
margin-bottom: 0 !important;
|
819 |
}
|
820 |
+
|
821 |
.tab-nav button {
|
822 |
font-weight: bold !important;
|
823 |
padding: 10px 20px !important;
|
824 |
}
|
825 |
+
|
826 |
.tab-nav button.selected {
|
827 |
border-bottom: 2px solid #1f77b4 !important;
|
828 |
color: #1f77b4 !important;
|
829 |
}
|
830 |
+
|
831 |
/* ์ํ ๋ฉ์์ง */
|
832 |
#status_area .markdown-text {
|
833 |
font-size: 1.1em;
|
834 |
color: #2c3e50;
|
835 |
padding: 10px 0;
|
836 |
}
|
837 |
+
|
838 |
/* ๊ธฐ๋ณธ ์ปจํ
์ด๋ */
|
839 |
.group {
|
840 |
border: 1px solid #eee;
|
|
|
843 |
border-radius: 5px;
|
844 |
background: white;
|
845 |
}
|
846 |
+
|
847 |
/* ๋ฒํผ ์คํ์ผ */
|
848 |
.primary-btn {
|
849 |
background: #1f77b4 !important;
|
850 |
border: none !important;
|
851 |
}
|
852 |
+
|
853 |
/* ์
๋ ฅ ํ๋ */
|
854 |
.textbox {
|
855 |
border: 1px solid #ddd !important;
|
856 |
border-radius: 4px !important;
|
857 |
}
|
858 |
+
|
859 |
/* ํ๋ก๊ทธ๋ ์ค๋ฐ ์ปจํ
์ด๋ */
|
860 |
.progress-container {
|
861 |
position: fixed;
|
|
|
866 |
background: #e0e0e0;
|
867 |
z-index: 1000;
|
868 |
}
|
869 |
+
|
870 |
/* ํ๋ก๊ทธ๋ ์ค๋ฐ */
|
871 |
.progress-bar {
|
872 |
height: 100%;
|
|
|
875 |
transition: width 0.3s ease;
|
876 |
animation: progress-glow 1.5s ease-in-out infinite;
|
877 |
}
|
878 |
+
|
879 |
/* ํ๋ก๊ทธ๋ ์ค ํ
์คํธ */
|
880 |
.progress-text {
|
881 |
position: fixed;
|
|
|
890 |
z-index: 1001;
|
891 |
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
892 |
}
|
893 |
+
|
894 |
/* ํ๋ก๊ทธ๋ ์ค๋ฐ ์ ๋๋ฉ์ด์
*/
|
895 |
@keyframes progress-glow {
|
896 |
0% {
|
|
|
903 |
box-shadow: 0 0 5px rgba(33, 150, 243, 0.5);
|
904 |
}
|
905 |
}
|
906 |
+
|
907 |
/* ๋ฐ์ํ ๋์์ธ */
|
908 |
@media (max-width: 768px) {
|
909 |
.group {
|
|
|
916 |
padding: 3px 10px;
|
917 |
}
|
918 |
}
|
919 |
+
|
920 |
/* ๋ก๋ฉ ์ํ ํ์ ๊ฐ์ */
|
921 |
.loading {
|
922 |
opacity: 0.7;
|
923 |
pointer-events: none;
|
924 |
transition: opacity 0.3s ease;
|
925 |
}
|
926 |
+
|
927 |
/* ๊ฒฐ๊ณผ ์ปจํ
์ด๋ ์ ๋๋ฉ์ด์
*/
|
928 |
.group {
|
929 |
transition: all 0.3s ease;
|
930 |
opacity: 0;
|
931 |
transform: translateY(20px);
|
932 |
}
|
933 |
+
|
934 |
.group.visible {
|
935 |
opacity: 1;
|
936 |
transform: translateY(0);
|
937 |
}
|
938 |
+
|
939 |
/* Examples ์คํ์ผ๋ง */
|
940 |
.examples-table {
|
941 |
margin-top: 10px !important;
|
942 |
margin-bottom: 20px !important;
|
943 |
}
|
944 |
+
|
945 |
.examples-table button {
|
946 |
background-color: #f0f0f0 !important;
|
947 |
border: 1px solid #ddd !important;
|
|
|
950 |
margin: 2px !important;
|
951 |
transition: all 0.3s ease !important;
|
952 |
}
|
953 |
+
|
954 |
.examples-table button:hover {
|
955 |
background-color: #e0e0e0 !important;
|
956 |
transform: translateY(-1px) !important;
|
957 |
box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
|
958 |
}
|
959 |
+
|
960 |
.examples-table .label {
|
961 |
font-weight: bold !important;
|
962 |
color: #444 !important;
|
|
|
1035 |
article_content = get_article_content(url)
|
1036 |
|
1037 |
translation_prompt = f"""๋ค์ ์๋ฌธ ๊ธฐ์ฌ๋ฅผ ํ๊ตญ์ด๋ก ๋ฒ์ญํ๊ณ ๊ธฐ์ฌ๋ฅผ ์์ฑํด์ฃผ์ธ์.
|
1038 |
+
|
1039 |
1๋จ๊ณ: ์ ๋ฌธ ๋ฒ์ญ
|
1040 |
===๋ฒ์ญ ์์===
|
1041 |
{article_content}
|
1042 |
===๋ฒ์ญ ๋===
|
1043 |
+
|
1044 |
2๋จ๊ณ: ๊ธฐ์ฌ ์์ฑ ๊ฐ์ด๋๋ผ์ธ
|
1045 |
๋ค์ ์๊ตฌ์ฌํญ์ ๋ฐ๋ผ ํ๊ตญ์ด ๊ธฐ์ฌ๋ฅผ ์์ฑํ์ธ์:
|
1046 |
+
|
1047 |
1. ๊ตฌ์กฐ
|
1048 |
- ํค๋๋ผ์ธ: ํต์ฌ ๋ด์ฉ์ ๋ด์ ๊ฐ๋ ฅํ ์ ๋ชฉ
|
1049 |
- ๋ถ์ ๋ชฉ: ํค๋๋ผ์ธ ๋ณด์ ์ค๋ช
|
1050 |
- ๋ฆฌ๋๋ฌธ: ๊ธฐ์ฌ์ ํต์ฌ์ ์์ฝํ ์ฒซ ๋ฌธ๋จ
|
1051 |
- ๋ณธ๋ฌธ: ์์ธ ๋ด์ฉ ์ ๊ฐ
|
1052 |
+
|
1053 |
2. ์์ฑ ๊ท์น
|
1054 |
- ๊ฐ๊ด์ ์ด๊ณ ์ ํํ ์ฌ์ค ์ ๋ฌ
|
1055 |
- ๋ฌธ์ฅ์ '๋ค.'๋ก ์ข
๊ฒฐ
|
|
|
1057 |
- ์ธ์ฉ๊ตฌ๋ ๋ฐ์ดํ ์ฒ๋ฆฌ
|
1058 |
- ํต์ฌ ์ ๋ณด๋ฅผ ์๋ถ๋ถ์ ๋ฐฐ์น
|
1059 |
- ์ ๋ฌธ ์ฉ์ด๋ ์ ์ ํ ์ค๋ช
์ถ๊ฐ
|
1060 |
+
|
1061 |
3. ํ์
|
1062 |
- ์ ์ ํ ๋จ๋ฝ ๊ตฌ๋ถ
|
1063 |
- ์ฝ๊ธฐ ์ฌ์ด ๋ฌธ์ฅ ๊ธธ์ด
|
1064 |
- ๋
ผ๋ฆฌ์ ์ธ ์ ๋ณด ๊ตฌ์ฑ
|
1065 |
+
|
1066 |
๊ฐ ๋จ๊ณ๋ '===๋ฒ์ญ===', '===๊ธฐ์ฌ==='๋ก ๋ช
ํํ ๊ตฌ๋ถํ์ฌ ์ถ๋ ฅํ์ธ์.
|
1067 |
"""
|
1068 |
|
|
|
1099 |
|
1100 |
return history
|
1101 |
|
1102 |
+
|
1103 |
+
def continue_writing(history, system_message, max_tokens, temperature, top_p):
|
1104 |
+
if not history:
|
1105 |
+
return history
|
1106 |
+
|
1107 |
+
last_response = history[-1][1] if history else ""
|
1108 |
+
continue_prompt = f"""์ด์ ๋ด์ฉ์ ์ด์ด์ ๊ณ์ ์์ฑํด์ฃผ์ธ์.
|
1109 |
+
๋ง์ง๋ง ์๋ต: {last_response}
|
1110 |
+
|
1111 |
+
์ถ๊ฐ ์ง์นจ:
|
1112 |
+
1. ์ด์ ๋ด์ฉ์ ๋งฅ๋ฝ์ ์ ์งํ๋ฉฐ ์์ฐ์ค๋ฝ๊ฒ ์ด์ด์ ์์ฑ
|
1113 |
+
2. ์๋ก์ด ์ ๋ณด๋ ์์ธ ์ค๋ช
์ ์ถ๊ฐ
|
1114 |
+
3. ํ์ํ ๊ฒฝ์ฐ ๋ณด์ถฉ ์ค๋ช
์ด๋ ๋ถ์ ์ ๊ณต
|
1115 |
+
4. ๊ธฐ์ฌ ํ์๊ณผ ์คํ์ผ ์ ์ง
|
1116 |
+
5. ํ์ํ ๊ฒฝ์ฐ ์ถ๊ฐ์ ์ธ ์ด๋ฏธ์ง ํ๋กฌํํธ ์์ฑ
|
1117 |
+
"""
|
1118 |
+
|
1119 |
+
# ๋ฉ์์ง ๊ตฌ์กฐ ์์
|
1120 |
+
messages = [
|
1121 |
+
{"role": "system", "content": system_message},
|
1122 |
+
{"role": "user", "content": continue_prompt} # ์ฌ์ฉ์ ๋ฉ์์ง๋ก ์์
|
1123 |
+
]
|
1124 |
+
|
1125 |
+
try:
|
1126 |
+
full_response = ""
|
1127 |
+
for message in client.chat.completions.create(
|
1128 |
+
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
1129 |
+
max_tokens=max_tokens,
|
1130 |
+
stream=True,
|
1131 |
+
temperature=temperature,
|
1132 |
+
top_p=top_p,
|
1133 |
+
messages=messages,
|
1134 |
+
):
|
1135 |
+
if hasattr(message.choices[0].delta, 'content'):
|
1136 |
+
token = message.choices[0].delta.content
|
1137 |
+
if token:
|
1138 |
+
full_response += token
|
1139 |
+
# ์ด์ ๋ํ ๊ธฐ๋ก์ ์ ์งํ๋ฉด์ ์๋ก์ด ์๋ต ์ถ๊ฐ
|
1140 |
+
new_history = history.copy()
|
1141 |
+
new_history.append(("๊ณ์ ์์ฑ", full_response))
|
1142 |
+
yield new_history
|
1143 |
+
|
1144 |
+
except Exception as e:
|
1145 |
+
error_message = f"๊ณ์ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
1146 |
+
new_history = history.copy()
|
1147 |
+
new_history.append(("์ค๋ฅ", error_message))
|
1148 |
+
yield new_history
|
1149 |
+
|
1150 |
+
return history
|
1151 |
+
|
1152 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น์ค") as iface:
|
1153 |
+
init_db() # DB ์ด๊ธฐํ
|
1154 |
+
|
1155 |
with gr.Tabs():
|
1156 |
+
# DB ์ ์ฅ/๋ถ๋ฌ์ค๊ธฐ ํญ
|
1157 |
+
with gr.Tab("DB ๊ฒ์"):
|
1158 |
+
gr.Markdown("์ผ์ฑ/๋ฏธ๊ตญ ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ DB์ ์ ์ฅํ๊ณ ๋ถ๋ฌ์ต๋๋ค.")
|
1159 |
+
|
1160 |
+
with gr.Row():
|
1161 |
+
search_button = gr.Button("๊ฒ์: samsung/๋ฏธ๊ตญ", variant="primary")
|
1162 |
+
load_button = gr.Button("์ถ๋ ฅ: samsung/๋ฏธ๊ตญ", variant="secondary")
|
1163 |
+
|
1164 |
+
results_display = gr.Markdown()
|
1165 |
+
|
1166 |
+
# ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
1167 |
+
search_button.click(
|
1168 |
+
fn=search_samsung_us,
|
1169 |
+
outputs=results_display
|
1170 |
+
)
|
1171 |
+
|
1172 |
+
load_button.click(
|
1173 |
+
fn=load_samsung_us,
|
1174 |
+
outputs=results_display
|
1175 |
+
)
|
1176 |
+
|
1177 |
with gr.Tab("๊ตญ๊ฐ๋ณ"):
|
1178 |
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ๊ตญ๊ฐ(ํ๊ตญ ์ ์ธ)๋ฅผ๋ฅผ ์ ํํ๋ฉด, ๊ฒ์์ด์ ์ผ์นํ๋ 24์๊ฐ ์ด๋ด ๋ด์ค๋ฅผ ์ต๋ 100๊ฐ ์ถ๋ ฅํฉ๋๋ค.")
|
1179 |
gr.Markdown("๊ตญ๊ฐ ์ ํํ ๊ฒ์์ด์ 'ํ๊ธ'์ ์
๋ ฅํ๋ฉด ํ์ง ์ธ์ด๋ก ๋ฒ์ญ๋์ด ๊ฒ์ํฉ๋๋ค. ์: 'Taiwan' ๊ตญ๊ฐ ์ ํํ '์ผ์ฑ' ์
๋ ฅ์ 'ไธๆ'์ผ๋ก ์๋ ๊ฒ์")
|
|
|
1216 |
translated_query_display = gr.Markdown(visible=False)
|
1217 |
search_button = gr.Button("๊ฒ์", variant="primary")
|
1218 |
|
|
|
1219 |
progress = gr.Progress()
|
1220 |
articles_state = gr.State([])
|
1221 |
|
|
|
1273 |
'index': i,
|
1274 |
})
|
1275 |
|
1276 |
+
# AI ๋ฒ์ญ ํญ
|
|
|
1277 |
with gr.Tab("AI ๊ธฐ์ฌ ์์ฑ"):
|
1278 |
gr.Markdown("๋ด์ค URL์ ์
๋ ฅํ๋ฉด AI๊ฐ ํ๊ตญ์ด๋ก ๋ฒ์ญํ์ฌ ๊ธฐ์ฌ ํ์์ผ๋ก ์์ฑํฉ๋๋ค.")
|
1279 |
gr.Markdown("์ด๋ฏธ์ง ์์ฑ: https://huggingface.co/spaces/ginipick/FLUXllama ")
|
|
|
1287 |
placeholder="https://..."
|
1288 |
)
|
1289 |
|
1290 |
+
with gr.Row():
|
1291 |
+
translate_button = gr.Button("๊ธฐ์ฌ ์์ฑ", variant="primary")
|
1292 |
+
continue_button = gr.Button("๊ณ์ ์ด์ด์ ์์ฑ", variant="secondary")
|
1293 |
|
1294 |
+
with gr.Accordion("๊ณ ๊ธ ์ค์ ", open=False):
|
1295 |
system_message = gr.Textbox(
|
1296 |
+
value="""You are a professional translator and journalist. Follow these steps strictly:
|
1297 |
1. TRANSLATION
|
1298 |
- Start with ===๋ฒ์ญ=== marker
|
1299 |
- Provide accurate Korean translation
|
|
|
1323 |
- Clearly separate each section with markers
|
1324 |
- Never skip or combine steps
|
1325 |
- Ensure image prompts align with article content""",
|
1326 |
+
label="System message"
|
1327 |
+
)
|
1328 |
|
|
|
|
|
1329 |
max_tokens = gr.Slider(
|
1330 |
minimum=1,
|
1331 |
+
maximum=7800,
|
1332 |
value=7624,
|
1333 |
step=1,
|
1334 |
label="Max new tokens"
|
|
|
1347 |
step=0.05,
|
1348 |
label="Top-P"
|
1349 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1350 |
|
|
|
1351 |
# ์ด๋ฒคํธ ์ฐ๊ฒฐ ๋ถ๋ถ
|
1352 |
# ๊ตญ๊ฐ๋ณ ํญ ์ด๋ฒคํธ
|
1353 |
search_outputs = [status_message, translated_query_display, gr.Markdown(visible=False)]
|
|
|
1381 |
show_progress=True
|
1382 |
)
|
1383 |
|
1384 |
+
# AI ๋ฒ์ญ ํญ ์ด๋ฒคํธ
|
1385 |
+
translate_button.click(
|
1386 |
+
fn=respond,
|
1387 |
+
inputs=[
|
1388 |
+
url_input,
|
1389 |
+
chatbot,
|
1390 |
+
system_message,
|
1391 |
+
max_tokens,
|
1392 |
+
temperature,
|
1393 |
+
top_p,
|
1394 |
+
],
|
1395 |
+
outputs=chatbot
|
1396 |
+
)
|
1397 |
+
|
1398 |
+
# ๊ณ์ ์์ฑ ๋ฒํผ ์ด๋ฒคํธ
|
1399 |
+
continue_button.click(
|
1400 |
+
fn=continue_writing,
|
1401 |
+
inputs=[
|
1402 |
+
chatbot,
|
1403 |
+
system_message,
|
1404 |
+
max_tokens,
|
1405 |
+
temperature,
|
1406 |
+
top_p,
|
1407 |
+
],
|
1408 |
+
outputs=chatbot
|
1409 |
+
)
|
1410 |
+
|
1411 |
iface.launch(
|
1412 |
server_name="0.0.0.0",
|
1413 |
server_port=7860,
|
|
|
1415 |
auth=("gini","pick"),
|
1416 |
ssl_verify=False,
|
1417 |
show_error=True
|
1418 |
+
)
|