Update app.py
Browse files
app.py
CHANGED
@@ -57,15 +57,8 @@ def search_serphouse(query, country, page, num_result):
|
|
57 |
return {"error": error_msg}
|
58 |
|
59 |
def format_results(results):
|
60 |
-
all_results = "<h2>๋ชจ๋ ๋ด์ค ๊ฒฐ๊ณผ (24์๊ฐ ์ด๋ด)</h2>"
|
61 |
-
debug_info = "<h2>๋๋ฒ๊ทธ ์ ๋ณด</h2>"
|
62 |
-
|
63 |
if isinstance(results, dict) and "error" in results:
|
64 |
-
|
65 |
-
debug_info += f"<pre>{results['error']}</pre>"
|
66 |
-
return all_results, debug_info
|
67 |
-
|
68 |
-
debug_info += f"<pre>{json.dumps(results, indent=2, ensure_ascii=False)}</pre>"
|
69 |
|
70 |
try:
|
71 |
if not isinstance(results, dict):
|
@@ -75,52 +68,38 @@ def format_results(results):
|
|
75 |
raise ValueError("'results' ํค๊ฐ ์๋ต์ ์์ต๋๋ค.")
|
76 |
|
77 |
news_results = results["results"].get("news", [])
|
78 |
-
debug_info += f"<p>๋ด์ค ๊ฒฐ๊ณผ ์: {len(news_results)}</p>"
|
79 |
|
80 |
if not news_results:
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
article_info = f"""
|
92 |
-
<li>
|
93 |
-
<h3><a href="{url}" target="_blank">{title}</a></h3>
|
94 |
-
<p>{snippet}</p>
|
95 |
-
<p><strong>์ถ์ฒ:</strong> {channel} - {time_str}</p>
|
96 |
-
</li>
|
97 |
-
"""
|
98 |
-
all_results += article_info
|
99 |
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
except Exception as e:
|
103 |
-
|
104 |
-
debug_info += f"<p>{error_message}</p>"
|
105 |
-
all_results += f"<p>{error_message}</p>"
|
106 |
-
|
107 |
-
return all_results, debug_info
|
108 |
|
109 |
def serphouse_search(query, country, page, num_result):
|
110 |
results = search_serphouse(query, country, page, num_result)
|
111 |
-
|
112 |
-
return all_results, debug_info
|
113 |
|
114 |
css = """
|
115 |
footer {
|
116 |
visibility: hidden;
|
117 |
}
|
118 |
-
ol {
|
119 |
-
padding-left: 20px;
|
120 |
-
}
|
121 |
-
li {
|
122 |
-
margin-bottom: 20px;
|
123 |
-
}
|
124 |
"""
|
125 |
|
126 |
iface = gr.Interface(
|
@@ -131,12 +110,7 @@ iface = gr.Interface(
|
|
131 |
gr.Slider(1, 10, 1, label="ํ์ด์ง"),
|
132 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
133 |
],
|
134 |
-
outputs=
|
135 |
-
gr.HTML(label="๋ชจ๋ ๊ฒฐ๊ณผ"),
|
136 |
-
gr.HTML(label="๋๋ฒ๊ทธ ์ ๋ณด")
|
137 |
-
],
|
138 |
-
|
139 |
-
|
140 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
141 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.",
|
142 |
theme="Nymbo/Nymbo_Theme",
|
|
|
57 |
return {"error": error_msg}
|
58 |
|
59 |
def format_results(results):
|
|
|
|
|
|
|
60 |
if isinstance(results, dict) and "error" in results:
|
61 |
+
return [f"์ค๋ฅ ๋ฐ์: {results['error']}"]
|
|
|
|
|
|
|
|
|
62 |
|
63 |
try:
|
64 |
if not isinstance(results, dict):
|
|
|
68 |
raise ValueError("'results' ํค๊ฐ ์๋ต์ ์์ต๋๋ค.")
|
69 |
|
70 |
news_results = results["results"].get("news", [])
|
|
|
71 |
|
72 |
if not news_results:
|
73 |
+
return ["๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."]
|
74 |
+
|
75 |
+
formatted_results = []
|
76 |
+
for result in news_results:
|
77 |
+
title = result.get("title", "์ ๋ชฉ ์์")
|
78 |
+
url = result.get("url", "#")
|
79 |
+
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
80 |
+
channel = result.get("channel", "์ ์ ์์")
|
81 |
+
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
article_info = f"""์ ๋ชฉ: {title}
|
84 |
+
๋งํฌ: {url}
|
85 |
+
๋ด์ฉ: {snippet}
|
86 |
+
์ถ์ฒ: {channel} - {time_str}
|
87 |
+
---"""
|
88 |
+
formatted_results.append(article_info)
|
89 |
+
|
90 |
+
return formatted_results
|
91 |
|
92 |
except Exception as e:
|
93 |
+
return [f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"]
|
|
|
|
|
|
|
|
|
94 |
|
95 |
def serphouse_search(query, country, page, num_result):
|
96 |
results = search_serphouse(query, country, page, num_result)
|
97 |
+
return format_results(results)
|
|
|
98 |
|
99 |
css = """
|
100 |
footer {
|
101 |
visibility: hidden;
|
102 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
"""
|
104 |
|
105 |
iface = gr.Interface(
|
|
|
110 |
gr.Slider(1, 10, 1, label="ํ์ด์ง"),
|
111 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
112 |
],
|
113 |
+
outputs=gr.outputs.Textbox(label="๋ด์ค ๊ฒฐ๊ณผ", lines=20),
|
|
|
|
|
|
|
|
|
|
|
114 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
115 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.",
|
116 |
theme="Nymbo/Nymbo_Theme",
|