Spaces:
Sleeping
Sleeping
File size: 1,512 Bytes
524d6a6 1210579 524d6a6 1210579 524d6a6 1210579 524d6a6 1210579 524d6a6 1210579 524d6a6 1210579 |
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 |
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from textblob import TextBlob
def load_data(uploaded_file):
df = pd.read_excel(uploaded_file)
return df
def analyze_sentiment(text):
polarity = TextBlob(str(text)).sentiment.polarity
if polarity >= 0.6:
return "Very Positive"
elif polarity >= 0.2:
return "Positive"
elif polarity > -0.2:
return "Neutral"
elif polarity > -0.6:
return "Negative"
else:
return "Very Negative"
st.title("Sentiment Analysis with Pie Chart")
uploaded_file = st.file_uploader("Upload an Excel file with text data", type=["xlsx"])
if uploaded_file is not None:
df = load_data(uploaded_file)
if "text" not in df.columns:
st.error("Error: The file must contain a 'text' column.")
else:
df["Sentiment"] = df["text"].apply(analyze_sentiment)
st.write("Here is a preview of the data:")
st.write(df.head())
sentiment_counts = df["Sentiment"].value_counts()
fig, ax = plt.subplots()
ax.pie(sentiment_counts, labels=sentiment_counts.index, autopct="%1.1f%%", colors=["green", "lightgreen", "gray", "orange", "red"])
ax.set_title("Sentiment Distribution")
st.pyplot(fig)
csv = df.to_csv(index=False)
st.download_button("Download Sentiment Data", csv, "sentiment_results.csv", "text/csv")
else:
st.write("Please upload an Excel file to get started.")
|