Download app.py from nick5363/Web: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/nick5363/Web/resolve/main/app.py
- Command line
-
hf download hf://spaces/nick5363/Web/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nick5363/Web/resolve/main/app.py
1.79 kB
| import requests | |
| import feedparser | |
| import gradio as gr | |
| API_KEY = "A3WuGPFo3tqoY2CDWs1JP27K1nrtx8nWdi4053Jt" | |
| def get_combined_news(): | |
| result = "\n\n" | |
| index = 1 | |
| try: | |
| vnexpress_url = "https://vnexpress.net/rss/kinh-doanh.rss" | |
| vn_feed = feedparser.parse(vnexpress_url) | |
| for entry in vn_feed.entries[:5]: | |
| result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n" | |
| index += 1 | |
| except: | |
| result += "*Lỗi khi lấy tin từ VnExpress*\n\n" | |
| try: | |
| url = f"https://api.marketaux.com/v1/news/all?language=en&limit=3&api_token={API_KEY}" | |
| data = requests.get(url).json() | |
| for article in data.get("data", []): | |
| title = article.get("title", "No title") | |
| link = article.get("url", "#") | |
| source = article.get("source", "Unknown") | |
| published = article.get("published_at", "") | |
| result += f"**{index}. [{title}]({link})** \n<sub>{source} – {published}</sub>\n\n" | |
| index += 1 | |
| except: | |
| result += "*Lỗi khi lấy từ Marketaux*\n\n" | |
| try: | |
| feed_url = "https://news.google.com/rss/search?q=site:finance.yahoo.com&hl=en-US&gl=US&ceid=US:en" | |
| feed = feedparser.parse(feed_url) | |
| for entry in feed.entries[:10]: | |
| result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n" | |
| index += 1 | |
| except: | |
| result += "*Lỗi khi lấy từ Google RSS*\n\n" | |
| return result | |
| # Dùng dark theme chuẩn trong Gradio mới | |
| dark_theme = gr.themes.Soft(primary_hue="blue", neutral_hue="gray") | |
| gr.Interface( | |
| fn=get_combined_news, | |
| inputs=None, | |
| outputs="markdown", | |
| live=True, | |
| theme=dark_theme, | |
| ).launch(share=True) |