seawolf2357 commited on
Commit
638a422
ยท
verified ยท
1 Parent(s): e63a0fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import requests
3
  import json
4
  from datetime import datetime, timedelta
 
5
 
6
  API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
7
 
@@ -58,7 +59,7 @@ def search_serphouse(query, country, page, num_result):
58
 
59
  def format_results(results):
60
  if isinstance(results, dict) and "error" in results:
61
- return [f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {results['error']}"]
62
 
63
  try:
64
  if not isinstance(results, dict):
@@ -70,27 +71,22 @@ def format_results(results):
70
  news_results = results["results"].get("news", [])
71
 
72
  if not news_results:
73
- return ["๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."]
74
 
75
  formatted_results = []
76
  for result in news_results:
77
- title = result.get("title", "์ œ๋ชฉ ์—†์Œ")
78
- url = result.get("url", "#")
79
- snippet = result.get("snippet", "๋‚ด์šฉ ์—†์Œ")
80
- channel = result.get("channel", "์•Œ ์ˆ˜ ์—†์Œ")
81
- time_str = result.get("time", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„")
82
-
83
- article_info = f"""์ œ๋ชฉ: {title}
84
- ๋งํฌ: {url}
85
- ๋‚ด์šฉ: {snippet}
86
- ์ถœ์ฒ˜: {channel} - {time_str}
87
- ---"""
88
- formatted_results.append(article_info)
89
 
90
- return formatted_results
91
 
92
  except Exception as e:
93
- return [f"๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"]
94
 
95
  def serphouse_search(query, country, page, num_result):
96
  results = search_serphouse(query, country, page, num_result)
@@ -110,7 +106,7 @@ iface = gr.Interface(
110
  gr.Slider(1, 10, 1, label="ํŽ˜์ด์ง€"),
111
  gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์ˆ˜")
112
  ],
113
- outputs=gr.outputs.Textbox(label="๋‰ด์Šค ๊ฒฐ๊ณผ", lines=20),
114
  title="24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค",
115
  description="๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜์—ฌ 24์‹œ๊ฐ„ ์ด๋‚ด์˜ ๋‰ด์Šค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.",
116
  theme="Nymbo/Nymbo_Theme",
 
2
  import requests
3
  import json
4
  from datetime import datetime, timedelta
5
+ import pandas as pd
6
 
7
  API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
8
 
 
59
 
60
  def format_results(results):
61
  if isinstance(results, dict) and "error" in results:
62
+ return pd.DataFrame({"Error": [results["error"]]})
63
 
64
  try:
65
  if not isinstance(results, dict):
 
71
  news_results = results["results"].get("news", [])
72
 
73
  if not news_results:
74
+ return pd.DataFrame({"Message": ["๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."]})
75
 
76
  formatted_results = []
77
  for result in news_results:
78
+ formatted_results.append({
79
+ "์ œ๋ชฉ": result.get("title", "์ œ๋ชฉ ์—†์Œ"),
80
+ "๋งํฌ": result.get("url", "#"),
81
+ "๋‚ด์šฉ": result.get("snippet", "๋‚ด์šฉ ์—†์Œ"),
82
+ "์ถœ์ฒ˜": result.get("channel", "์•Œ ์ˆ˜ ์—†์Œ"),
83
+ "์‹œ๊ฐ„": result.get("time", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„")
84
+ })
 
 
 
 
 
85
 
86
+ return pd.DataFrame(formatted_results)
87
 
88
  except Exception as e:
89
+ return pd.DataFrame({"Error": [f"๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"]})
90
 
91
  def serphouse_search(query, country, page, num_result):
92
  results = search_serphouse(query, country, page, num_result)
 
106
  gr.Slider(1, 10, 1, label="ํŽ˜์ด์ง€"),
107
  gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์ˆ˜")
108
  ],
109
+ outputs=gr.Dataframe(label="๋‰ด์Šค ๊ฒฐ๊ณผ"),
110
  title="24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค",
111
  description="๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜์—ฌ 24์‹œ๊ฐ„ ์ด๋‚ด์˜ ๋‰ด์Šค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.",
112
  theme="Nymbo/Nymbo_Theme",