Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
|
|
5 |
|
6 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
7 |
|
@@ -58,7 +59,7 @@ def search_serphouse(query, country, page, num_result):
|
|
58 |
|
59 |
def format_results(results):
|
60 |
if isinstance(results, dict) and "error" in results:
|
61 |
-
return
|
62 |
|
63 |
try:
|
64 |
if not isinstance(results, dict):
|
@@ -70,27 +71,22 @@ def format_results(results):
|
|
70 |
news_results = results["results"].get("news", [])
|
71 |
|
72 |
if not news_results:
|
73 |
-
return ["๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."]
|
74 |
|
75 |
formatted_results = []
|
76 |
for result in news_results:
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
๋งํฌ: {url}
|
85 |
-
๋ด์ฉ: {snippet}
|
86 |
-
์ถ์ฒ: {channel} - {time_str}
|
87 |
-
---"""
|
88 |
-
formatted_results.append(article_info)
|
89 |
|
90 |
-
return formatted_results
|
91 |
|
92 |
except Exception as e:
|
93 |
-
return [f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"]
|
94 |
|
95 |
def serphouse_search(query, country, page, num_result):
|
96 |
results = search_serphouse(query, country, page, num_result)
|
@@ -110,7 +106,7 @@ iface = gr.Interface(
|
|
110 |
gr.Slider(1, 10, 1, label="ํ์ด์ง"),
|
111 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
112 |
],
|
113 |
-
outputs=gr.
|
114 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
115 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.",
|
116 |
theme="Nymbo/Nymbo_Theme",
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
5 |
+
import pandas as pd
|
6 |
|
7 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
8 |
|
|
|
59 |
|
60 |
def format_results(results):
|
61 |
if isinstance(results, dict) and "error" in results:
|
62 |
+
return pd.DataFrame({"Error": [results["error"]]})
|
63 |
|
64 |
try:
|
65 |
if not isinstance(results, dict):
|
|
|
71 |
news_results = results["results"].get("news", [])
|
72 |
|
73 |
if not news_results:
|
74 |
+
return pd.DataFrame({"Message": ["๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."]})
|
75 |
|
76 |
formatted_results = []
|
77 |
for result in news_results:
|
78 |
+
formatted_results.append({
|
79 |
+
"์ ๋ชฉ": result.get("title", "์ ๋ชฉ ์์"),
|
80 |
+
"๋งํฌ": result.get("url", "#"),
|
81 |
+
"๋ด์ฉ": result.get("snippet", "๋ด์ฉ ์์"),
|
82 |
+
"์ถ์ฒ": result.get("channel", "์ ์ ์์"),
|
83 |
+
"์๊ฐ": result.get("time", "์ ์ ์๋ ์๊ฐ")
|
84 |
+
})
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
return pd.DataFrame(formatted_results)
|
87 |
|
88 |
except Exception as e:
|
89 |
+
return pd.DataFrame({"Error": [f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"]})
|
90 |
|
91 |
def serphouse_search(query, country, page, num_result):
|
92 |
results = search_serphouse(query, country, page, num_result)
|
|
|
106 |
gr.Slider(1, 10, 1, label="ํ์ด์ง"),
|
107 |
gr.Slider(1, 100, 10, label="๊ฒฐ๊ณผ ์")
|
108 |
],
|
109 |
+
outputs=gr.Dataframe(label="๋ด์ค ๊ฒฐ๊ณผ"),
|
110 |
title="24์๊ฐ ์ด๋ด ๋ด์ค ๊ฒ์ ์ธํฐํ์ด์ค",
|
111 |
description="๊ฒ์์ด๋ฅผ ์
๋ ฅํ๊ณ ๊ตญ๊ฐ๋ฅผ ์ ํํ์ฌ 24์๊ฐ ์ด๋ด์ ๋ด์ค ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.",
|
112 |
theme="Nymbo/Nymbo_Theme",
|