seawolf2357 commited on
Commit
e420980
ยท
verified ยท
1 Parent(s): 109fed9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -27
app.py CHANGED
@@ -7,15 +7,15 @@ import pandas as pd
7
  API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
8
 
9
  MAJOR_COUNTRIES = [
10
- "United States", "United Kingdom", "Canada", "Australia", "Germany",
11
- "France", "Japan", "South Korea", "China", "India",
12
- "Brazil", "Mexico", "Russia", "Italy", "Spain",
13
- "Netherlands", "Sweden", "Switzerland", "Norway", "Denmark",
14
- "Finland", "Belgium", "Austria", "New Zealand", "Ireland",
15
- "Singapore", "Hong Kong", "Israel", "United Arab Emirates", "Saudi Arabia",
16
- "South Africa", "Turkey", "Egypt", "Poland", "Czech Republic",
17
- "Hungary", "Greece", "Portugal", "Argentina", "Chile",
18
- "Colombia", "Peru", "Venezuela", "Thailand", "Malaysia",
19
  "Indonesia", "Philippines", "Vietnam", "Pakistan", "Bangladesh"
20
  ]
21
 
@@ -62,7 +62,7 @@ def format_results(results):
62
 
63
  try:
64
  if isinstance(results, dict) and "error" in results:
65
- return pd.DataFrame({"Error": [results["error"]]}), debug_info
66
 
67
  if not isinstance(results, dict):
68
  raise ValueError("๊ฒฐ๊ณผ๊ฐ€ ์‚ฌ์ „ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค.")
@@ -89,19 +89,26 @@ def format_results(results):
89
  debug_info += f"๋‰ด์Šค ๊ฒฐ๊ณผ ์ˆ˜: {len(news_results)}\n"
90
 
91
  if not news_results:
92
- return pd.DataFrame({"Message": ["๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."]}), debug_info
93
 
94
- formatted_results = []
95
  for result in news_results:
96
- formatted_results.append({
97
- "์ œ๋ชฉ": result.get("title", "์ œ๋ชฉ ์—†์Œ"),
98
- "๋งํฌ": result.get("url", result.get("link", "#")),
99
- "๋‚ด์šฉ": result.get("snippet", "๋‚ด์šฉ ์—†์Œ"),
100
- "์ถœ์ฒ˜": result.get("source", result.get("channel", "์•Œ ์ˆ˜ ์—†์Œ")),
101
- "์‹œ๊ฐ„": result.get("date", result.get("time", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„"))
102
- })
 
 
 
 
 
 
 
103
 
104
- return pd.DataFrame(formatted_results), debug_info
105
 
106
  except Exception as e:
107
  error_message = f"๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
@@ -109,12 +116,12 @@ def format_results(results):
109
  debug_info += f"Results structure: {type(results)}\n"
110
  if isinstance(results, dict):
111
  debug_info += f"Results keys: {results.keys()}\n"
112
- return pd.DataFrame({"Error": [error_message]}), debug_info
113
 
114
  def serphouse_search(query, country, page, num_result):
115
  results = search_serphouse(query, country, page, num_result)
116
- df_results, debug_info = format_results(results)
117
- return df_results, debug_info
118
 
119
  css = """
120
  footer {
@@ -131,7 +138,7 @@ iface = gr.Interface(
131
  gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์ˆ˜")
132
  ],
133
  outputs=[
134
- gr.Dataframe(label="๋‰ด์Šค ๊ฒฐ๊ณผ"),
135
  gr.Textbox(label="๋””๋ฒ„๊ทธ ์ •๋ณด", lines=10)
136
  ],
137
  title="24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค",
@@ -140,6 +147,4 @@ iface = gr.Interface(
140
  css=css
141
  )
142
 
143
-
144
-
145
- iface.launch(auth=("gini","pick"))
 
7
  API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
8
 
9
  MAJOR_COUNTRIES = [
10
+ "United States", "United Kingdom", "Canada", "Australia", "Germany",
11
+ "France", "Japan", "South Korea", "China", "India",
12
+ "Brazil", "Mexico", "Russia", "Italy", "Spain",
13
+ "Netherlands", "Sweden", "Switzerland", "Norway", "Denmark",
14
+ "Finland", "Belgium", "Austria", "New Zealand", "Ireland",
15
+ "Singapore", "Hong Kong", "Israel", "United Arab Emirates", "Saudi Arabia",
16
+ "South Africa", "Turkey", "Egypt", "Poland", "Czech Republic",
17
+ "Hungary", "Greece", "Portugal", "Argentina", "Chile",
18
+ "Colombia", "Peru", "Venezuela", "Thailand", "Malaysia",
19
  "Indonesia", "Philippines", "Vietnam", "Pakistan", "Bangladesh"
20
  ]
21
 
 
62
 
63
  try:
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("๊ฒฐ๊ณผ๊ฐ€ ์‚ฌ์ „ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค.")
 
89
  debug_info += f"๋‰ด์Šค ๊ฒฐ๊ณผ ์ˆ˜: {len(news_results)}\n"
90
 
91
  if not news_results:
92
+ return "๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.", debug_info
93
 
94
+ formatted_articles = ""
95
  for result in news_results:
96
+ title = result.get("title", "์ œ๋ชฉ ์—†์Œ")
97
+ link = result.get("url", result.get("link", "#"))
98
+ snippet = result.get("snippet", "๋‚ด์šฉ ์—†์Œ")
99
+ source = result.get("source", result.get("channel", "์•Œ ์ˆ˜ ์—†์Œ"))
100
+ date = result.get("date", result.get("time", "์•Œ ์ˆ˜ ์—†๋Š” ์‹œ๊ฐ„"))
101
+
102
+ article_html = f"""
103
+ <div style="margin-bottom: 20px;">
104
+ <h3><a href="{link}" target="_blank">{title}</a></h3>
105
+ <p>{snippet}</p>
106
+ <p><strong>{source}</strong> - {date}</p>
107
+ </div>
108
+ """
109
+ formatted_articles += article_html
110
 
111
+ return formatted_articles, debug_info
112
 
113
  except Exception as e:
114
  error_message = f"๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
 
116
  debug_info += f"Results structure: {type(results)}\n"
117
  if isinstance(results, dict):
118
  debug_info += f"Results keys: {results.keys()}\n"
119
+ return "Error: " + error_message, debug_info
120
 
121
  def serphouse_search(query, country, page, num_result):
122
  results = search_serphouse(query, country, page, num_result)
123
+ formatted_articles, debug_info = format_results(results)
124
+ return formatted_articles, debug_info
125
 
126
  css = """
127
  footer {
 
138
  gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์ˆ˜")
139
  ],
140
  outputs=[
141
+ gr.HTML(label="๋‰ด์Šค ๊ฒฐ๊ณผ"),
142
  gr.Textbox(label="๋””๋ฒ„๊ทธ ์ •๋ณด", lines=10)
143
  ],
144
  title="24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค ๊ฒ€์ƒ‰ ์ธํ„ฐํŽ˜์ด์Šค",
 
147
  css=css
148
  )
149
 
150
+ iface.launch(auth=("gini","pick"))