Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
695d9f1
ยท
verified ยท
1 Parent(s): 9e7cf4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -55
app.py CHANGED
@@ -135,7 +135,7 @@ footer {
135
  """
136
 
137
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
138
- with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
139
  gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์›ํ•˜๋Š” ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜๋ฉด, ๊ฒ€์ƒ‰์–ด์™€ ์ผ์น˜ํ•˜๋Š” 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ์ตœ๋Œ€ 10๊ฐœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
140
 
141
  with gr.Column():
@@ -144,6 +144,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
144
  country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ€", value="South Korea")
145
  search_button = gr.Button("๊ฒ€์ƒ‰")
146
 
 
 
 
147
  # ๊ธฐ์‚ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ƒํƒœ ๋ณ€์ˆ˜
148
  articles_state = gr.State([]) # ์ดˆ๊ธฐ๊ฐ’์„ ๋นˆ ๋ฆฌ์ŠคํŠธ๋กœ ์„ค์ •
149
 
@@ -170,47 +173,14 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
170
  })
171
 
172
  def search_and_display(query, country, articles_state):
173
- # Progress ๊ฐ์ฒด ์ƒ์„ฑ
174
- progress = gr.Progress(track_tqdm=True)
175
- progress(0, desc="์ฒ˜๋ฆฌ์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ฆฌ์„ธ์š”.")
176
-
177
- error_message, articles = serphouse_search(query, country)
178
- progress(50) # ์ง„ํ–‰๋ฅ  50%๋กœ ์—…๋ฐ์ดํŠธ
179
-
180
- outputs = []
181
- if error_message:
182
- outputs.append(gr.update(value=error_message, visible=True))
183
- for comp in article_components:
184
- outputs.extend([
185
- gr.update(visible=False), # group
186
- gr.update(), # title
187
- gr.update(), # image
188
- gr.update(), # snippet
189
- gr.update(), # info
190
- gr.update(visible=False), # summary_output
191
- ])
192
- articles_state = []
193
- else:
194
- outputs.append(gr.update(value="", visible=False))
195
- for idx, comp in enumerate(article_components):
196
- if idx < len(articles):
197
- article = articles[idx]
198
- # ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ˆ˜์ •
199
- image_url = article['image_url']
200
- if image_url and not image_url.startswith('data:image'):
201
- image_update = gr.update(value=image_url, visible=True)
202
- else:
203
- image_update = gr.update(value=None, visible=False)
204
-
205
- outputs.extend([
206
- gr.update(visible=True), # group
207
- gr.update(value=f"### [{article['title']}]({article['link']})"), # title
208
- image_update, # image
209
- gr.update(value=f"**์š”์•ฝ:** {article['snippet']}"), # snippet
210
- gr.update(value=f"**์ถœ์ฒ˜:** {article['channel']} | **์‹œ๊ฐ„:** {article['time']}"), # info
211
- gr.update(visible=False), # summary_output
212
- ])
213
- else:
214
  outputs.extend([
215
  gr.update(visible=False), # group
216
  gr.update(), # title
@@ -219,9 +189,39 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
219
  gr.update(), # info
220
  gr.update(visible=False), # summary_output
221
  ])
222
- articles_state = articles # articles_state ์—…๋ฐ์ดํŠธ
223
- outputs.append(articles_state)
224
- progress(100) # ์ง„ํ–‰๋ฅ  100%๋กœ ์—…๋ฐ์ดํŠธ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  return outputs
226
 
227
  # search_button ํด๋ฆญ ์‹œ ์—…๋ฐ์ดํŠธ๋  ์ถœ๋ ฅ ์ปดํฌ๋„ŒํŠธ ๋ชฉ๋ก ์ƒ์„ฑ
@@ -236,6 +236,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
236
  search_outputs.append(comp['info'])
237
  search_outputs.append(comp['summary_output'])
238
  search_outputs.append(articles_state)
 
239
 
240
  search_button.click(
241
  search_and_display,
@@ -247,16 +248,14 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
247
  for idx, comp in enumerate(article_components):
248
  def create_analyze_function(index=idx):
249
  def analyze_article(articles):
250
- progress = gr.Progress(track_tqdm=True)
251
- progress(0, desc="์ฒ˜๋ฆฌ์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ฆฌ์„ธ์š”.")
252
- if articles and index < len(articles):
253
- article = articles[index]
254
- summary = summarize_article(article['title'], article['snippet'])
255
- progress(100) # ์ง„ํ–‰๋ฅ  100%๋กœ ์—…๋ฐ์ดํŠธ
256
- return gr.update(value=summary, visible=True)
257
- else:
258
- progress(100) # ์ง„ํ–‰๋ฅ  100%๋กœ ์—…๋ฐ์ดํŠธ
259
- return gr.update(value="๊ธฐ์‚ฌ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", visible=True)
260
  return analyze_article
261
 
262
  comp['analyze_button'].click(
 
135
  """
136
 
137
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
138
+ with gr.Blocks(css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
139
  gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์›ํ•˜๋Š” ๊ตญ๊ฐ€๋ฅผ ์„ ํƒํ•˜๋ฉด, ๊ฒ€์ƒ‰์–ด์™€ ์ผ์น˜ํ•˜๋Š” 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ์ตœ๋Œ€ 10๊ฐœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
140
 
141
  with gr.Column():
 
144
  country = gr.Dropdown(MAJOR_COUNTRIES, label="๊ตญ๊ฐ€", value="South Korea")
145
  search_button = gr.Button("๊ฒ€์ƒ‰")
146
 
147
+ # ์ƒํƒœ ๋ฉ”์‹œ์ง€ ์ปดํฌ๋„ŒํŠธ ์ œ๊ฑฐ (Progress๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ๋ถˆํ•„์š”)
148
+ # status_message = gr.Markdown(visible=False)
149
+
150
  # ๊ธฐ์‚ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ƒํƒœ ๋ณ€์ˆ˜
151
  articles_state = gr.State([]) # ์ดˆ๊ธฐ๊ฐ’์„ ๋นˆ ๋ฆฌ์ŠคํŠธ๋กœ ์„ค์ •
152
 
 
173
  })
174
 
175
  def search_and_display(query, country, articles_state):
176
+ with gr.Progress() as progress:
177
+ progress(0, desc="์ฒ˜๋ฆฌ์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ฆฌ์„ธ์š”.")
178
+
179
+ error_message, articles = serphouse_search(query, country)
180
+ outputs = []
181
+ if error_message:
182
+ outputs.append(gr.update(value=error_message, visible=True))
183
+ for comp in article_components:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  outputs.extend([
185
  gr.update(visible=False), # group
186
  gr.update(), # title
 
189
  gr.update(), # info
190
  gr.update(visible=False), # summary_output
191
  ])
192
+ articles_state = []
193
+ else:
194
+ outputs.append(gr.update(value="", visible=False))
195
+ for idx, comp in enumerate(article_components):
196
+ if idx < len(articles):
197
+ article = articles[idx]
198
+ # ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ˆ˜์ •
199
+ image_url = article['image_url']
200
+ if image_url and not image_url.startswith('data:image'):
201
+ image_update = gr.update(value=image_url, visible=True)
202
+ else:
203
+ image_update = gr.update(value=None, visible=False)
204
+
205
+ outputs.extend([
206
+ gr.update(visible=True), # group
207
+ gr.update(value=f"### [{article['title']}]({article['link']})"), # title
208
+ image_update, # image
209
+ gr.update(value=f"**์š”์•ฝ:** {article['snippet']}"), # snippet
210
+ gr.update(value=f"**์ถœ์ฒ˜:** {article['channel']} | **์‹œ๊ฐ„:** {article['time']}"), # info
211
+ gr.update(visible=False), # summary_output
212
+ ])
213
+ else:
214
+ outputs.extend([
215
+ gr.update(visible=False), # group
216
+ gr.update(), # title
217
+ gr.update(), # image
218
+ gr.update(), # snippet
219
+ gr.update(), # info
220
+ gr.update(visible=False), # summary_output
221
+ ])
222
+ articles_state = articles # articles_state ์—…๋ฐ์ดํŠธ
223
+ outputs.append(articles_state)
224
+ # ์ƒํƒœ ๋ฉ”์‹œ์ง€ ์ˆจ๊น€ (Progress๋Š” ์ž๋™์œผ๋กœ ์‚ฌ๋ผ์ง‘๋‹ˆ๋‹ค)
225
  return outputs
226
 
227
  # search_button ํด๋ฆญ ์‹œ ์—…๋ฐ์ดํŠธ๋  ์ถœ๋ ฅ ์ปดํฌ๋„ŒํŠธ ๋ชฉ๋ก ์ƒ์„ฑ
 
236
  search_outputs.append(comp['info'])
237
  search_outputs.append(comp['summary_output'])
238
  search_outputs.append(articles_state)
239
+ # status_message ์ปดํฌ๋„ŒํŠธ ์ œ๊ฑฐ
240
 
241
  search_button.click(
242
  search_and_display,
 
248
  for idx, comp in enumerate(article_components):
249
  def create_analyze_function(index=idx):
250
  def analyze_article(articles):
251
+ with gr.Progress() as progress:
252
+ progress(0, desc="์ฒ˜๋ฆฌ์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ฆฌ์„ธ์š”.")
253
+ if articles and index < len(articles):
254
+ article = articles[index]
255
+ summary = summarize_article(article['title'], article['snippet'])
256
+ return gr.update(value=summary, visible=True)
257
+ else:
258
+ return gr.update(value="๊ธฐ์‚ฌ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", visible=True)
 
 
259
  return analyze_article
260
 
261
  comp['analyze_button'].click(