Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
79f8cda
ยท
verified ยท
1 Parent(s): d5532c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -49,33 +49,37 @@ def search_serphouse(query, country, page, num_result):
49
  def format_results(results):
50
  all_results = "## ๋ชจ๋“  ๋‰ด์Šค ๊ฒฐ๊ณผ\n\n"
51
  result_table = "## ๋‰ด์Šค ๊ฒฐ๊ณผ ํ‘œ\n\n"
52
- result_table += "| ์ œ๋ชฉ | ๋งํฌ | ์‹œ๊ฐ„ | ์ถœ์ฒ˜ |\n"
53
- result_table += "|------|------|------|------|\n"
54
 
55
  debug_info = "## ๋””๋ฒ„๊ทธ ์ •๋ณด\n\n"
56
  debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
57
 
58
  try:
59
  if not isinstance(results, dict):
60
- raise ValueError("Results is not a dictionary")
61
 
62
  if "results" not in results:
63
- raise ValueError("No 'results' key in the response")
64
 
 
65
  news_results = results["results"].get("news", [])
66
-
67
  debug_info += f"๋‰ด์Šค ๊ฒฐ๊ณผ ์ˆ˜: {len(news_results)}\n\n"
68
 
69
- for result in news_results:
70
  title = result.get("title", "์ œ๋ชฉ ์—†์Œ")
71
  url = result.get("url", "#")
72
  snippet = result.get("snippet", "๋‚ด์šฉ ์—†์Œ")
73
  channel = result.get("channel", "์•Œ ์ˆ˜ ์—†์Œ")
74
  time_str = result.get("time", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„")
75
 
76
- # ๊ฒฐ๊ณผ ํ‘œ์— ํ–‰ ์ถ”๊ฐ€
77
- result_table += f"| {title[:30]}... | [{url[:30]}...]({url}) | {time_str} | {channel} |\n"
 
 
 
78
 
 
79
  article_info = f"""
80
  ### [{title}]({url})
81
  {snippet}
@@ -89,12 +93,8 @@ def format_results(results):
89
  debug_info += error_message + "\n"
90
  all_results = error_message + "\n\n"
91
 
92
- # ๋””๋ฒ„๊ทธ ์ •๋ณด๋ฅผ ํ‘œ์— ์ถ”๊ฐ€ (์กฐ๊ฑด ์—†์ด)
93
- result_table += f"| ์˜ค๋ฅ˜ ๋ฐœ์ƒ | - | - | - |\n"
94
- result_table += f"| Debug Info | {error_message} | - | - |\n"
95
-
96
- # ๋””๋ฒ„๊ทธ ์ •๋ณด๋ฅผ ํ‘œ์— ์ถ”๊ฐ€
97
- result_table += "| Debug Info | ํฌํ•จ๋จ | ํฌํ•จ๋จ | ํฌํ•จ๋จ |\n"
98
 
99
  return all_results, result_table + "\n\n" + debug_info
100
 
 
49
  def format_results(results):
50
  all_results = "## ๋ชจ๋“  ๋‰ด์Šค ๊ฒฐ๊ณผ\n\n"
51
  result_table = "## ๋‰ด์Šค ๊ฒฐ๊ณผ ํ‘œ\n\n"
52
+ result_table += "| ์ œ๋ชฉ | ๋งํฌ | ์‹œ๊ฐ„ | ์ถœ์ฒ˜ | ๋””๋ฒ„๊ทธ ์ •๋ณด |\n"
53
+ result_table += "|------|------|------|------|-------------|\n"
54
 
55
  debug_info = "## ๋””๋ฒ„๊ทธ ์ •๋ณด\n\n"
56
  debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
57
 
58
  try:
59
  if not isinstance(results, dict):
60
+ raise ValueError("๊ฒฐ๊ณผ๊ฐ€ ์‚ฌ์ „ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค.")
61
 
62
  if "results" not in results:
63
+ raise ValueError("'results' ํ‚ค๊ฐ€ ์‘๋‹ต์— ์—†์Šต๋‹ˆ๋‹ค.")
64
 
65
+ # 'news' ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ด
66
  news_results = results["results"].get("news", [])
 
67
  debug_info += f"๋‰ด์Šค ๊ฒฐ๊ณผ ์ˆ˜: {len(news_results)}\n\n"
68
 
69
+ for idx, result in enumerate(news_results):
70
  title = result.get("title", "์ œ๋ชฉ ์—†์Œ")
71
  url = result.get("url", "#")
72
  snippet = result.get("snippet", "๋‚ด์šฉ ์—†์Œ")
73
  channel = result.get("channel", "์•Œ ์ˆ˜ ์—†์Œ")
74
  time_str = result.get("time", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„")
75
 
76
+ # ๊ฐ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ๋””๋ฒ„๊ทธ ์ •๋ณด๋ฅผ ๋ฌธ์ž์—ด๋กœ ๊ตฌ์„ฑ
77
+ single_debug_info = f"๋‰ด์Šค {idx + 1} - ์ œ๋ชฉ: {title}, ๋งํฌ: {url}, ์‹œ๊ฐ„: {time_str}, ์ถœ์ฒ˜: {channel}"
78
+
79
+ # ๊ฒฐ๊ณผ ํ‘œ์— ํ–‰ ์ถ”๊ฐ€ (๋””๋ฒ„๊ทธ ์ •๋ณด ํฌํ•จ)
80
+ result_table += f"| {title[:30]}... | [{url[:30]}...]({url}) | {time_str} | {channel} | {single_debug_info[:50]}... |\n"
81
 
82
+ # ๋‰ด์Šค ๊ธฐ์‚ฌ ์ •๋ณด
83
  article_info = f"""
84
  ### [{title}]({url})
85
  {snippet}
 
93
  debug_info += error_message + "\n"
94
  all_results = error_message + "\n\n"
95
 
96
+ # ์˜ค๋ฅ˜ ์‹œ ๋””๋ฒ„๊ทธ ์ •๋ณด๋„ ํ‘œ์— ์ถ”๊ฐ€
97
+ result_table += f"| ์˜ค๋ฅ˜ ๋ฐœ์ƒ | - | - | - | {error_message} |\n"
 
 
 
 
98
 
99
  return all_results, result_table + "\n\n" + debug_info
100