Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import json
|
@@ -58,7 +59,7 @@ def search_serphouse(query, country, page, num_result):
|
|
58 |
|
59 |
def format_results_from_raw(results):
|
60 |
try:
|
61 |
-
debug_info = f"Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}
|
62 |
|
63 |
if isinstance(results, dict) and "error" in results:
|
64 |
return "Error: " + results["error"], debug_info
|
@@ -89,7 +90,7 @@ def format_results_from_raw(results):
|
|
89 |
time = result.get("time", result.get("date", "์ ์ ์๋ ์๊ฐ"))
|
90 |
image_url = result.get("img", result.get("thumbnail", ""))
|
91 |
|
92 |
-
# base64๋ก ์ธ์ฝ๋ฉ๋ ์ด๋ฏธ์ง๋ฅผ
|
93 |
if image_url and not image_url.startswith("data:image"):
|
94 |
image_html = f'<img src="{image_url}" alt="Image" style="max-width: 100%; height: auto;">'
|
95 |
else:
|
@@ -123,22 +124,35 @@ footer {
|
|
123 |
}
|
124 |
"""
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
gr.
|
133 |
-
|
134 |
-
|
135 |
-
gr.
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
iface.launch(auth=("gini", "pick"))
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import json
|
|
|
59 |
|
60 |
def format_results_from_raw(results):
|
61 |
try:
|
62 |
+
debug_info = f"Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}"
|
63 |
|
64 |
if isinstance(results, dict) and "error" in results:
|
65 |
return "Error: " + results["error"], debug_info
|
|
|
90 |
time = result.get("time", result.get("date", "์ ์ ์๋ ์๊ฐ"))
|
91 |
image_url = result.get("img", result.get("thumbnail", ""))
|
92 |
|
93 |
+
# base64๋ก ์ธ์ฝ๋ฉ๋ ์ด๋ฏธ์ง๋ฅผ ์ฒ๋ฆฌํ์ง ์์
|
94 |
if image_url and not image_url.startswith("data:image"):
|
95 |
image_html = f'<img src="{image_url}" alt="Image" style="max-width: 100%; height: auto;">'
|
96 |
else:
|
|
|
124 |
}
|
125 |
"""
|
126 |
|
127 |
+
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
128 |
+
with gr.Blocks(css=css, title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค") as iface:
|
129 |
+
gr.Markdown("## 24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค")
|
130 |
+
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.")
|
131 |
+
|
132 |
+
with gr.Tab("๊ฒ์"):
|
133 |
+
with gr.Row():
|
134 |
+
query = gr.Textbox(label="๊ฒ์์ด")
|
135 |
+
country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ", value="South Korea")
|
136 |
+
with gr.Row():
|
137 |
+
page = gr.Slider(1, 10, 1, label="ํ์ด์ง")
|
138 |
+
num_result = gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
139 |
+
|
140 |
+
search_button = gr.Button("๊ฒ์")
|
141 |
+
|
142 |
+
with gr.Tab("๋ด์ค ๊ฒฐ๊ณผ"):
|
143 |
+
news_output = gr.HTML(label="๋ด์ค ๊ฒฐ๊ณผ")
|
144 |
+
|
145 |
+
with gr.Tab("๋๋ฒ๊ทธ ์ ๋ณด"):
|
146 |
+
debug_output = gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", lines=10)
|
147 |
+
|
148 |
+
def search_and_display(query, country, page, num_result):
|
149 |
+
articles, debug_info = serphouse_search(query, country, page, num_result)
|
150 |
+
return {news_output: articles, debug_output: debug_info}
|
151 |
+
|
152 |
+
search_button.click(
|
153 |
+
search_and_display,
|
154 |
+
inputs=[query, country, page, num_result],
|
155 |
+
outputs=[news_output, debug_output]
|
156 |
+
)
|
157 |
|
158 |
iface.launch(auth=("gini", "pick"))
|