seawolf2357 commited on
Commit
2748048
·
verified ·
1 Parent(s): dc63a3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -28
app.py CHANGED
@@ -66,9 +66,9 @@ def is_recent_news(time_str):
66
  return False
67
 
68
  def format_results(results):
69
- all_results = "## All News Results\n\n"
70
- recent_results = "## Recent News Results (Within 1 Day)\n\n"
71
- debug_info = "## Debug Information\n\n"
72
 
73
  debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
74
 
@@ -83,37 +83,33 @@ def format_results(results):
83
  raise ValueError("No 'news' key in results")
84
 
85
  news_results = results["results"]["news"]
86
- debug_info += f"Number of news results: {len(news_results)}\n\n"
87
 
88
  for result in news_results:
89
- title = result.get("title", "No Title")
90
  url = result.get("url", "#")
91
- snippet = result.get("snippet", "No Snippet")
92
- channel = result.get("channel", "Unknown")
93
- time_str = result.get("time", "Unknown time")
94
 
95
  is_recent = is_recent_news(time_str)
96
- debug_info += f"Article: {title}\nTime: {time_str}, Is Recent: {is_recent}\n\n"
97
 
98
  article_info = f"""
99
  ### [{title}]({url})
100
-
101
  {snippet}
102
-
103
- **Source:** {channel} - {time_str}
104
-
105
  ---
106
-
107
  """
108
  all_results += article_info
109
  if is_recent:
110
  recent_results += article_info
111
 
112
- if recent_results == "## Recent News Results (Within 1 Day)\n\n":
113
- recent_results += "*No recent news results found within 1 day.*\n\n"
114
 
115
  except Exception as e:
116
- error_message = f"Error processing results: {str(e)}"
117
  debug_info += error_message + "\n"
118
  all_results = error_message + "\n\n"
119
  recent_results = error_message + "\n\n"
@@ -131,24 +127,23 @@ footer {
131
  }
132
  """
133
 
134
-
135
  iface = gr.Interface(
136
  fn=serphouse_search,
137
  inputs=[
138
- gr.Textbox(label="Search Query"),
139
- gr.Dropdown(MAJOR_COUNTRIES, label="Country"),
140
- gr.Slider(1, 10, 1, label="Page"),
141
- gr.Slider(1, 100, 10, label="Number of Results")
142
  ],
143
  outputs=[
144
- gr.Markdown(label="All Results"),
145
- gr.Markdown(label="Recent Results (Within 1 Day)"),
146
- gr.Markdown(label="Debug Information")
147
  ],
148
- title="SERPHouse News Search Interface",
149
- description="Enter your search query and select a country to get news results from the SERPHouse API. Recent results (within 1 day) are shown separately.",
150
  theme="Nymbo/Nymbo_Theme",
151
  css=css
152
  )
153
 
154
- iface.launch()
 
66
  return False
67
 
68
  def format_results(results):
69
+ all_results = "## 모든 뉴스 결과\n\n"
70
+ recent_results = "## 최근 뉴스 결과 (1 이내)\n\n"
71
+ debug_info = "## 디버그 정보\n\n"
72
 
73
  debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
74
 
 
83
  raise ValueError("No 'news' key in results")
84
 
85
  news_results = results["results"]["news"]
86
+ debug_info += f"뉴스 결과 수: {len(news_results)}\n\n"
87
 
88
  for result in news_results:
89
+ title = result.get("title", "제목 없음")
90
  url = result.get("url", "#")
91
+ snippet = result.get("snippet", "내용 없음")
92
+ channel = result.get("channel", "알 수 없음")
93
+ time_str = result.get("time", " 수 없는 시간")
94
 
95
  is_recent = is_recent_news(time_str)
96
+ debug_info += f"기사: {title}\n시간: {time_str}, 최근 여부: {is_recent}\n\n"
97
 
98
  article_info = f"""
99
  ### [{title}]({url})
 
100
  {snippet}
101
+ **출처:** {channel} - {time_str}
 
 
102
  ---
 
103
  """
104
  all_results += article_info
105
  if is_recent:
106
  recent_results += article_info
107
 
108
+ if recent_results == "## 최근 뉴스 결과 (1 이내)\n\n":
109
+ recent_results += "*1일 이내의 최근 뉴스 결과가 없습니다.*\n\n"
110
 
111
  except Exception as e:
112
+ error_message = f"결과 처리 오류 발생: {str(e)}"
113
  debug_info += error_message + "\n"
114
  all_results = error_message + "\n\n"
115
  recent_results = error_message + "\n\n"
 
127
  }
128
  """
129
 
 
130
  iface = gr.Interface(
131
  fn=serphouse_search,
132
  inputs=[
133
+ gr.Textbox(label="검색어"),
134
+ gr.Dropdown(MAJOR_COUNTRIES, label="국가"),
135
+ gr.Slider(1, 10, 1, label="페이지"),
136
+ gr.Slider(1, 100, 10, label="결과 ")
137
  ],
138
  outputs=[
139
+ gr.Markdown(label="모든 결과"),
140
+ gr.Markdown(label="최근 결과 (1 이내)"),
141
+ gr.Markdown(label="디버그 정보")
142
  ],
143
+ title="SERPHouse 뉴스 검색 인터페이스",
144
+ description="검색어를 입력하고 국가를 선택하여 SERPHouse API에서 뉴스 결과를 가져옵니다. 최근 결과(1 이내) 별도로 표시됩니다.",
145
  theme="Nymbo/Nymbo_Theme",
146
  css=css
147
  )
148
 
149
+ iface.launch()