logeswari commited on
Commit
006e4b1
·
1 Parent(s): 9355775
Files changed (1) hide show
  1. app.py +19 -16
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["Sentiment"] = predict_sentiment(df[text_column].astype(str).tolist())
36
-
37
- # Display results
38
- st.write("### Sentiment Analysis Results:")
39
- st.dataframe(df[[text_column, "Sentiment"]])
40
-
41
- # Pie chart
42
- sentiment_counts = df["Sentiment"].value_counts()
43
- fig, ax = plt.subplots()
44
- ax.pie(sentiment_counts, labels=sentiment_counts.index, autopct='%1.1f%%', colors=["red", "orange", "gray", "lightgreen", "green"])
45
- ax.set_title("Sentiment Distribution")
46
- st.pyplot(fig)
47
-
48
- # Download option
49
- st.sidebar.download_button("Download Results", df.to_csv(index=False).encode('utf-8'), "sentiment_results.csv", "text/csv")
 
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")