Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -66,7 +66,20 @@ def is_recent_news(time_str):
|
|
66 |
return False
|
67 |
|
68 |
def format_results(results):
|
69 |
-
html_output = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
try:
|
72 |
if isinstance(results, dict) and "results" in results and "news" in results["results"]:
|
@@ -89,6 +102,9 @@ def format_results(results):
|
|
89 |
except Exception as e:
|
90 |
html_output += f'<p class="no-results">Error processing results: {str(e)}</p>'
|
91 |
|
|
|
|
|
|
|
92 |
html_output += "</div>"
|
93 |
return html_output
|
94 |
|
@@ -96,17 +112,25 @@ def serphouse_search(query, country, page, num_result):
|
|
96 |
results = search_serphouse(query, country, page, num_result)
|
97 |
return format_results(results)
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
iface = gr.Interface(
|
100 |
fn=serphouse_search,
|
101 |
inputs=[
|
102 |
gr.Textbox(label="Search Query"),
|
103 |
-
gr.Dropdown(
|
104 |
-
gr.Slider(
|
105 |
-
gr.Slider(
|
106 |
],
|
107 |
outputs="html",
|
108 |
-
title="
|
109 |
-
|
|
|
|
|
110 |
)
|
111 |
|
112 |
-
iface.launch()
|
|
|
66 |
return False
|
67 |
|
68 |
def format_results(results):
|
69 |
+
html_output = """
|
70 |
+
<style>
|
71 |
+
.news-container { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; }
|
72 |
+
.news-item { background-color: #f9f9f9; border: 1px solid #ddd; padding: 20px; margin-bottom: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
73 |
+
.news-title { font-size: 20px; color: #1a0dab; text-decoration: none; font-weight: bold; }
|
74 |
+
.news-title:hover { text-decoration: underline; }
|
75 |
+
.news-snippet { color: #545454; margin: 15px 0; line-height: 1.4; }
|
76 |
+
.news-meta { font-size: 14px; color: #006621; }
|
77 |
+
.no-results { text-align: center; color: #666; font-style: italic; }
|
78 |
+
.debug-info { background-color: #f0f0f0; padding: 10px; margin-top: 20px; border-radius: 5px; white-space: pre-wrap; }
|
79 |
+
</style>
|
80 |
+
<div class="news-container">
|
81 |
+
<h2 style="text-align: center; color: #333;">Recent News Results</h2>
|
82 |
+
"""
|
83 |
|
84 |
try:
|
85 |
if isinstance(results, dict) and "results" in results and "news" in results["results"]:
|
|
|
102 |
except Exception as e:
|
103 |
html_output += f'<p class="no-results">Error processing results: {str(e)}</p>'
|
104 |
|
105 |
+
# 디버그 정보 추가
|
106 |
+
html_output += f'<div class="debug-info"><h3>Debug Info:</h3><pre>{json.dumps(results, indent=2)}</pre></div>'
|
107 |
+
|
108 |
html_output += "</div>"
|
109 |
return html_output
|
110 |
|
|
|
112 |
results = search_serphouse(query, country, page, num_result)
|
113 |
return format_results(results)
|
114 |
|
115 |
+
css = """
|
116 |
+
footer {
|
117 |
+
visibility: hidden;
|
118 |
+
}
|
119 |
+
"""
|
120 |
+
|
121 |
iface = gr.Interface(
|
122 |
fn=serphouse_search,
|
123 |
inputs=[
|
124 |
gr.Textbox(label="Search Query"),
|
125 |
+
gr.Dropdown(MAJOR_COUNTRIES, label="Country"),
|
126 |
+
gr.Slider(1, 10, 1, label="Page"),
|
127 |
+
gr.Slider(1, 100, 10, label="Number of Results")
|
128 |
],
|
129 |
outputs="html",
|
130 |
+
title="SERPHouse News Search Interface",
|
131 |
+
description="Enter your search query and select a country to get recent news results from the SERPHouse API.",
|
132 |
+
theme="Nymbo/Nymbo_Theme",
|
133 |
+
css=css
|
134 |
)
|
135 |
|
136 |
+
iface.launch()
|