Spaces:
No application file
No application file
Create text-classificaton-forNews
Browse files- text-classificaton-forNews +123 -0
text-classificaton-forNews
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
BASE_URL = "http://localhost:8000" # Base URL for API requests
|
| 5 |
+
st.title("Company News Sentiment Analysis")
|
| 6 |
+
|
| 7 |
+
# Input field for company name
|
| 8 |
+
company_name = st.text_input(
|
| 9 |
+
"Enter the company name:",
|
| 10 |
+
placeholder="Example: Microsoft, Apple, Tesla"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Function to display articles with sentiment analysis
|
| 14 |
+
def display_articles(articles):
|
| 15 |
+
for i, article in enumerate(articles, start=1):
|
| 16 |
+
st.markdown(f"##### **Article {i}: {article['Title']}**")
|
| 17 |
+
st.write(f"- **Summary:** {article['Summary']}")
|
| 18 |
+
st.write(f"- **Sentiment:** {article['Sentiment']} | **Score:** {article['Score']:.2f}")
|
| 19 |
+
st.write(f"- **Topics:** {', '.join(article['Topics'])}")
|
| 20 |
+
|
| 21 |
+
# Function to display sentiment distribution in table format
|
| 22 |
+
def display_sentiment_distribution(sentiment_distribution):
|
| 23 |
+
st.markdown("#### **Sentiment Distribution:**")
|
| 24 |
+
sentiment_data = {
|
| 25 |
+
"Sentiment": list(sentiment_distribution.keys()),
|
| 26 |
+
"Count": list(sentiment_distribution.values())
|
| 27 |
+
}
|
| 28 |
+
st.table(sentiment_data)
|
| 29 |
+
|
| 30 |
+
# Function to display coverage differences between articles
|
| 31 |
+
def display_coverage_differences(coverage_differences):
|
| 32 |
+
if coverage_differences:
|
| 33 |
+
st.markdown("#### **Coverage Differences:**")
|
| 34 |
+
for diff in coverage_differences:
|
| 35 |
+
st.write(f"- **{diff['Comparison']}:** {diff['Impact']}")
|
| 36 |
+
|
| 37 |
+
# Function to display topic overlap analysis
|
| 38 |
+
def display_topic_overlap(topic_overlap):
|
| 39 |
+
st.markdown("#### **Topic Overlap:**")
|
| 40 |
+
st.write(f"- **Common Topics:** {', '.join(topic_overlap['Common Topics'])}")
|
| 41 |
+
st.markdown("- **Unique Topics by Article:**")
|
| 42 |
+
for article, topics in topic_overlap["Unique Topics"].items():
|
| 43 |
+
st.write(f" - **{article}:** {', '.join(topics)}")
|
| 44 |
+
|
| 45 |
+
# Button to generate summary based on company name
|
| 46 |
+
if st.button("Generate Summary"):
|
| 47 |
+
if company_name:
|
| 48 |
+
try:
|
| 49 |
+
summary_url = f"{BASE_URL}/generateSummary?company_name={company_name}"
|
| 50 |
+
response = requests.post(summary_url)
|
| 51 |
+
|
| 52 |
+
if response.status_code == 200:
|
| 53 |
+
data = response.json()
|
| 54 |
+
st.markdown(f"#### **Company: {data.get('Company', 'Unknown')}**")
|
| 55 |
+
|
| 56 |
+
# Display articles with sentiment analysis
|
| 57 |
+
st.markdown("#### **Articles:**")
|
| 58 |
+
display_articles(data.get("Articles", []))
|
| 59 |
+
|
| 60 |
+
# Display sentiment analysis details
|
| 61 |
+
st.markdown("#### **Comparative Sentiment Score:**")
|
| 62 |
+
sentiment_distribution = data.get("Comparative Sentiment Score", {}).get("Sentiment Distribution", {})
|
| 63 |
+
display_sentiment_distribution(sentiment_distribution)
|
| 64 |
+
|
| 65 |
+
coverage_differences = data.get("Comparative Sentiment Score", {}).get("Coverage Differences", [])
|
| 66 |
+
display_coverage_differences(coverage_differences)
|
| 67 |
+
|
| 68 |
+
topic_overlap = data.get("Comparative Sentiment Score", {}).get("Topic Overlap", {})
|
| 69 |
+
display_topic_overlap(topic_overlap)
|
| 70 |
+
|
| 71 |
+
# Display final sentiment analysis result
|
| 72 |
+
st.markdown("#### **Final Sentiment Analysis:**")
|
| 73 |
+
st.write(data.get("Final Sentiment Analysis", "No sentiment analysis available."))
|
| 74 |
+
|
| 75 |
+
# Display and play Hindi summary audio
|
| 76 |
+
st.markdown("#### **Hindi Summary Audio:**")
|
| 77 |
+
st.write(data.get("Audio", "No Audio available"))
|
| 78 |
+
audio_url = f"{BASE_URL}/downloadHindiAudio"
|
| 79 |
+
audio_response = requests.get(audio_url)
|
| 80 |
+
if audio_response.status_code == 200:
|
| 81 |
+
st.audio(audio_response.content, format="audio/mp3")
|
| 82 |
+
else:
|
| 83 |
+
st.error("Failed to load audio.")
|
| 84 |
+
else:
|
| 85 |
+
st.error(f"Error: {response.status_code}, {response.text}")
|
| 86 |
+
except Exception as e:
|
| 87 |
+
st.error(f"An error occurred: {e}")
|
| 88 |
+
else:
|
| 89 |
+
st.warning("Please enter a company name !")
|
| 90 |
+
|
| 91 |
+
# Button to download the final summary in JSON format
|
| 92 |
+
if st.button("Download JSON File"):
|
| 93 |
+
json_url = f"{BASE_URL}/downloadJson"
|
| 94 |
+
try:
|
| 95 |
+
response = requests.get(json_url)
|
| 96 |
+
if response.status_code == 200:
|
| 97 |
+
st.download_button(
|
| 98 |
+
label="Download JSON File",
|
| 99 |
+
data=response.content,
|
| 100 |
+
file_name="final_summary.json",
|
| 101 |
+
mime="application/json",
|
| 102 |
+
)
|
| 103 |
+
else:
|
| 104 |
+
st.error(f"Error: {response.status_code}, {response.text}")
|
| 105 |
+
except Exception as e:
|
| 106 |
+
st.error(f"An error occurred: {e}")
|
| 107 |
+
|
| 108 |
+
# Button to download Hindi summary audio file
|
| 109 |
+
if st.button("Download Hindi Audio"):
|
| 110 |
+
audio_url = f"{BASE_URL}/downloadHindiAudio"
|
| 111 |
+
try:
|
| 112 |
+
response = requests.get(audio_url)
|
| 113 |
+
if response.status_code == 200:
|
| 114 |
+
st.download_button(
|
| 115 |
+
label="Download Hindi Audio",
|
| 116 |
+
data=response.content,
|
| 117 |
+
file_name="hindi_summary.mp3",
|
| 118 |
+
mime="audio/mp3",
|
| 119 |
+
)
|
| 120 |
+
else:
|
| 121 |
+
st.error(f"Error: {response.status_code}, {response.text}")
|
| 122 |
+
except Exception as e:
|
| 123 |
+
st.error(f"An error occurred: {e}")
|