File size: 2,600 Bytes
3bf50ea 40aea7b 3bf50ea 40aea7b |
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 46 47 48 49 50 51 52 53 54 55 |
import os
import time
import requests
import streamlit as st
# 🔥 Change this to match your Hugging Face Space name
API_URL = "https://news-summarise-tts.hf.space" # Replace with your actual Space URL
st.title("News Summarization and Hindi TTS Application")
company = st.text_input("Enter Company Name", "")
if st.button("Fetch News"):
if company.strip() == "":
st.warning("Please enter a valid company name.")
else:
with st.spinner("Fetching and processing news..."):
try:
response = requests.get(f"{API_URL}/news/{company}")
if response.status_code == 200:
data = response.json()
st.header(f"News for {data['company']}")
for article in data["articles"]:
st.subheader(article.get("title", "No Title"))
st.markdown(f"**URL:** [Read More]({article.get('url', '#')})")
st.markdown(f"**Date:** {article.get('date', 'N/A')}")
st.markdown(f"**Sentiment:** {article.get('sentiment', 'Neutral')} (Score: {article.get('score', 0):.2f})")
st.markdown(f"**Excerpt:** {article.get('content','')[:300]}...")
st.markdown("---")
st.subheader("Comparative Sentiment Analysis")
comp_sent = data.get("comparative_sentiment", {})
st.write({k: comp_sent[k] for k in ["Positive", "Negative", "Neutral"]})
if "graph" in comp_sent and os.path.exists(comp_sent["graph"]):
st.image(comp_sent["graph"], caption="Sentiment Analysis Graph")
st.subheader("Final Combined Summary")
st.write(data.get("final_summary", "No summary available."))
st.subheader("Hindi Summary")
st.write(data.get("hindi_summary", ""))
st.subheader("Hindi Summary Audio")
audio_path = data.get("tts_audio", None)
if audio_path and os.path.exists(audio_path):
with open(audio_path, "rb") as audio_file:
st.audio(audio_file.read(), format='audio/mp3')
else:
st.error("Audio file not found or TTS generation failed.")
else:
st.error("Failed to fetch news from the API. Please try again.")
except requests.exceptions.RequestException as e:
st.error(f"API error: {e}")
|