Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,12 +56,10 @@ def search_serphouse(query, country, page, num_result):
|
|
| 56 |
error_msg += f"\nResponse content: {response.text}"
|
| 57 |
return {"error": error_msg}
|
| 58 |
|
| 59 |
-
def
|
| 60 |
-
debug_info = f"Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}\n\n"
|
| 61 |
-
|
| 62 |
try:
|
| 63 |
if isinstance(results, dict) and "error" in results:
|
| 64 |
-
return "Error: " + results["error"]
|
| 65 |
|
| 66 |
if not isinstance(results, dict):
|
| 67 |
raise ValueError("๊ฒฐ๊ณผ๊ฐ ์ฌ์ ํ์์ด ์๋๋๋ค.")
|
|
@@ -80,7 +78,7 @@ def format_results(results):
|
|
| 80 |
news_results = []
|
| 81 |
|
| 82 |
if not news_results:
|
| 83 |
-
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
| 84 |
|
| 85 |
formatted_articles = ""
|
| 86 |
for result in news_results:
|
|
@@ -107,17 +105,17 @@ def format_results(results):
|
|
| 107 |
"""
|
| 108 |
formatted_articles += article_html
|
| 109 |
|
| 110 |
-
return formatted_articles
|
| 111 |
|
| 112 |
except Exception as e:
|
| 113 |
-
|
| 114 |
-
debug_info += f"Error: {error_message}\n"
|
| 115 |
-
return "Error: " + error_message, debug_info
|
| 116 |
|
| 117 |
def serphouse_search(query, country, page, num_result):
|
| 118 |
results = search_serphouse(query, country, page, num_result)
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
|
| 122 |
css = """
|
| 123 |
footer {
|
|
@@ -134,8 +132,8 @@ iface = gr.Interface(
|
|
| 134 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
| 135 |
],
|
| 136 |
outputs=[
|
| 137 |
-
gr.HTML(label="๋ด์ค ๊ฒฐ๊ณผ"),
|
| 138 |
-
gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", lines=10)
|
| 139 |
],
|
| 140 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
| 141 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.",
|
|
|
|
| 56 |
error_msg += f"\nResponse content: {response.text}"
|
| 57 |
return {"error": error_msg}
|
| 58 |
|
| 59 |
+
def format_results_from_raw(results):
|
|
|
|
|
|
|
| 60 |
try:
|
| 61 |
if isinstance(results, dict) and "error" in results:
|
| 62 |
+
return "Error: " + results["error"]
|
| 63 |
|
| 64 |
if not isinstance(results, dict):
|
| 65 |
raise ValueError("๊ฒฐ๊ณผ๊ฐ ์ฌ์ ํ์์ด ์๋๋๋ค.")
|
|
|
|
| 78 |
news_results = []
|
| 79 |
|
| 80 |
if not news_results:
|
| 81 |
+
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
| 82 |
|
| 83 |
formatted_articles = ""
|
| 84 |
for result in news_results:
|
|
|
|
| 105 |
"""
|
| 106 |
formatted_articles += article_html
|
| 107 |
|
| 108 |
+
return formatted_articles
|
| 109 |
|
| 110 |
except Exception as e:
|
| 111 |
+
return f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
|
|
|
|
| 112 |
|
| 113 |
def serphouse_search(query, country, page, num_result):
|
| 114 |
results = search_serphouse(query, country, page, num_result)
|
| 115 |
+
# ๋๋ฒ๊ทธ ์ ๋ณด ์์ฑ
|
| 116 |
+
debug_info = f"Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}\n\n"
|
| 117 |
+
# Raw API Response์ ๋๋ฒ๊ทธ ์ ๋ณด ๋ฐํ
|
| 118 |
+
return results, debug_info
|
| 119 |
|
| 120 |
css = """
|
| 121 |
footer {
|
|
|
|
| 132 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
| 133 |
],
|
| 134 |
outputs=[
|
| 135 |
+
gr.HTML(label="๋ด์ค ๊ฒฐ๊ณผ", value=lambda results, debug_info: format_results_from_raw(results)),
|
| 136 |
+
gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", lines=10, value=lambda results, debug_info: debug_info)
|
| 137 |
],
|
| 138 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
| 139 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.",
|