Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
12d3fa4
ยท
verified ยท
1 Parent(s): 0d52d72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -19
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import requests
3
  import json
@@ -58,7 +59,7 @@ def search_serphouse(query, country, page, num_result):
58
 
59
  def format_results_from_raw(results):
60
  try:
61
- debug_info = f"Raw API Response:\n{json.dumps(results, indent=2, ensure_ascii=False)}\n\n"
62
 
63
  if isinstance(results, dict) and "error" in results:
64
  return "Error: " + results["error"], debug_info
@@ -89,7 +90,7 @@ def format_results_from_raw(results):
89
  time = result.get("time", result.get("date", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„"))
90
  image_url = result.get("img", result.get("thumbnail", ""))
91
 
92
- # base64๋กœ ์ธ์ฝ”๋”ฉ๋œ ์ด๋ฏธ์ง€๋ฅผ ์ฒ˜๋ฆฌ
93
  if image_url and not image_url.startswith("data:image"):
94
  image_html = f'<img src="{image_url}" alt="Image" style="max-width: 100%; height: auto;">'
95
  else:
@@ -123,22 +124,35 @@ footer {
123
  }
124
  """
125
 
126
- iface = gr.Interface(
127
- fn=serphouse_search,
128
- inputs=[
129
- gr.Textbox(label="๊ฒ€์ƒ‰์–ด"),
130
- gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ€"),
131
- gr.Slider(1, 10, 1, label="ํŽ˜์ด์ง€"),
132
- gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์ˆ˜")
133
- ],
134
- outputs=[
135
- gr.HTML(label="๋‰ด์Šค ๊ฒฐ๊ณผ"),
136
- gr.Textbox(label="๋””๋ฒ„๊ทธ ์ •๋ณด", lines=10)
137
- ],
138
- title="24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค",
139
- description="๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜์—ฌ 24์‹œ๊ฐ„ ์ด๋‚ด์˜ ๋‰ด์Šค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.",
140
- theme="default",
141
- css=css
142
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  iface.launch(auth=("gini", "pick"))
 
1
+
2
  import gradio as gr
3
  import requests
4
  import json
 
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
 
90
  time = result.get("time", result.get("date", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„"))
91
  image_url = result.get("img", result.get("thumbnail", ""))
92
 
93
+ # base64๋กœ ์ธ์ฝ”๋”ฉ๋œ ์ด๋ฏธ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ
94
  if image_url and not image_url.startswith("data:image"):
95
  image_html = f'<img src="{image_url}" alt="Image" style="max-width: 100%; height: auto;">'
96
  else:
 
124
  }
125
  """
126
 
127
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
128
+ with gr.Blocks(css=css, title="24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค") as iface:
129
+ gr.Markdown("## 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค")
130
+ gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜์—ฌ 24์‹œ๊ฐ„ ์ด๋‚ด์˜ ๋‰ด์Šค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.")
131
+
132
+ with gr.Tab("๊ฒ€์ƒ‰"):
133
+ with gr.Row():
134
+ query = gr.Textbox(label="๊ฒ€์ƒ‰์–ด")
135
+ country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ€", value="South Korea")
136
+ with gr.Row():
137
+ page = gr.Slider(1, 10, 1, label="ํŽ˜์ด์ง€")
138
+ num_result = gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์ˆ˜")
139
+
140
+ search_button = gr.Button("๊ฒ€์ƒ‰")
141
+
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"))