seawolf2357 commited on
Commit
ef406af
ยท
verified ยท
1 Parent(s): e312573

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
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}'") # API์—์„œ ๋ฐ›์€ ์›๋ž˜ ์‹œ๊ฐ„ ๋ฌธ์ž์—ด
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์ผ ์ด๋‚ด)๋Š” ๋ณ„๋„๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.",