Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,20 +66,7 @@ def is_recent_news(time_str):
|
|
| 66 |
return False
|
| 67 |
|
| 68 |
def format_results(results):
|
| 69 |
-
|
| 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"]:
|
|
@@ -87,26 +74,28 @@ def format_results(results):
|
|
| 87 |
filtered_results = [result for result in news_results if is_recent_news(result.get("time", ""))]
|
| 88 |
|
| 89 |
if not filtered_results:
|
| 90 |
-
|
| 91 |
else:
|
| 92 |
for result in filtered_results:
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
else:
|
| 101 |
-
|
| 102 |
except Exception as e:
|
| 103 |
-
|
| 104 |
|
| 105 |
# 디버그 정보 추가
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
| 109 |
-
return html_output
|
| 110 |
|
| 111 |
def serphouse_search(query, country, page, num_result):
|
| 112 |
results = search_serphouse(query, country, page, num_result)
|
|
@@ -126,7 +115,7 @@ iface = gr.Interface(
|
|
| 126 |
gr.Slider(1, 10, 1, label="Page"),
|
| 127 |
gr.Slider(1, 100, 10, label="Number of Results")
|
| 128 |
],
|
| 129 |
-
outputs=
|
| 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",
|
|
|
|
| 66 |
return False
|
| 67 |
|
| 68 |
def format_results(results):
|
| 69 |
+
markdown_output = "## Recent News Results\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
try:
|
| 72 |
if isinstance(results, dict) and "results" in results and "news" in results["results"]:
|
|
|
|
| 74 |
filtered_results = [result for result in news_results if is_recent_news(result.get("time", ""))]
|
| 75 |
|
| 76 |
if not filtered_results:
|
| 77 |
+
markdown_output += "*No recent news results found.*\n\n"
|
| 78 |
else:
|
| 79 |
for result in filtered_results:
|
| 80 |
+
markdown_output += f"""
|
| 81 |
+
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|
| 82 |
+
|
| 83 |
+
{result.get('snippet', 'No Snippet')}
|
| 84 |
+
|
| 85 |
+
**Source:** {result.get('channel', 'Unknown')} - {result.get('time', 'Unknown time')}
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
"""
|
| 90 |
else:
|
| 91 |
+
markdown_output += "*No valid news results found in the API response.*\n\n"
|
| 92 |
except Exception as e:
|
| 93 |
+
markdown_output += f"*Error processing results: {str(e)}*\n\n"
|
| 94 |
|
| 95 |
# 디버그 정보 추가
|
| 96 |
+
markdown_output += f"### Debug Info:\n\n```json\n{json.dumps(results, indent=2)}\n```\n"
|
| 97 |
|
| 98 |
+
return markdown_output
|
|
|
|
| 99 |
|
| 100 |
def serphouse_search(query, country, page, num_result):
|
| 101 |
results = search_serphouse(query, country, page, num_result)
|
|
|
|
| 115 |
gr.Slider(1, 10, 1, label="Page"),
|
| 116 |
gr.Slider(1, 100, 10, label="Number of Results")
|
| 117 |
],
|
| 118 |
+
outputs=gr.Markdown(),
|
| 119 |
title="SERPHouse News Search Interface",
|
| 120 |
description="Enter your search query and select a country to get recent news results from the SERPHouse API.",
|
| 121 |
theme="Nymbo/Nymbo_Theme",
|