Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,45 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
)
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
for
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
"""
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
-
demo = gr.ChatInterface(
|
46 |
-
respond,
|
47 |
-
additional_inputs=[
|
48 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
49 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
-
gr.Slider(
|
52 |
-
minimum=0.1,
|
53 |
-
maximum=1.0,
|
54 |
-
value=0.95,
|
55 |
-
step=0.05,
|
56 |
-
label="Top-p (nucleus sampling)",
|
57 |
-
),
|
58 |
],
|
|
|
|
|
|
|
59 |
)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from gnewsclient import gnewsclient
|
3 |
+
from datetime import datetime, timedelta
|
4 |
+
|
5 |
+
# Google ๋ด์ค ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
6 |
+
client = gnewsclient.NewsClient()
|
7 |
+
|
8 |
+
# ์ง์๋๋ ๊ตญ๊ฐ ๋ชฉ๋ก
|
9 |
+
supported_countries = client.locations
|
10 |
+
|
11 |
+
def get_news(country, keyword):
|
12 |
+
# ๊ตญ๊ฐ ์ค์
|
13 |
+
client.location = country
|
14 |
+
client.language = 'en' # ์์ด๋ก ์ค์
|
15 |
+
|
16 |
+
# ํ์ฌ ์๊ฐ ๊ธฐ์ค 24์๊ฐ ์ ์๊ฐ ๊ณ์ฐ
|
17 |
+
time_threshold = datetime.now() - timedelta(hours=24)
|
18 |
+
|
19 |
+
# ๋ด์ค ๊ฒ์
|
20 |
+
news_items = client.get_news(keyword)
|
21 |
+
|
22 |
+
# 24์๊ฐ ์ด๋ด์ ๋ด์ค๋ง ํํฐ๋งํ๊ณ ์ ๋ชฉ๊ณผ ๋งํฌ ์ถ์ถ
|
23 |
+
filtered_news = []
|
24 |
+
for item in news_items:
|
25 |
+
if 'published' in item:
|
26 |
+
news_date = datetime.strptime(item['published'], "%a, %d %b %Y %H:%M:%S %Z")
|
27 |
+
if news_date > time_threshold:
|
28 |
+
filtered_news.append(f"Title: {item['title']}\nLink: {item['link']}\n")
|
29 |
+
|
30 |
+
return "\n".join(filtered_news) if filtered_news else "No recent news found for the given keyword."
|
31 |
+
|
32 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=get_news,
|
35 |
+
inputs=[
|
36 |
+
gr.Dropdown(choices=supported_countries, label="Select Country"),
|
37 |
+
gr.Textbox(label="Enter keyword")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
],
|
39 |
+
outputs="text",
|
40 |
+
title="Google News Search",
|
41 |
+
description="Search for news articles from the last 24 hours using Google News."
|
42 |
)
|
43 |
|
44 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
45 |
+
iface.launch()
|
|