Commit
·
9b42cbc
1
Parent(s):
84078e8
added project
Browse files- requirements.txt +4 -0
- streamlit_code.py +47 -0
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.14.0
|
| 2 |
+
pandas==1.5.3
|
| 3 |
+
matplotlib==3.6.2
|
| 4 |
+
textblob==0.15.3
|
streamlit_code.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from textblob import TextBlob
|
| 5 |
+
|
| 6 |
+
def load_data(uploaded_file):
|
| 7 |
+
df = pd.read_excel(uploaded_file)
|
| 8 |
+
return df
|
| 9 |
+
|
| 10 |
+
def analyze_sentiment(text):
|
| 11 |
+
polarity = TextBlob(str(text)).sentiment.polarity
|
| 12 |
+
if polarity >= 0.6:
|
| 13 |
+
return "Very Positive"
|
| 14 |
+
elif polarity >= 0.2:
|
| 15 |
+
return "Positive"
|
| 16 |
+
elif polarity > -0.2:
|
| 17 |
+
return "Neutral"
|
| 18 |
+
elif polarity > -0.6:
|
| 19 |
+
return "Negative"
|
| 20 |
+
else:
|
| 21 |
+
return "Very Negative"
|
| 22 |
+
|
| 23 |
+
st.title("Sentiment Analysis with Pie Chart")
|
| 24 |
+
|
| 25 |
+
uploaded_file = st.file_uploader("Upload an Excel file with text data", type=["xlsx"])
|
| 26 |
+
|
| 27 |
+
if uploaded_file is not None:
|
| 28 |
+
df = load_data(uploaded_file)
|
| 29 |
+
if "text" not in df.columns:
|
| 30 |
+
st.error("Error: The file must contain a 'text' column.")
|
| 31 |
+
else:
|
| 32 |
+
df["Sentiment"] = df["text"].apply(analyze_sentiment)
|
| 33 |
+
|
| 34 |
+
st.write("Here is a preview of the data:")
|
| 35 |
+
st.write(df.head())
|
| 36 |
+
|
| 37 |
+
sentiment_counts = df["Sentiment"].value_counts()
|
| 38 |
+
|
| 39 |
+
fig, ax = plt.subplots()
|
| 40 |
+
ax.pie(sentiment_counts, labels=sentiment_counts.index, autopct="%1.1f%%", colors=["green", "lightgreen", "gray", "orange", "red"])
|
| 41 |
+
ax.set_title("Sentiment Distribution")
|
| 42 |
+
st.pyplot(fig)
|
| 43 |
+
|
| 44 |
+
csv = df.to_csv(index=False)
|
| 45 |
+
st.download_button("Download Sentiment Data", csv, "sentiment_results.csv", "text/csv")
|
| 46 |
+
else:
|
| 47 |
+
st.write("Please upload an Excel file to get started.")
|