Spaces:
Building
Building
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시간 이내의 뉴스 결과를 가져옵니다.",
|