Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -36,21 +36,14 @@ KOREAN_COMPANIES = [
|
|
36 |
|
37 |
def convert_to_seoul_time(timestamp_str):
|
38 |
try:
|
39 |
-
# ์
๋ ฅ๋ ์๊ฐ์ naive datetime ๊ฐ์ฒด๋ก ๋ณํ
|
40 |
dt = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S')
|
41 |
-
|
42 |
-
# ์์ธ ์๊ฐ๋ ์ค์
|
43 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
44 |
-
|
45 |
-
# ํ์ฌ ์๊ฐ์ ์์ธ ์๊ฐ์ผ๋ก ์ธ์ํ๋๋ก ์์
|
46 |
seoul_time = seoul_tz.localize(dt)
|
47 |
-
|
48 |
return seoul_time.strftime('%Y-%m-%d %H:%M:%S KST')
|
49 |
except Exception as e:
|
50 |
print(f"์๊ฐ ๋ณํ ์ค๋ฅ: {str(e)}")
|
51 |
return timestamp_str
|
52 |
|
53 |
-
|
54 |
def analyze_sentiment_batch(articles, client):
|
55 |
try:
|
56 |
# ๋ชจ๋ ๊ธฐ์ฌ์ ์ ๋ชฉ๊ณผ ๋ด์ฉ์ ํ๋์ ํ
์คํธ๋ก ๊ฒฐํฉ
|
@@ -58,8 +51,9 @@ def analyze_sentiment_batch(articles, client):
|
|
58 |
f"์ ๋ชฉ: {article.get('title', '')}\n๋ด์ฉ: {article.get('snippet', '')}"
|
59 |
for article in articles
|
60 |
])
|
61 |
-
|
62 |
-
|
|
|
63 |
|
64 |
๋ด์ค ๋ด์ฉ:
|
65 |
{combined_text}
|
@@ -74,7 +68,7 @@ def analyze_sentiment_batch(articles, client):
|
|
74 |
- [ํญ๋ชฉ2]
|
75 |
4. ์ข
ํฉ ํ๊ฐ: [์์ธ ์ค๋ช
]
|
76 |
"""
|
77 |
-
|
78 |
response = client.chat.completions.create(
|
79 |
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
80 |
messages=[{"role": "user", "content": prompt}],
|
@@ -101,27 +95,20 @@ def init_db():
|
|
101 |
conn.commit()
|
102 |
conn.close()
|
103 |
|
104 |
-
|
105 |
def save_to_db(keyword, country, results):
|
106 |
conn = sqlite3.connect("search_results.db")
|
107 |
c = conn.cursor()
|
108 |
-
|
109 |
-
# ํ์ฌ ์๊ฐ์ ์์ธ ์๊ฐ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ
|
110 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
111 |
now = datetime.now(seoul_tz)
|
112 |
-
|
113 |
-
# ์๊ฐ๋ ์ ๋ณด๋ฅผ ์ ๊ฑฐํ๊ณ ์ ์ฅ
|
114 |
timestamp = now.strftime('%Y-%m-%d %H:%M:%S')
|
115 |
|
116 |
c.execute("""INSERT INTO searches
|
117 |
(keyword, country, results, timestamp)
|
118 |
VALUES (?, ?, ?, ?)""",
|
119 |
(keyword, country, json.dumps(results), timestamp))
|
120 |
-
|
121 |
conn.commit()
|
122 |
conn.close()
|
123 |
|
124 |
-
|
125 |
def load_from_db(keyword, country):
|
126 |
conn = sqlite3.connect("search_results.db")
|
127 |
c = conn.cursor()
|
@@ -133,7 +120,6 @@ def load_from_db(keyword, country):
|
|
133 |
return json.loads(result[0]), convert_to_seoul_time(result[1])
|
134 |
return None, None
|
135 |
|
136 |
-
|
137 |
def display_results(articles):
|
138 |
output = ""
|
139 |
for idx, article in enumerate(articles, 1):
|
@@ -144,7 +130,6 @@ def display_results(articles):
|
|
144 |
output += f"์์ฝ: {article['snippet']}\n\n"
|
145 |
return output
|
146 |
|
147 |
-
|
148 |
def search_company(company):
|
149 |
error_message, articles = serphouse_search(company, "United States")
|
150 |
if not error_message and articles:
|
@@ -152,14 +137,12 @@ def search_company(company):
|
|
152 |
return display_results(articles)
|
153 |
return f"{company}์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
154 |
|
155 |
-
|
156 |
def load_company(company):
|
157 |
results, timestamp = load_from_db(company, "United States")
|
158 |
if results:
|
159 |
return f"### {company} ๊ฒ์ ๊ฒฐ๊ณผ\n์ ์ฅ ์๊ฐ: {timestamp}\n\n" + display_results(results)
|
160 |
return f"{company}์ ๋ํ ์ ์ฅ๋ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
161 |
|
162 |
-
|
163 |
def show_stats():
|
164 |
conn = sqlite3.connect("search_results.db")
|
165 |
c = conn.cursor()
|
@@ -186,7 +169,6 @@ def show_stats():
|
|
186 |
output += f"- ์ ์ฅ๋ ๊ธฐ์ฌ ์: {len(articles)}๊ฑด\n\n"
|
187 |
|
188 |
if articles:
|
189 |
-
# ์ ์ฒด ๊ธฐ์ฌ์ ๋ํ ๊ฐ์ฑ ๋ถ์
|
190 |
sentiment_analysis = analyze_sentiment_batch(articles, client)
|
191 |
output += "#### ๋ด์ค ๊ฐ์ฑ ๋ถ์\n"
|
192 |
output += f"{sentiment_analysis}\n\n"
|
@@ -196,11 +178,7 @@ def show_stats():
|
|
196 |
conn.close()
|
197 |
return output
|
198 |
|
199 |
-
|
200 |
def search_all_companies():
|
201 |
-
"""
|
202 |
-
๋ฑ๋ก๋ ๋ชจ๋ ๊ธฐ์
์ ๋ํด ์์ฐจ์ ์ผ๋ก ๊ฒ์ ์ํ ํ ๊ฒฐ๊ณผ๋ฅผ ํฉ์ณ์ ๋ฐํ
|
203 |
-
"""
|
204 |
overall_result = "# [์ ์ฒด ๊ฒ์ ๊ฒฐ๊ณผ]\n\n"
|
205 |
for comp in KOREAN_COMPANIES:
|
206 |
overall_result += f"## {comp}\n"
|
@@ -209,9 +187,6 @@ def search_all_companies():
|
|
209 |
return overall_result
|
210 |
|
211 |
def load_all_companies():
|
212 |
-
"""
|
213 |
-
๋ฑ๋ก๋ ๋ชจ๋ ๊ธฐ์
์ ๋ํด DB์ ์ ์ฅ๋ ๊ฒฐ๊ณผ๋ฅผ ์์ฐจ์ ์ผ๋ก ๋ถ๋ฌ์์ ํฉ์ณ์ ๋ฐํ
|
214 |
-
"""
|
215 |
overall_result = "# [์ ์ฒด ์ถ๋ ฅ ๊ฒฐ๊ณผ]\n\n"
|
216 |
for comp in KOREAN_COMPANIES:
|
217 |
overall_result += f"## {comp}\n"
|
@@ -220,21 +195,13 @@ def load_all_companies():
|
|
220 |
return overall_result
|
221 |
|
222 |
def full_summary_report():
|
223 |
-
"""
|
224 |
-
'์ ์ฒด ๋ถ์ ๋ณด๊ณ ์์ฝ' ๋ฒํผ ํด๋ฆญ ์,
|
225 |
-
1) ์ ์ฒด ๊ฒ์ -> 2) ์ ์ฒด ์ถ๋ ฅ -> 3) ์ ์ฒด ํต๊ณ(๊ฐ์ฑ ๋ถ์)
|
226 |
-
์์ผ๋ก ์คํํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ํ ๋ฒ์ ๋ฆฌํด
|
227 |
-
"""
|
228 |
# 1) ์ ์ฒด ๊ฒ์
|
229 |
search_result_text = search_all_companies()
|
230 |
-
|
231 |
# 2) ์ ์ฒด ์ถ๋ ฅ
|
232 |
load_result_text = load_all_companies()
|
233 |
-
|
234 |
# 3) ์ ์ฒด ํต๊ณ
|
235 |
stats_text = show_stats()
|
236 |
|
237 |
-
# ์ต์ข
๋ณด๊ณ ์ ํํ๋ก ํฉ์ณ์ ๋ฐํ
|
238 |
combined_report = (
|
239 |
"# ์ ์ฒด ๋ถ์ ๋ณด๊ณ ์์ฝ\n\n"
|
240 |
"์๋ ์์๋ก ์คํ๋์์ต๋๋ค:\n"
|
@@ -246,7 +213,6 @@ def full_summary_report():
|
|
246 |
)
|
247 |
return combined_report
|
248 |
|
249 |
-
|
250 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
251 |
if not ACCESS_TOKEN:
|
252 |
raise ValueError("HF_TOKEN environment variable is not set")
|
@@ -258,8 +224,6 @@ client = OpenAI(
|
|
258 |
|
259 |
API_KEY = os.getenv("SERPHOUSE_API_KEY")
|
260 |
|
261 |
-
|
262 |
-
# ๊ตญ๊ฐ๋ณ ์ธ์ด ์ฝ๋ ๋งคํ (์ฒซ ๋ฒ์งธ ํญ์์๋ 'United States'๋ง ์ฃผ๋ก ์ฌ์ฉ)
|
263 |
COUNTRY_LANGUAGES = {
|
264 |
"United States": "en",
|
265 |
"KOREA": "ko",
|
@@ -325,10 +289,10 @@ COUNTRY_LANGUAGES = {
|
|
325 |
"Latvia": "lv",
|
326 |
"Lithuania": "lt",
|
327 |
"Slovenia": "sl",
|
328 |
-
"Luxembourg": "
|
329 |
-
"Malta": "
|
330 |
-
"Cyprus": "
|
331 |
-
"Iceland": "
|
332 |
}
|
333 |
|
334 |
COUNTRY_LOCATIONS = {
|
@@ -402,17 +366,15 @@ COUNTRY_LOCATIONS = {
|
|
402 |
"Iceland": "Iceland"
|
403 |
}
|
404 |
|
405 |
-
|
406 |
@lru_cache(maxsize=100)
|
407 |
def translate_query(query, country):
|
408 |
try:
|
409 |
if is_english(query):
|
410 |
return query
|
411 |
-
|
412 |
if country in COUNTRY_LANGUAGES:
|
413 |
if country == "South Korea":
|
414 |
return query
|
415 |
-
|
416 |
target_lang = COUNTRY_LANGUAGES[country]
|
417 |
|
418 |
url = "https://translate.googleapis.com/translate_a/single"
|
@@ -438,11 +400,9 @@ def translate_query(query, country):
|
|
438 |
print(f"๋ฒ์ญ ์ค๋ฅ: {str(e)}")
|
439 |
return query
|
440 |
|
441 |
-
|
442 |
def is_english(text):
|
443 |
return all(ord(char) < 128 for char in text.replace(' ', '').replace('-', '').replace('_', ''))
|
444 |
|
445 |
-
|
446 |
def search_serphouse(query, country, page=1, num_result=10):
|
447 |
url = "https://api.serphouse.com/serp/live"
|
448 |
|
@@ -513,7 +473,6 @@ def search_serphouse(query, country, page=1, num_result=10):
|
|
513 |
"translated_query": query
|
514 |
}
|
515 |
|
516 |
-
|
517 |
def format_results_from_raw(response_data):
|
518 |
if "error" in response_data:
|
519 |
return "Error: " + response_data["error"], []
|
@@ -525,8 +484,7 @@ def format_results_from_raw(response_data):
|
|
525 |
news_results = results.get('results', {}).get('results', {}).get('news', [])
|
526 |
if not news_results:
|
527 |
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.", []
|
528 |
-
|
529 |
-
# ํ๊ตญ ๋๋ฉ์ธ ๋ฐ ํ๊ตญ ๊ด๋ จ ํค์๋ ํํฐ๋ง
|
530 |
korean_domains = [
|
531 |
'.kr', 'korea', 'korean', 'yonhap', 'hankyung', 'chosun',
|
532 |
'donga', 'joins', 'hani', 'koreatimes', 'koreaherald'
|
@@ -542,7 +500,6 @@ def format_results_from_raw(response_data):
|
|
542 |
title = result.get("title", "").lower()
|
543 |
channel = result.get("channel", result.get("source", "")).lower()
|
544 |
|
545 |
-
# ํ๊ตญ ๊ด๋ จ ์ปจํ
์ธ ํํฐ๋ง
|
546 |
is_korean_content = (
|
547 |
any(domain in url or domain in channel for domain in korean_domains) or
|
548 |
any(keyword in title.lower() for keyword in korean_keywords)
|
@@ -564,12 +521,10 @@ def format_results_from_raw(response_data):
|
|
564 |
except Exception as e:
|
565 |
return f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}", []
|
566 |
|
567 |
-
|
568 |
def serphouse_search(query, country):
|
569 |
response_data = search_serphouse(query, country)
|
570 |
return format_results_from_raw(response_data)
|
571 |
|
572 |
-
|
573 |
css = """
|
574 |
/* ์ ์ญ ์คํ์ผ */
|
575 |
footer {visibility: hidden;}
|
@@ -745,7 +700,6 @@ footer {visibility: hidden;}
|
|
745 |
}
|
746 |
"""
|
747 |
|
748 |
-
|
749 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น์ค") as iface:
|
750 |
init_db()
|
751 |
|
@@ -755,18 +709,15 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น
|
|
755 |
gr.Markdown("## ํ๊ตญ ์ฃผ์ ๊ธฐ์
๋ฏธ๊ตญ ๋ด์ค DB")
|
756 |
gr.Markdown("๊ฐ ๊ธฐ์
์ ๋ฏธ๊ตญ ๋ด์ค๋ฅผ ๊ฒ์ํ์ฌ DB์ ์ ์ฅํ๊ณ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค.")
|
757 |
|
758 |
-
# (์์ ) ์๋จ์ '์ ์ฒด ๋ถ์ ๋ณด๊ณ ์์ฝ' ๋ฒํผ์ ๋ฐฐ์น
|
759 |
with gr.Row():
|
760 |
full_report_btn = gr.Button("์ ์ฒด ๋ถ์ ๋ณด๊ณ ์์ฝ", variant="primary")
|
761 |
full_report_display = gr.Markdown()
|
762 |
|
763 |
-
# ๋ฒํผ ํด๋ฆญ ์ full_summary_report() ์คํ
|
764 |
full_report_btn.click(
|
765 |
fn=full_summary_report,
|
766 |
outputs=full_report_display
|
767 |
)
|
768 |
|
769 |
-
# ์ดํ ๊ฐ๋ณ ๊ธฐ์
๊ฒ์/์ถ๋ ฅ UI
|
770 |
with gr.Column():
|
771 |
for i in range(0, len(KOREAN_COMPANIES), 2):
|
772 |
with gr.Row():
|
|
|
36 |
|
37 |
def convert_to_seoul_time(timestamp_str):
|
38 |
try:
|
|
|
39 |
dt = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
40 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
|
|
|
|
41 |
seoul_time = seoul_tz.localize(dt)
|
|
|
42 |
return seoul_time.strftime('%Y-%m-%d %H:%M:%S KST')
|
43 |
except Exception as e:
|
44 |
print(f"์๊ฐ ๋ณํ ์ค๋ฅ: {str(e)}")
|
45 |
return timestamp_str
|
46 |
|
|
|
47 |
def analyze_sentiment_batch(articles, client):
|
48 |
try:
|
49 |
# ๋ชจ๋ ๊ธฐ์ฌ์ ์ ๋ชฉ๊ณผ ๋ด์ฉ์ ํ๋์ ํ
์คํธ๋ก ๊ฒฐํฉ
|
|
|
51 |
f"์ ๋ชฉ: {article.get('title', '')}\n๋ด์ฉ: {article.get('snippet', '')}"
|
52 |
for article in articles
|
53 |
])
|
54 |
+
|
55 |
+
# f""" ... """ ํํ๋ก ์ฌ๋ฌ ์ค ๋ฌธ์์ด์ ์ ํํ ์ฌ์ฉ
|
56 |
+
prompt = f"""๋ค์ ๋ด์ค ๋ชจ์์ ๋ํด ์ ๋ฐ์ ์ธ ๊ฐ์ฑ ๋ถ์์ ์ํํ์ธ์:
|
57 |
|
58 |
๋ด์ค ๋ด์ฉ:
|
59 |
{combined_text}
|
|
|
68 |
- [ํญ๋ชฉ2]
|
69 |
4. ์ข
ํฉ ํ๊ฐ: [์์ธ ์ค๋ช
]
|
70 |
"""
|
71 |
+
|
72 |
response = client.chat.completions.create(
|
73 |
model="CohereForAI/c4ai-command-r-plus-08-2024",
|
74 |
messages=[{"role": "user", "content": prompt}],
|
|
|
95 |
conn.commit()
|
96 |
conn.close()
|
97 |
|
|
|
98 |
def save_to_db(keyword, country, results):
|
99 |
conn = sqlite3.connect("search_results.db")
|
100 |
c = conn.cursor()
|
|
|
|
|
101 |
seoul_tz = pytz.timezone('Asia/Seoul')
|
102 |
now = datetime.now(seoul_tz)
|
|
|
|
|
103 |
timestamp = now.strftime('%Y-%m-%d %H:%M:%S')
|
104 |
|
105 |
c.execute("""INSERT INTO searches
|
106 |
(keyword, country, results, timestamp)
|
107 |
VALUES (?, ?, ?, ?)""",
|
108 |
(keyword, country, json.dumps(results), timestamp))
|
|
|
109 |
conn.commit()
|
110 |
conn.close()
|
111 |
|
|
|
112 |
def load_from_db(keyword, country):
|
113 |
conn = sqlite3.connect("search_results.db")
|
114 |
c = conn.cursor()
|
|
|
120 |
return json.loads(result[0]), convert_to_seoul_time(result[1])
|
121 |
return None, None
|
122 |
|
|
|
123 |
def display_results(articles):
|
124 |
output = ""
|
125 |
for idx, article in enumerate(articles, 1):
|
|
|
130 |
output += f"์์ฝ: {article['snippet']}\n\n"
|
131 |
return output
|
132 |
|
|
|
133 |
def search_company(company):
|
134 |
error_message, articles = serphouse_search(company, "United States")
|
135 |
if not error_message and articles:
|
|
|
137 |
return display_results(articles)
|
138 |
return f"{company}์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
139 |
|
|
|
140 |
def load_company(company):
|
141 |
results, timestamp = load_from_db(company, "United States")
|
142 |
if results:
|
143 |
return f"### {company} ๊ฒ์ ๊ฒฐ๊ณผ\n์ ์ฅ ์๊ฐ: {timestamp}\n\n" + display_results(results)
|
144 |
return f"{company}์ ๋ํ ์ ์ฅ๋ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
145 |
|
|
|
146 |
def show_stats():
|
147 |
conn = sqlite3.connect("search_results.db")
|
148 |
c = conn.cursor()
|
|
|
169 |
output += f"- ์ ์ฅ๋ ๊ธฐ์ฌ ์: {len(articles)}๊ฑด\n\n"
|
170 |
|
171 |
if articles:
|
|
|
172 |
sentiment_analysis = analyze_sentiment_batch(articles, client)
|
173 |
output += "#### ๋ด์ค ๊ฐ์ฑ ๋ถ์\n"
|
174 |
output += f"{sentiment_analysis}\n\n"
|
|
|
178 |
conn.close()
|
179 |
return output
|
180 |
|
|
|
181 |
def search_all_companies():
|
|
|
|
|
|
|
182 |
overall_result = "# [์ ์ฒด ๊ฒ์ ๊ฒฐ๊ณผ]\n\n"
|
183 |
for comp in KOREAN_COMPANIES:
|
184 |
overall_result += f"## {comp}\n"
|
|
|
187 |
return overall_result
|
188 |
|
189 |
def load_all_companies():
|
|
|
|
|
|
|
190 |
overall_result = "# [์ ์ฒด ์ถ๋ ฅ ๊ฒฐ๊ณผ]\n\n"
|
191 |
for comp in KOREAN_COMPANIES:
|
192 |
overall_result += f"## {comp}\n"
|
|
|
195 |
return overall_result
|
196 |
|
197 |
def full_summary_report():
|
|
|
|
|
|
|
|
|
|
|
198 |
# 1) ์ ์ฒด ๊ฒ์
|
199 |
search_result_text = search_all_companies()
|
|
|
200 |
# 2) ์ ์ฒด ์ถ๋ ฅ
|
201 |
load_result_text = load_all_companies()
|
|
|
202 |
# 3) ์ ์ฒด ํต๊ณ
|
203 |
stats_text = show_stats()
|
204 |
|
|
|
205 |
combined_report = (
|
206 |
"# ์ ์ฒด ๋ถ์ ๋ณด๊ณ ์์ฝ\n\n"
|
207 |
"์๋ ์์๋ก ์คํ๋์์ต๋๋ค:\n"
|
|
|
213 |
)
|
214 |
return combined_report
|
215 |
|
|
|
216 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
217 |
if not ACCESS_TOKEN:
|
218 |
raise ValueError("HF_TOKEN environment variable is not set")
|
|
|
224 |
|
225 |
API_KEY = os.getenv("SERPHOUSE_API_KEY")
|
226 |
|
|
|
|
|
227 |
COUNTRY_LANGUAGES = {
|
228 |
"United States": "en",
|
229 |
"KOREA": "ko",
|
|
|
289 |
"Latvia": "lv",
|
290 |
"Lithuania": "lt",
|
291 |
"Slovenia": "sl",
|
292 |
+
"Luxembourg": "Luxembourg",
|
293 |
+
"Malta": "Malta",
|
294 |
+
"Cyprus": "Cyprus",
|
295 |
+
"Iceland": "Iceland"
|
296 |
}
|
297 |
|
298 |
COUNTRY_LOCATIONS = {
|
|
|
366 |
"Iceland": "Iceland"
|
367 |
}
|
368 |
|
|
|
369 |
@lru_cache(maxsize=100)
|
370 |
def translate_query(query, country):
|
371 |
try:
|
372 |
if is_english(query):
|
373 |
return query
|
374 |
+
|
375 |
if country in COUNTRY_LANGUAGES:
|
376 |
if country == "South Korea":
|
377 |
return query
|
|
|
378 |
target_lang = COUNTRY_LANGUAGES[country]
|
379 |
|
380 |
url = "https://translate.googleapis.com/translate_a/single"
|
|
|
400 |
print(f"๋ฒ์ญ ์ค๋ฅ: {str(e)}")
|
401 |
return query
|
402 |
|
|
|
403 |
def is_english(text):
|
404 |
return all(ord(char) < 128 for char in text.replace(' ', '').replace('-', '').replace('_', ''))
|
405 |
|
|
|
406 |
def search_serphouse(query, country, page=1, num_result=10):
|
407 |
url = "https://api.serphouse.com/serp/live"
|
408 |
|
|
|
473 |
"translated_query": query
|
474 |
}
|
475 |
|
|
|
476 |
def format_results_from_raw(response_data):
|
477 |
if "error" in response_data:
|
478 |
return "Error: " + response_data["error"], []
|
|
|
484 |
news_results = results.get('results', {}).get('results', {}).get('news', [])
|
485 |
if not news_results:
|
486 |
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.", []
|
487 |
+
|
|
|
488 |
korean_domains = [
|
489 |
'.kr', 'korea', 'korean', 'yonhap', 'hankyung', 'chosun',
|
490 |
'donga', 'joins', 'hani', 'koreatimes', 'koreaherald'
|
|
|
500 |
title = result.get("title", "").lower()
|
501 |
channel = result.get("channel", result.get("source", "")).lower()
|
502 |
|
|
|
503 |
is_korean_content = (
|
504 |
any(domain in url or domain in channel for domain in korean_domains) or
|
505 |
any(keyword in title.lower() for keyword in korean_keywords)
|
|
|
521 |
except Exception as e:
|
522 |
return f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}", []
|
523 |
|
|
|
524 |
def serphouse_search(query, country):
|
525 |
response_data = search_serphouse(query, country)
|
526 |
return format_results_from_raw(response_data)
|
527 |
|
|
|
528 |
css = """
|
529 |
/* ์ ์ญ ์คํ์ผ */
|
530 |
footer {visibility: hidden;}
|
|
|
700 |
}
|
701 |
"""
|
702 |
|
|
|
703 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์๋น์ค") as iface:
|
704 |
init_db()
|
705 |
|
|
|
709 |
gr.Markdown("## ํ๊ตญ ์ฃผ์ ๊ธฐ์
๋ฏธ๊ตญ ๋ด์ค DB")
|
710 |
gr.Markdown("๊ฐ ๊ธฐ์
์ ๋ฏธ๊ตญ ๋ด์ค๋ฅผ ๊ฒ์ํ์ฌ DB์ ์ ์ฅํ๊ณ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค.")
|
711 |
|
|
|
712 |
with gr.Row():
|
713 |
full_report_btn = gr.Button("์ ์ฒด ๋ถ์ ๋ณด๊ณ ์์ฝ", variant="primary")
|
714 |
full_report_display = gr.Markdown()
|
715 |
|
|
|
716 |
full_report_btn.click(
|
717 |
fn=full_summary_report,
|
718 |
outputs=full_report_display
|
719 |
)
|
720 |
|
|
|
721 |
with gr.Column():
|
722 |
for i in range(0, len(KOREAN_COMPANIES), 2):
|
723 |
with gr.Row():
|