seawolf2357 commited on
Commit
cdca7fd
·
verified ·
1 Parent(s): c57002d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -1,10 +1,9 @@
1
-
2
  import gradio as gr
3
  import requests
4
  import json
5
  from datetime import datetime, timedelta
6
 
7
- API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
8
 
9
  MAJOR_COUNTRIES = [
10
  "United States", "United Kingdom", "Canada", "Australia", "Germany",
@@ -59,10 +58,10 @@ def search_serphouse(query, country, page, num_result):
59
 
60
  def format_results_from_raw(results):
61
  try:
62
- debug_info = f"Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}"
63
 
64
  if isinstance(results, dict) and "error" in results:
65
- return "Error: " + results["error"], debug_info
66
 
67
  if not isinstance(results, dict):
68
  raise ValueError("결과가 사전 형식이 아닙니다.")
@@ -79,7 +78,7 @@ def format_results_from_raw(results):
79
  news_results = []
80
 
81
  if not news_results:
82
- return "검색 결과가 없습니다.", debug_info
83
 
84
  formatted_articles = ""
85
  for result in news_results:
@@ -106,17 +105,20 @@ def format_results_from_raw(results):
106
  """
107
  formatted_articles += article_html
108
 
109
- return formatted_articles, debug_info
 
 
 
110
 
111
  except Exception as e:
112
  error_message = f"결과 처리 중 오류 발생: {str(e)}"
113
- debug_info = f"Error: {error_message}\n"
114
- return "Error: " + error_message, debug_info
115
 
116
  def serphouse_search(query, country, page, num_result):
117
  results = search_serphouse(query, country, page, num_result)
118
- formatted_articles, debug_info = format_results_from_raw(results)
119
- return formatted_articles, debug_info
120
 
121
  css = """
122
  footer {
@@ -142,17 +144,18 @@ with gr.Blocks(css=css, title="24시간 이내 뉴스 검색 인터페이스") a
142
  with gr.Tab("뉴스 결과"):
143
  news_output = gr.HTML(label="뉴스 결과")
144
 
145
- with gr.Tab("디버그 정보"):
146
- debug_output = gr.Textbox(label="디버그 정보", lines=10)
 
147
 
148
  def search_and_display(query, country, page, num_result):
149
- articles, debug_info = serphouse_search(query, country, page, num_result)
150
- return {news_output: articles, debug_output: debug_info}
151
 
152
  search_button.click(
153
  search_and_display,
154
  inputs=[query, country, page, num_result],
155
- outputs=[news_output, debug_output]
156
  )
157
 
158
  iface.launch(auth=("gini", "pick"))
 
 
1
  import gradio as gr
2
  import requests
3
  import json
4
  from datetime import datetime, timedelta
5
 
6
+ API_KEY = "YOUR_API_KEY_HERE" # 여기에 본인의 API 키를 입력하세요.
7
 
8
  MAJOR_COUNTRIES = [
9
  "United States", "United Kingdom", "Canada", "Australia", "Germany",
 
58
 
59
  def format_results_from_raw(results):
60
  try:
61
+ debug_info = f"<pre>Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}</pre>"
62
 
63
  if isinstance(results, dict) and "error" in results:
64
+ return "Error: " + results["error"] + debug_info
65
 
66
  if not isinstance(results, dict):
67
  raise ValueError("결과가 사전 형식이 아닙니다.")
 
78
  news_results = []
79
 
80
  if not news_results:
81
+ return "검색 결과가 없습니다." + debug_info
82
 
83
  formatted_articles = ""
84
  for result in news_results:
 
105
  """
106
  formatted_articles += article_html
107
 
108
+ # 뉴스 결과와 디버그 정보를 합침
109
+ combined_output = formatted_articles + debug_info
110
+
111
+ return combined_output
112
 
113
  except Exception as e:
114
  error_message = f"결과 처리 중 오류 발생: {str(e)}"
115
+ debug_info = f"<pre>Error: {error_message}\n</pre>"
116
+ return "Error: " + error_message + debug_info
117
 
118
  def serphouse_search(query, country, page, num_result):
119
  results = search_serphouse(query, country, page, num_result)
120
+ combined_output = format_results_from_raw(results)
121
+ return combined_output
122
 
123
  css = """
124
  footer {
 
144
  with gr.Tab("뉴스 결과"):
145
  news_output = gr.HTML(label="뉴스 결과")
146
 
147
+ # 디버그 정보 탭 제거 또는 주석 처리
148
+ # with gr.Tab("디버그 정보"):
149
+ # debug_output = gr.Textbox(label="디버그 정보", lines=10)
150
 
151
  def search_and_display(query, country, page, num_result):
152
+ combined_output = serphouse_search(query, country, page, num_result)
153
+ return {news_output: combined_output}
154
 
155
  search_button.click(
156
  search_and_display,
157
  inputs=[query, country, page, num_result],
158
+ outputs=[news_output]
159
  )
160
 
161
  iface.launch(auth=("gini", "pick"))