Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -7,15 +7,15 @@ import pandas as pd
|
|
7 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
8 |
|
9 |
MAJOR_COUNTRIES = [
|
10 |
-
"United States", "United Kingdom", "Canada", "Australia", "Germany",
|
11 |
-
"France", "Japan", "South Korea", "China", "India",
|
12 |
-
"Brazil", "Mexico", "Russia", "Italy", "Spain",
|
13 |
-
"Netherlands", "Sweden", "Switzerland", "Norway", "Denmark",
|
14 |
-
"Finland", "Belgium", "Austria", "New Zealand", "Ireland",
|
15 |
-
"Singapore", "Hong Kong", "Israel", "United Arab Emirates", "Saudi Arabia",
|
16 |
-
"South Africa", "Turkey", "Egypt", "Poland", "Czech Republic",
|
17 |
-
"Hungary", "Greece", "Portugal", "Argentina", "Chile",
|
18 |
-
"Colombia", "Peru", "Venezuela", "Thailand", "Malaysia",
|
19 |
"Indonesia", "Philippines", "Vietnam", "Pakistan", "Bangladesh"
|
20 |
]
|
21 |
|
@@ -62,7 +62,7 @@ def format_results(results):
|
|
62 |
|
63 |
try:
|
64 |
if isinstance(results, dict) and "error" in results:
|
65 |
-
return
|
66 |
|
67 |
if not isinstance(results, dict):
|
68 |
raise ValueError("๊ฒฐ๊ณผ๊ฐ ์ฌ์ ํ์์ด ์๋๋๋ค.")
|
@@ -89,19 +89,26 @@ def format_results(results):
|
|
89 |
debug_info += f"๋ด์ค ๊ฒฐ๊ณผ ์: {len(news_results)}\n"
|
90 |
|
91 |
if not news_results:
|
92 |
-
return
|
93 |
|
94 |
-
|
95 |
for result in news_results:
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
return
|
105 |
|
106 |
except Exception as e:
|
107 |
error_message = f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
@@ -109,12 +116,12 @@ def format_results(results):
|
|
109 |
debug_info += f"Results structure: {type(results)}\n"
|
110 |
if isinstance(results, dict):
|
111 |
debug_info += f"Results keys: {results.keys()}\n"
|
112 |
-
return
|
113 |
|
114 |
def serphouse_search(query, country, page, num_result):
|
115 |
results = search_serphouse(query, country, page, num_result)
|
116 |
-
|
117 |
-
return
|
118 |
|
119 |
css = """
|
120 |
footer {
|
@@ -131,7 +138,7 @@ iface = gr.Interface(
|
|
131 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
132 |
],
|
133 |
outputs=[
|
134 |
-
gr.
|
135 |
gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", lines=10)
|
136 |
],
|
137 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
@@ -140,6 +147,4 @@ iface = gr.Interface(
|
|
140 |
css=css
|
141 |
)
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
iface.launch(auth=("gini","pick"))
|
|
|
7 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
8 |
|
9 |
MAJOR_COUNTRIES = [
|
10 |
+
"United States", "United Kingdom", "Canada", "Australia", "Germany",
|
11 |
+
"France", "Japan", "South Korea", "China", "India",
|
12 |
+
"Brazil", "Mexico", "Russia", "Italy", "Spain",
|
13 |
+
"Netherlands", "Sweden", "Switzerland", "Norway", "Denmark",
|
14 |
+
"Finland", "Belgium", "Austria", "New Zealand", "Ireland",
|
15 |
+
"Singapore", "Hong Kong", "Israel", "United Arab Emirates", "Saudi Arabia",
|
16 |
+
"South Africa", "Turkey", "Egypt", "Poland", "Czech Republic",
|
17 |
+
"Hungary", "Greece", "Portugal", "Argentina", "Chile",
|
18 |
+
"Colombia", "Peru", "Venezuela", "Thailand", "Malaysia",
|
19 |
"Indonesia", "Philippines", "Vietnam", "Pakistan", "Bangladesh"
|
20 |
]
|
21 |
|
|
|
62 |
|
63 |
try:
|
64 |
if isinstance(results, dict) and "error" in results:
|
65 |
+
return "Error: " + results["error"], debug_info
|
66 |
|
67 |
if not isinstance(results, dict):
|
68 |
raise ValueError("๊ฒฐ๊ณผ๊ฐ ์ฌ์ ํ์์ด ์๋๋๋ค.")
|
|
|
89 |
debug_info += f"๋ด์ค ๊ฒฐ๊ณผ ์: {len(news_results)}\n"
|
90 |
|
91 |
if not news_results:
|
92 |
+
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.", debug_info
|
93 |
|
94 |
+
formatted_articles = ""
|
95 |
for result in news_results:
|
96 |
+
title = result.get("title", "์ ๋ชฉ ์์")
|
97 |
+
link = result.get("url", result.get("link", "#"))
|
98 |
+
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
99 |
+
source = result.get("source", result.get("channel", "์ ์ ์์"))
|
100 |
+
date = result.get("date", result.get("time", "์ ์ ์๋ ์๊ฐ"))
|
101 |
+
|
102 |
+
article_html = f"""
|
103 |
+
<div style="margin-bottom: 20px;">
|
104 |
+
<h3><a href="{link}" target="_blank">{title}</a></h3>
|
105 |
+
<p>{snippet}</p>
|
106 |
+
<p><strong>{source}</strong> - {date}</p>
|
107 |
+
</div>
|
108 |
+
"""
|
109 |
+
formatted_articles += article_html
|
110 |
|
111 |
+
return formatted_articles, debug_info
|
112 |
|
113 |
except Exception as e:
|
114 |
error_message = f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
116 |
debug_info += f"Results structure: {type(results)}\n"
|
117 |
if isinstance(results, dict):
|
118 |
debug_info += f"Results keys: {results.keys()}\n"
|
119 |
+
return "Error: " + error_message, debug_info
|
120 |
|
121 |
def serphouse_search(query, country, page, num_result):
|
122 |
results = search_serphouse(query, country, page, num_result)
|
123 |
+
formatted_articles, debug_info = format_results(results)
|
124 |
+
return formatted_articles, debug_info
|
125 |
|
126 |
css = """
|
127 |
footer {
|
|
|
138 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
139 |
],
|
140 |
outputs=[
|
141 |
+
gr.HTML(label="๋ด์ค ๊ฒฐ๊ณผ"),
|
142 |
gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", lines=10)
|
143 |
],
|
144 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
|
|
147 |
css=css
|
148 |
)
|
149 |
|
150 |
+
iface.launch(auth=("gini","pick"))
|
|
|
|