Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,7 @@ import requests
|
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
5 |
|
6 |
-
API_KEY = "
|
7 |
-
|
8 |
|
9 |
MAJOR_COUNTRIES = [
|
10 |
"United States", "United Kingdom", "Canada", "Australia", "Germany",
|
@@ -87,7 +86,7 @@ def format_results_from_raw(results):
|
|
87 |
|
88 |
# 뉴스 결과를 HTML 형식으로 포맷팅
|
89 |
formatted_articles = ""
|
90 |
-
# 뉴스 결과를 리스트 형태로 포맷팅
|
91 |
list_output = ""
|
92 |
|
93 |
for idx, result in enumerate(news_results, 1):
|
@@ -101,8 +100,10 @@ def format_results_from_raw(results):
|
|
101 |
# base64로 인코딩된 이미지를 처리하지 않음
|
102 |
if image_url and not image_url.startswith("data:image"):
|
103 |
image_html = f'<img src="{image_url}" alt="Image" style="max-width: 100%; height: auto;">'
|
|
|
104 |
else:
|
105 |
image_html = ''
|
|
|
106 |
|
107 |
# HTML 형식의 기사
|
108 |
article_html = f"""
|
@@ -115,16 +116,16 @@ def format_results_from_raw(results):
|
|
115 |
"""
|
116 |
formatted_articles += article_html
|
117 |
|
118 |
-
# 리스트 형식의 기사
|
119 |
list_item = f"""
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
시간: {time}
|
125 |
-
|
126 |
-
|
127 |
-
"""
|
128 |
list_output += list_item
|
129 |
|
130 |
# 뉴스 결과와 디버그 정보를 반환
|
@@ -161,13 +162,13 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="24시간 이내 뉴스
|
|
161 |
page = gr.Slider(1, 10, 1, label="페이지")
|
162 |
num_result = gr.Slider(1, 100, 100, label="결과 수")
|
163 |
|
164 |
-
search_button = gr.Button("검색")
|
165 |
|
166 |
with gr.Tab("뉴스 결과"):
|
167 |
news_output = gr.HTML(label="뉴스 결과")
|
168 |
|
169 |
with gr.Tab("리스트"):
|
170 |
-
list_output = gr.
|
171 |
|
172 |
with gr.Tab("디버그 정보"):
|
173 |
debug_output = gr.Textbox(label="디버그 정보", lines=10)
|
|
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
5 |
|
6 |
+
API_KEY = "YOUR_API_KEY_HERE" # 여기에 본인의 API 키를 입력하세요.
|
|
|
7 |
|
8 |
MAJOR_COUNTRIES = [
|
9 |
"United States", "United Kingdom", "Canada", "Australia", "Germany",
|
|
|
86 |
|
87 |
# 뉴스 결과를 HTML 형식으로 포맷팅
|
88 |
formatted_articles = ""
|
89 |
+
# 뉴스 결과를 리스트 형태로 포맷팅 (이미지 썸네일 포함)
|
90 |
list_output = ""
|
91 |
|
92 |
for idx, result in enumerate(news_results, 1):
|
|
|
100 |
# base64로 인코딩된 이미지를 처리하지 않음
|
101 |
if image_url and not image_url.startswith("data:image"):
|
102 |
image_html = f'<img src="{image_url}" alt="Image" style="max-width: 100%; height: auto;">'
|
103 |
+
thumbnail_html = f'<img src="{image_url}" alt="Thumbnail" style="width: 100px; height: auto;">'
|
104 |
else:
|
105 |
image_html = ''
|
106 |
+
thumbnail_html = ''
|
107 |
|
108 |
# HTML 형식의 기사
|
109 |
article_html = f"""
|
|
|
116 |
"""
|
117 |
formatted_articles += article_html
|
118 |
|
119 |
+
# 리스트 형식의 기사 (이미지 썸네일 포함)
|
120 |
list_item = f"""
|
121 |
+
<div style="margin-bottom: 20px;">
|
122 |
+
<h4>{idx}. <a href="{link}" target="_blank">{title}</a></h4>
|
123 |
+
<p>{thumbnail_html}</p>
|
124 |
+
<p>요약: {snippet}</p>
|
125 |
+
<p>출처: {channel} | 시간: {time}</p>
|
126 |
+
<hr>
|
127 |
+
</div>
|
128 |
+
"""
|
129 |
list_output += list_item
|
130 |
|
131 |
# 뉴스 결과와 디버그 정보를 반환
|
|
|
162 |
page = gr.Slider(1, 10, 1, label="페이지")
|
163 |
num_result = gr.Slider(1, 100, 100, label="결과 수")
|
164 |
|
165 |
+
search_button = gr.Button("검색")
|
166 |
|
167 |
with gr.Tab("뉴스 결과"):
|
168 |
news_output = gr.HTML(label="뉴스 결과")
|
169 |
|
170 |
with gr.Tab("리스트"):
|
171 |
+
list_output = gr.HTML(label="리스트 결과") # HTML로 변경
|
172 |
|
173 |
with gr.Tab("디버그 정보"):
|
174 |
debug_output = gr.Textbox(label="디버그 정보", lines=10)
|