Spaces:
Sleeping
Sleeping
Add Streamlit sentiment analysis app
Browse files
app.py
CHANGED
@@ -33,19 +33,25 @@ if uploaded_file is not None:
|
|
33 |
if st.button("Analyze Sentiment"):
|
34 |
df["Sentiment"] = predict_sentiment(df[text_column].astype(str).tolist())
|
35 |
|
36 |
-
#
|
37 |
-
st.
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
if st.button("Analyze Sentiment"):
|
34 |
df["Sentiment"] = predict_sentiment(df[text_column].astype(str).tolist())
|
35 |
|
36 |
+
# Store results in session state
|
37 |
+
st.session_state["df_results"] = df
|
38 |
+
|
39 |
+
# Display the results only if available in session state
|
40 |
+
if "df_results" in st.session_state:
|
41 |
+
df = st.session_state["df_results"]
|
42 |
+
|
43 |
+
st.write("### Sentiment Analysis Results:")
|
44 |
+
st.dataframe(df[[text_column, "Sentiment"]])
|
45 |
+
|
46 |
+
# Pie chart
|
47 |
+
sentiment_counts = df["Sentiment"].value_counts()
|
48 |
+
all_sentiments = ["Very Negative", "Negative", "Neutral", "Positive", "Very Positive"]
|
49 |
+
sentiment_counts = sentiment_counts.reindex(all_sentiments, fill_value=0)
|
50 |
+
|
51 |
+
fig, ax = plt.subplots()
|
52 |
+
ax.pie(sentiment_counts, labels=sentiment_counts.index, autopct='%1.1f%%', colors=["red", "orange", "gray", "lightgreen", "green"])
|
53 |
+
ax.set_title("Sentiment Distribution")
|
54 |
+
st.pyplot(fig)
|
55 |
+
|
56 |
+
# Download option
|
57 |
+
st.download_button("Download Results", df.to_csv(index=False).encode('utf-8'), "sentiment_results.csv", "text/csv")
|