Delete app1.py
Browse files
app1.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import feedparser
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
API_KEY = "A3WuGPFo3tqoY2CDWs1JP27K1nrtx8nWdi4053Jt"
|
| 6 |
-
|
| 7 |
-
def get_combined_news():
|
| 8 |
-
result = "\n\n"
|
| 9 |
-
index = 1
|
| 10 |
-
|
| 11 |
-
# Marketaux
|
| 12 |
-
try:
|
| 13 |
-
url = f"https://api.marketaux.com/v1/news/all?language=en&limit=3&api_token={API_KEY}"
|
| 14 |
-
data = requests.get(url).json()
|
| 15 |
-
for article in data.get("data", []):
|
| 16 |
-
title = article.get("title", "No title")
|
| 17 |
-
link = article.get("url", "#")
|
| 18 |
-
source = article.get("source", "Unknown")
|
| 19 |
-
published = article.get("published_at", "")
|
| 20 |
-
result += f"**{index}. [{title}]({link})** \n<sub>{source} – {published}</sub>\n\n"
|
| 21 |
-
index += 1
|
| 22 |
-
except:
|
| 23 |
-
result += "*Lỗi khi lấy từ Marketaux*\n\n"
|
| 24 |
-
|
| 25 |
-
# Google RSS
|
| 26 |
-
try:
|
| 27 |
-
feed_url = "https://news.google.com/rss/search?q=site:finance.yahoo.com&hl=en-US&gl=US&ceid=US:en"
|
| 28 |
-
feed = feedparser.parse(feed_url)
|
| 29 |
-
for entry in feed.entries[:10]:
|
| 30 |
-
result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
|
| 31 |
-
index += 1
|
| 32 |
-
except:
|
| 33 |
-
result += "*Lỗi khi lấy từ Google RSS*\n\n"
|
| 34 |
-
|
| 35 |
-
return result
|
| 36 |
-
|
| 37 |
-
# Tự động load luôn khi mở web (live=True)
|
| 38 |
-
# Giao diện Gradio với theme tối + tự chạy
|
| 39 |
-
theme = gr.themes.Base().set(
|
| 40 |
-
body_background_fill="#000000", # nền đen
|
| 41 |
-
body_text_color="#ffffff", # chữ trắng
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
gr.Interface(
|
| 45 |
-
fn=get_combined_news,
|
| 46 |
-
inputs=None,
|
| 47 |
-
outputs="markdown",
|
| 48 |
-
live=True, # tự động chạy khi mở web
|
| 49 |
-
theme=theme,
|
| 50 |
-
|
| 51 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|