newsfeed / app.py
armandhilton's picture
Update app.py
8c62821 verified
raw
history blame contribute delete
787 Bytes
import gradio as gr
import feedparser
def fetch_rss(url):
try:
feed = feedparser.parse(url)
items = []
for entry in feed.entries[:30]:
items.append({
"title": entry.get("title", ""),
"link": entry.get("link", ""),
"pubDate": entry.get("published", ""),
"description": entry.get("summary", "")
})
return items
except Exception as e:
return [{"title": "Error", "link": "", "pubDate": "", "description": str(e)}]
# Hidden Gradio endpoint to serve backend requests only
demo = gr.Interface(
fn=fetch_rss,
inputs=gr.Textbox(),
outputs=gr.JSON(),
live=False
)
# Launch with share=False to avoid exposing frontend
demo.launch(share=False)