Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
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 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
outputs.extend([
|
180 |
gr.update(visible=False), # group
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
gr.update(visible=False), # summary_output
|
186 |
])
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
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 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
|
257 |
-
|
|
|
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"))
|