Spaces:
Sleeping
Sleeping
msg
Browse files
app.py
CHANGED
|
@@ -30,21 +30,24 @@ if uploaded_file is not None:
|
|
| 30 |
st.sidebar.write("✅ File Uploaded Successfully!")
|
| 31 |
|
| 32 |
text_column = st.sidebar.selectbox("Select Text Column", df.columns)
|
| 33 |
-
|
| 34 |
if st.sidebar.button("Analyze Sentiment"):
|
| 35 |
-
df
|
| 36 |
-
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
|
|
|
|
|
|
|
|
|
| 30 |
st.sidebar.write("✅ File Uploaded Successfully!")
|
| 31 |
|
| 32 |
text_column = st.sidebar.selectbox("Select Text Column", df.columns)
|
| 33 |
+
|
| 34 |
if st.sidebar.button("Analyze Sentiment"):
|
| 35 |
+
st.session_state.df = df # Store dataframe in session state
|
| 36 |
+
st.session_state.df["Sentiment"] = predict_sentiment(df[text_column].astype(str).tolist())
|
| 37 |
+
st.session_state.analysis_done = True # Set flag to indicate analysis is done
|
| 38 |
+
|
| 39 |
+
# Check if analysis is done and persist results
|
| 40 |
+
if "analysis_done" in st.session_state and st.session_state.analysis_done:
|
| 41 |
+
df = st.session_state.df # Retrieve dataframe from session state
|
| 42 |
+
st.write("### Sentiment Analysis Results:")
|
| 43 |
+
st.dataframe(df[[text_column, "Sentiment"]])
|
| 44 |
+
|
| 45 |
+
# Pie chart
|
| 46 |
+
sentiment_counts = df["Sentiment"].value_counts()
|
| 47 |
+
fig, ax = plt.subplots()
|
| 48 |
+
ax.pie(sentiment_counts, labels=sentiment_counts.index, autopct='%1.1f%%', colors=["red", "orange", "gray", "lightgreen", "green"])
|
| 49 |
+
ax.set_title("Sentiment Distribution")
|
| 50 |
+
st.pyplot(fig)
|
| 51 |
|
| 52 |
+
# Download button (chart remains visible)
|
| 53 |
+
st.sidebar.download_button("Download Results", df.to_csv(index=False).encode('utf-8'), "sentiment_results.csv", "text/csv")
|