Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -967,60 +967,60 @@ footer {visibility: hidden;}
|
|
967 |
|
968 |
|
969 |
# 기존 함수들
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
988 |
outputs.extend([
|
989 |
gr.update(visible=False), gr.update(), gr.update(),
|
990 |
gr.update(), gr.update()
|
991 |
])
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
article = articles[idx]
|
1000 |
-
image_url = article['image_url']
|
1001 |
-
image_update = gr.update(value=image_url, visible=True) if image_url and not image_url.startswith('data:image') else gr.update(value=None, visible=False)
|
1002 |
-
|
1003 |
-
korean_summary = translate_to_korean(article['snippet'])
|
1004 |
-
|
1005 |
-
outputs.extend([
|
1006 |
-
gr.update(visible=True),
|
1007 |
-
gr.update(value=f"### [{article['title']}]({article['link']})"),
|
1008 |
-
image_update,
|
1009 |
-
gr.update(value=f"**요약:** {article['snippet']}\n\n**한글 요약:** {korean_summary}"),
|
1010 |
-
gr.update(value=f"**출처:** {article['channel']} | **시간:** {article['time']}")
|
1011 |
-
])
|
1012 |
-
else:
|
1013 |
-
outputs.extend([
|
1014 |
-
gr.update(visible=False), gr.update(), gr.update(),
|
1015 |
-
gr.update(), gr.update()
|
1016 |
-
])
|
1017 |
-
articles_state = articles
|
1018 |
-
|
1019 |
-
progress(1.0, desc="완료!")
|
1020 |
-
outputs.append(articles_state)
|
1021 |
-
outputs[0] = gr.update(value="", visible=False)
|
1022 |
-
|
1023 |
-
return outputs
|
1024 |
|
1025 |
|
1026 |
def get_region_countries(region):
|
|
|
967 |
|
968 |
|
969 |
# 기존 함수들
|
970 |
+
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
971 |
+
status_msg = "검색을 진행중입니다. 잠시만 기다리세요..."
|
972 |
+
|
973 |
+
progress(0, desc="검색어 번역 중...")
|
974 |
+
translated_query = translate_query(query, country)
|
975 |
+
translated_display = f"**원본 검색어:** {query}\n**번역된 검색어:** {translated_query}" if translated_query != query else f"**검색어:** {query}"
|
976 |
+
|
977 |
+
progress(0.2, desc="검색 시작...")
|
978 |
+
error_message, articles = serphouse_search(query, country)
|
979 |
+
progress(0.5, desc="결과 처리 중...")
|
980 |
+
|
981 |
+
outputs = []
|
982 |
+
outputs.append(gr.update(value=status_msg, visible=True))
|
983 |
+
outputs.append(gr.update(value=translated_display, visible=True))
|
984 |
+
|
985 |
+
if error_message:
|
986 |
+
outputs.append(gr.update(value=error_message, visible=True))
|
987 |
+
for comp in article_components:
|
988 |
+
outputs.extend([
|
989 |
+
gr.update(visible=False), gr.update(), gr.update(),
|
990 |
+
gr.update(), gr.update()
|
991 |
+
])
|
992 |
+
articles_state = []
|
993 |
+
else:
|
994 |
+
outputs.append(gr.update(value="", visible=False))
|
995 |
+
total_articles = len(articles)
|
996 |
+
for idx, comp in enumerate(article_components):
|
997 |
+
progress((idx + 1) / total_articles, desc=f"결과 표시 중... {idx + 1}/{total_articles}")
|
998 |
+
if idx < len(articles):
|
999 |
+
article = articles[idx]
|
1000 |
+
image_url = article['image_url']
|
1001 |
+
image_update = gr.update(value=image_url, visible=True) if image_url and not image_url.startswith('data:image') else gr.update(value=None, visible=False)
|
1002 |
+
|
1003 |
+
korean_summary = translate_to_korean(article['snippet'])
|
1004 |
+
|
1005 |
+
outputs.extend([
|
1006 |
+
gr.update(visible=True),
|
1007 |
+
gr.update(value=f"### [{article['title']}]({article['link']})"),
|
1008 |
+
image_update,
|
1009 |
+
gr.update(value=f"**요약:** {article['snippet']}\n\n**한글 요약:** {korean_summary}"),
|
1010 |
+
gr.update(value=f"**출처:** {article['channel']} | **시간:** {article['time']}")
|
1011 |
+
])
|
1012 |
+
else:
|
1013 |
outputs.extend([
|
1014 |
gr.update(visible=False), gr.update(), gr.update(),
|
1015 |
gr.update(), gr.update()
|
1016 |
])
|
1017 |
+
articles_state = articles
|
1018 |
+
|
1019 |
+
progress(1.0, desc="완료!")
|
1020 |
+
outputs.append(articles_state)
|
1021 |
+
outputs[0] = gr.update(value="", visible=False)
|
1022 |
+
|
1023 |
+
return outputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1024 |
|
1025 |
|
1026 |
def get_region_countries(region):
|