Spaces:
Running
Running
File size: 1,439 Bytes
ad0f104 ab30506 ad0f104 ab30506 ad0f104 ab30506 |
1 2 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
from gnewsclient import gnewsclient
from datetime import datetime, timedelta
# Google ๋ด์ค ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
client = gnewsclient.NewsClient()
# ์ง์๋๋ ๊ตญ๊ฐ ๋ชฉ๋ก
supported_countries = client.locations
def get_news(country, keyword):
# ๊ตญ๊ฐ ์ค์
client.location = country
client.language = 'en' # ์์ด๋ก ์ค์
# ํ์ฌ ์๊ฐ ๊ธฐ์ค 24์๊ฐ ์ ์๊ฐ ๊ณ์ฐ
time_threshold = datetime.now() - timedelta(hours=24)
# ๋ด์ค ๊ฒ์
news_items = client.get_news(keyword)
# 24์๊ฐ ์ด๋ด์ ๋ด์ค๋ง ํํฐ๋งํ๊ณ ์ ๋ชฉ๊ณผ ๋งํฌ ์ถ์ถ
filtered_news = []
for item in news_items:
if 'published' in item:
news_date = datetime.strptime(item['published'], "%a, %d %b %Y %H:%M:%S %Z")
if news_date > time_threshold:
filtered_news.append(f"Title: {item['title']}\nLink: {item['link']}\n")
return "\n".join(filtered_news) if filtered_news else "No recent news found for the given keyword."
# Gradio ์ธํฐํ์ด์ค ์์ฑ
iface = gr.Interface(
fn=get_news,
inputs=[
gr.Dropdown(choices=supported_countries, label="Select Country"),
gr.Textbox(label="Enter keyword")
],
outputs="text",
title="Google News Search",
description="Search for news articles from the last 24 hours using Google News."
)
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
iface.launch() |