Update app.py
Browse files
app.py
CHANGED
@@ -48,14 +48,14 @@ def search_serphouse(query, country, page, num_result):
|
|
48 |
return f"Error: {str(e)}"
|
49 |
|
50 |
def is_recent_news(time_str):
|
51 |
-
print(f"Received time string: '{time_str}'")
|
52 |
|
53 |
if not time_str:
|
54 |
print("Empty time string, returning False")
|
55 |
return False
|
56 |
|
57 |
time_str = time_str.lower().strip()
|
58 |
-
print(f"Processed time string: '{time_str}'")
|
59 |
|
60 |
if "1 day ago" in time_str:
|
61 |
print("Matched '1 day ago', returning True")
|
@@ -73,6 +73,10 @@ def format_results(results):
|
|
73 |
recent_results = "## ์ต๊ทผ ๋ด์ค ๊ฒฐ๊ณผ (1์ผ ์ด๋ด)\n\n"
|
74 |
debug_info = "## ๋๋ฒ๊ทธ ์ ๋ณด\n\n"
|
75 |
|
|
|
|
|
|
|
|
|
76 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
77 |
|
78 |
try:
|
@@ -93,12 +97,15 @@ def format_results(results):
|
|
93 |
channel = result.get("channel", "์ ์ ์์")
|
94 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
95 |
|
96 |
-
print(f"\nProcessing news item: {title}")
|
97 |
-
print(f"Time string from API: '{time_str}'")
|
98 |
|
99 |
is_recent = is_recent_news(time_str)
|
100 |
debug_info += f"๊ธฐ์ฌ: {title}\n์๊ฐ: {time_str}, ์ต๊ทผ ์ฌ๋ถ: {is_recent}\n\n"
|
101 |
|
|
|
|
|
|
|
102 |
article_info = f"""
|
103 |
### [{title}]({url})
|
104 |
{snippet}
|
@@ -117,8 +124,9 @@ def format_results(results):
|
|
117 |
debug_info += error_message + "\n"
|
118 |
all_results = error_message + "\n\n"
|
119 |
recent_results = error_message + "\n\n"
|
|
|
120 |
|
121 |
-
return all_results, recent_results, debug_info
|
122 |
|
123 |
def serphouse_search(query, country, page, num_result):
|
124 |
results = search_serphouse(query, country, page, num_result)
|
@@ -142,7 +150,7 @@ iface = gr.Interface(
|
|
142 |
outputs=[
|
143 |
gr.Markdown(label="๋ชจ๋ ๊ฒฐ๊ณผ"),
|
144 |
gr.Markdown(label="์ต๊ทผ ๊ฒฐ๊ณผ (1์ผ ์ด๋ด)"),
|
145 |
-
gr.Markdown(label="๋๋ฒ๊ทธ ์ ๋ณด")
|
146 |
],
|
147 |
title="SERPHouse ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
148 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ SERPHouse API์์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ์ต๊ทผ ๊ฒฐ๊ณผ(1์ผ ์ด๋ด)๋ ๋ณ๋๋ก ํ์๋ฉ๋๋ค.",
|
|
|
48 |
return f"Error: {str(e)}"
|
49 |
|
50 |
def is_recent_news(time_str):
|
51 |
+
print(f"Received time string: '{time_str}'")
|
52 |
|
53 |
if not time_str:
|
54 |
print("Empty time string, returning False")
|
55 |
return False
|
56 |
|
57 |
time_str = time_str.lower().strip()
|
58 |
+
print(f"Processed time string: '{time_str}'")
|
59 |
|
60 |
if "1 day ago" in time_str:
|
61 |
print("Matched '1 day ago', returning True")
|
|
|
73 |
recent_results = "## ์ต๊ทผ ๋ด์ค ๊ฒฐ๊ณผ (1์ผ ์ด๋ด)\n\n"
|
74 |
debug_info = "## ๋๋ฒ๊ทธ ์ ๋ณด\n\n"
|
75 |
|
76 |
+
debug_table = "## ๋๋ฒ๊น
๊ฒฐ๊ณผ ํ\n\n"
|
77 |
+
debug_table += "| ์ ๋ชฉ | ๋งํฌ | ์๊ฐ | ์ต๊ทผ ์ฌ๋ถ |\n"
|
78 |
+
debug_table += "|------|------|------|----------|\n"
|
79 |
+
|
80 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
81 |
|
82 |
try:
|
|
|
97 |
channel = result.get("channel", "์ ์ ์์")
|
98 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
99 |
|
100 |
+
print(f"\nProcessing news item: {title}")
|
101 |
+
print(f"Time string from API: '{time_str}'")
|
102 |
|
103 |
is_recent = is_recent_news(time_str)
|
104 |
debug_info += f"๊ธฐ์ฌ: {title}\n์๊ฐ: {time_str}, ์ต๊ทผ ์ฌ๋ถ: {is_recent}\n\n"
|
105 |
|
106 |
+
# ๋๋ฒ๊น
๊ฒฐ๊ณผ ํ์ ํ ์ถ๊ฐ
|
107 |
+
debug_table += f"| {title[:30]}... | [{url[:30]}...]({url}) | {time_str} | {is_recent} |\n"
|
108 |
+
|
109 |
article_info = f"""
|
110 |
### [{title}]({url})
|
111 |
{snippet}
|
|
|
124 |
debug_info += error_message + "\n"
|
125 |
all_results = error_message + "\n\n"
|
126 |
recent_results = error_message + "\n\n"
|
127 |
+
debug_table += f"| ์ค๋ฅ ๋ฐ์ | - | - | - |\n"
|
128 |
|
129 |
+
return all_results, recent_results, debug_info + "\n\n" + debug_table
|
130 |
|
131 |
def serphouse_search(query, country, page, num_result):
|
132 |
results = search_serphouse(query, country, page, num_result)
|
|
|
150 |
outputs=[
|
151 |
gr.Markdown(label="๋ชจ๋ ๊ฒฐ๊ณผ"),
|
152 |
gr.Markdown(label="์ต๊ทผ ๊ฒฐ๊ณผ (1์ผ ์ด๋ด)"),
|
153 |
+
gr.Markdown(label="๋๋ฒ๊ทธ ์ ๋ณด ๋ฐ ๊ฒฐ๊ณผ ํ")
|
154 |
],
|
155 |
title="SERPHouse ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
156 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ SERPHouse API์์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ์ต๊ทผ ๊ฒฐ๊ณผ(1์ผ ์ด๋ด)๋ ๋ณ๋๋ก ํ์๋ฉ๋๋ค.",
|