Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,59 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import requests
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
BACKEND_URL = "
|
7 |
-
|
8 |
-
st.title("π News Sentiment Analysis & TTS in Hindi")
|
9 |
-
|
10 |
-
# Input field for company name
|
11 |
-
company_name = st.text_input("Enter Company Name", "")
|
12 |
-
|
13 |
-
if st.button("Analyze"):
|
14 |
-
if not company_name:
|
15 |
-
st.warning("β οΈ Please enter a company name.")
|
16 |
-
else:
|
17 |
-
st.info(f"Analyzing news for {company_name}...")
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
st.
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
st.
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
st.error("β Error analyzing news. Please try again.")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
# β
Replace with your Hugging Face backend URL
|
6 |
+
BACKEND_URL = "https://<your-huggingface-space-name>.hf.space/analyze"
|
7 |
+
|
8 |
+
st.title("π News Sentiment Analysis & TTS in Hindi")
|
9 |
+
|
10 |
+
# Input field for company name
|
11 |
+
company_name = st.text_input("Enter Company Name", "")
|
12 |
+
|
13 |
+
if st.button("Analyze"):
|
14 |
+
if not company_name:
|
15 |
+
st.warning("β οΈ Please enter a company name.")
|
16 |
+
else:
|
17 |
+
st.info(f"π Analyzing news for {company_name}...")
|
18 |
+
|
19 |
+
# Send request to Flask backend
|
20 |
+
response = requests.post(
|
21 |
+
BACKEND_URL,
|
22 |
+
json={"company_name": company_name}
|
23 |
+
)
|
24 |
+
|
25 |
+
if response.status_code == 200:
|
26 |
+
data = response.json()
|
27 |
+
|
28 |
+
st.success("β
Analysis Complete!")
|
29 |
+
|
30 |
+
# β
Display Sentiment Summary
|
31 |
+
st.subheader("π Sentiment Summary")
|
32 |
+
st.json(data["sentiment_summary"])
|
33 |
+
|
34 |
+
# β
Display Articles
|
35 |
+
st.subheader("π° Extracted Articles")
|
36 |
+
|
37 |
+
df = pd.DataFrame(data["articles"])
|
38 |
+
|
39 |
+
for _, article in df.iterrows():
|
40 |
+
st.markdown(f"### [{article['title']}]({article['url']})")
|
41 |
+
st.write(f"**Summary:** {article['summary']}")
|
42 |
+
st.write("---")
|
43 |
+
|
44 |
+
# β
Display Hindi TTS Audio
|
45 |
+
st.subheader("π Hindi TTS Audio Output")
|
46 |
+
|
47 |
+
audio_file_url = f"{BACKEND_URL}/{data['audio_file']}"
|
48 |
+
|
49 |
+
st.audio(audio_file_url, format="audio/mp3")
|
50 |
+
|
51 |
+
st.download_button(
|
52 |
+
label="β¬οΈ Download Hindi TTS Audio",
|
53 |
+
data=requests.get(audio_file_url).content,
|
54 |
+
file_name=f"{company_name}_TTS.mp3",
|
55 |
+
mime="audio/mpeg"
|
56 |
+
)
|
57 |
+
|
58 |
+
else:
|
59 |
+
st.error("β Error analyzing news. Please try again.")
|
|