File size: 1,936 Bytes
c7a5805
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
import streamlit as st
import requests
import pandas as pd

# βœ… Replace with your Hugging Face backend URL
# βœ… Use the deployed backend Space URL
BACKEND_URL = "https://manishkumaryadav-news-summarize.hf.space/analyze"



st.title("πŸ“Š News Sentiment Analysis & TTS in Hindi")

# Input field for company name
company_name = st.text_input("Enter Company Name", "")

if st.button("Analyze"):
    if not company_name:
        st.warning("⚠️ Please enter a company name.")
    else:
        st.info(f"πŸ” Analyzing news for {company_name}...")

        # Send request to Flask backend
        response = requests.post(
            BACKEND_URL,
            json={"company_name": company_name}
        )

        if response.status_code == 200:
            data = response.json()

            st.success("βœ… Analysis Complete!")

            # βœ… Display Sentiment Summary
            st.subheader("πŸ“Š Sentiment Summary")
            st.json(data["sentiment_summary"])

            # βœ… Display Articles
            st.subheader("πŸ“° Extracted Articles")
            
            df = pd.DataFrame(data["articles"])
            
            for _, article in df.iterrows():
                st.markdown(f"### [{article['title']}]({article['url']})")
                st.write(f"**Summary:** {article['summary']}")
                st.write("---")

            # βœ… Display Hindi TTS Audio
            st.subheader("πŸ”Š Hindi TTS Audio Output")

            audio_file_url = f"{BACKEND_URL}/{data['audio_file']}"
            
            st.audio(audio_file_url, format="audio/mp3")

            st.download_button(
                label="⬇️ Download Hindi TTS Audio",
                data=requests.get(audio_file_url).content,
                file_name=f"{company_name}_TTS.mp3",
                mime="audio/mpeg"
            )
            
        else:
            st.error("❌ Error analyzing news. Please try again.")