Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
1ac6a1a
ยท
verified ยท
1 Parent(s): 1173591

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -80
app.py CHANGED
@@ -146,7 +146,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
146
  search_button = gr.Button("๊ฒ€์ƒ‰")
147
 
148
  # ๊ธฐ์‚ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ƒํƒœ ๋ณ€์ˆ˜
149
- articles_state = gr.State()
150
 
151
  # ์ตœ๋Œ€ 10๊ฐœ์˜ ๊ธฐ์‚ฌ์— ๋Œ€ํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
152
  article_components = []
@@ -170,88 +170,89 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์„œ๋น„์Šค") as
170
  'index': i,
171
  })
172
 
173
- def search_and_display(query, country):
174
- error_message, articles = serphouse_search(query, country)
175
- outputs = []
176
- if error_message:
177
- outputs.append(gr.update(value=error_message, visible=True))
178
- for comp in article_components:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  outputs.extend([
180
  gr.update(visible=False), # group
181
- None, # title
182
- None, # image
183
- None, # snippet
184
- None, # info
185
  gr.update(visible=False), # summary_output
186
  ])
187
- outputs.append(gr.update(value=[])) # articles_state ์ดˆ๊ธฐํ™”
188
- else:
189
- outputs.append(gr.update(value="", visible=False))
190
- for idx, comp in enumerate(article_components):
191
- if idx < len(articles):
192
- article = articles[idx]
193
- # ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ˆ˜์ •
194
- image_url = article['image_url']
195
- if image_url and not image_url.startswith('data:image'):
196
- image_update = gr.update(value=image_url, visible=True)
197
- else:
198
- image_update = gr.update(value=None, visible=False)
199
-
200
- outputs.extend([
201
- gr.update(visible=True), # group
202
- gr.update(value=f"### [{article['title']}]({article['link']})"), # title
203
- image_update, # image
204
- gr.update(value=f"**์š”์•ฝ:** {article['snippet']}"), # snippet
205
- gr.update(value=f"**์ถœ์ฒ˜:** {article['channel']} | **์‹œ๊ฐ„:** {article['time']}"), # info
206
- gr.update(visible=False), # summary_output
207
- ])
208
- else:
209
- outputs.extend([
210
- gr.update(visible=False), # group
211
- None, # title
212
- None, # image
213
- None, # snippet
214
- None, # info
215
- gr.update(visible=False), # summary_output
216
- ])
217
- outputs.append(gr.update(value=articles)) # articles_state ์—…๋ฐ์ดํŠธ
218
- return outputs
219
-
220
- # search_button ํด๋ฆญ ์‹œ ์—…๋ฐ์ดํŠธ๋  ์ถœ๋ ฅ ์ปดํฌ๋„ŒํŠธ ๋ชฉ๋ก ์ƒ์„ฑ
221
- search_outputs = []
222
- error_output = gr.Markdown(visible=False)
223
- search_outputs.append(error_output)
224
- for comp in article_components:
225
- search_outputs.append(comp['group'])
226
- search_outputs.append(comp['title'])
227
- search_outputs.append(comp['image'])
228
- search_outputs.append(comp['snippet'])
229
- search_outputs.append(comp['info'])
230
- search_outputs.append(comp['summary_output'])
231
- search_outputs.append(articles_state)
232
-
233
- search_button.click(
234
- search_and_display,
235
- inputs=[query, country],
236
- outputs=search_outputs
237
- )
238
-
239
- # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •
240
- for idx, comp in enumerate(article_components):
241
- def create_analyze_function(index):
242
- def analyze_article(articles):
243
- if index < len(articles):
244
- article = articles[index]
245
- summary = summarize_article(article['title'], article['snippet'])
246
- return gr.update(value=summary, visible=True)
247
- else:
248
- return gr.update(value="๊ธฐ์‚ฌ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", visible=True)
249
- return analyze_article
250
 
251
- comp['analyze_button'].click(
252
- create_analyze_function(idx),
253
- inputs=[articles_state],
254
- outputs=comp['summary_output']
255
- )
256
 
257
- iface.launch(auth=("gini", "pick"))
 
146
  search_button = gr.Button("๊ฒ€์ƒ‰")
147
 
148
  # ๊ธฐ์‚ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ƒํƒœ ๋ณ€์ˆ˜
149
+ articles_state = gr.State([]) # ์ดˆ๊ธฐ๊ฐ’์„ ๋นˆ ๋ฆฌ์ŠคํŠธ๋กœ ์„ค์ •
150
 
151
  # ์ตœ๋Œ€ 10๊ฐœ์˜ ๊ธฐ์‚ฌ์— ๋Œ€ํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
152
  article_components = []
 
170
  'index': i,
171
  })
172
 
173
+ def search_and_display(query, country, articles_state):
174
+ error_message, articles = serphouse_search(query, country)
175
+ outputs = []
176
+ if error_message:
177
+ outputs.append(gr.update(value=error_message, visible=True))
178
+ for comp in article_components:
179
+ outputs.extend([
180
+ gr.update(visible=False), # group
181
+ gr.update(), # title
182
+ gr.update(), # image
183
+ gr.update(), # snippet
184
+ gr.update(), # info
185
+ gr.update(visible=False), # summary_output
186
+ ])
187
+ articles_state = []
188
+ else:
189
+ outputs.append(gr.update(value="", visible=False))
190
+ for idx, comp in enumerate(article_components):
191
+ if idx < len(articles):
192
+ article = articles[idx]
193
+ # ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ ์ˆ˜์ •
194
+ image_url = article['image_url']
195
+ if image_url and not image_url.startswith('data:image'):
196
+ image_update = gr.update(value=image_url, visible=True)
197
+ else:
198
+ image_update = gr.update(value=None, visible=False)
199
+
200
+ outputs.extend([
201
+ gr.update(visible=True), # group
202
+ gr.update(value=f"### [{article['title']}]({article['link']})"), # title
203
+ image_update, # image
204
+ gr.update(value=f"**์š”์•ฝ:** {article['snippet']}"), # snippet
205
+ gr.update(value=f"**์ถœ์ฒ˜:** {article['channel']} | **์‹œ๊ฐ„:** {article['time']}"), # info
206
+ gr.update(visible=False), # summary_output
207
+ ])
208
+ else:
209
  outputs.extend([
210
  gr.update(visible=False), # group
211
+ gr.update(), # title
212
+ gr.update(), # image
213
+ gr.update(), # snippet
214
+ gr.update(), # info
215
  gr.update(visible=False), # summary_output
216
  ])
217
+ articles_state = articles # articles_state ์—…๋ฐ์ดํŠธ
218
+ outputs.append(articles_state)
219
+ return outputs
220
+
221
+ # search_button ํด๋ฆญ ์‹œ ์—…๋ฐ์ดํŠธ๋  ์ถœ๋ ฅ ์ปดํฌ๋„ŒํŠธ ๋ชฉ๋ก ์ƒ์„ฑ
222
+ search_outputs = []
223
+ error_output = gr.Markdown(visible=False)
224
+ search_outputs.append(error_output)
225
+ for comp in article_components:
226
+ search_outputs.append(comp['group'])
227
+ search_outputs.append(comp['title'])
228
+ search_outputs.append(comp['image'])
229
+ search_outputs.append(comp['snippet'])
230
+ search_outputs.append(comp['info'])
231
+ search_outputs.append(comp['summary_output'])
232
+ search_outputs.append(articles_state)
233
+
234
+ search_button.click(
235
+ search_and_display,
236
+ inputs=[query, country, articles_state],
237
+ outputs=search_outputs
238
+ )
239
+
240
+ # ๋ถ„์„ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •
241
+ for idx, comp in enumerate(article_components):
242
+ def create_analyze_function(index=idx):
243
+ def analyze_article(articles):
244
+ if articles and index < len(articles):
245
+ article = articles[index]
246
+ summary = summarize_article(article['title'], article['snippet'])
247
+ return gr.update(value=summary, visible=True)
248
+ else:
249
+ return gr.update(value="๊ธฐ์‚ฌ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", visible=True)
250
+ return analyze_article
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
+ comp['analyze_button'].click(
253
+ create_analyze_function(),
254
+ inputs=[articles_state],
255
+ outputs=comp['summary_output']
256
+ )
257
 
258
+ iface.launch(auth=("gini", "pick"))