Uvini commited on
Commit
8486637
1 Parent(s): a67fe67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -66,31 +66,36 @@ if file is not None:
66
  unsafe_allow_html=True
67
  )
68
 
 
69
  # Define sentiment colors
70
  sentiment_colors = {'POSITIVE': 'FFC845', 'NEGATIVE': '52565E'}
71
 
72
- # Create a copy of the dataframe to use for filtering
73
- filtered_df = df.copy()
74
-
75
- # Create selectbox to filter by sentiment
76
- selected_sentiment = st.sidebar.selectbox('Filter by Sentiment', ['All'] + list(sentiment_colors.keys()))
77
-
78
- # If the user selects a specific sentiment, filter the dataframe
79
- if selected_sentiment != 'All':
80
- filtered_df = filtered_df[filtered_df['sentiment'] == selected_sentiment]
81
-
82
  # Map sentiment to colours and apply to review column
83
- filtered_df['sentiment'] = filtered_df['sentiment'].apply(lambda x: f'<span style="color: {sentiment_colors[x]}">{x}</span>')
84
 
85
  # Create HTML table with no border and centered text
86
- table_html = (filtered_df.style
87
  .set_properties(**{'text-align': 'center'})
88
- .set_table_styles(
89
- [{'selector': 'th', 'props': [('border', '0px')]}, {'selector': 'td', 'props': [('border', '0px')]}])
90
  .to_html(escape=False))
91
 
92
- # Display the table
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  st.write(table_html, unsafe_allow_html=True)
94
 
 
95
  else:
96
  st.write("Please upload a CSV file.")
 
66
  unsafe_allow_html=True
67
  )
68
 
69
+
70
  # Define sentiment colors
71
  sentiment_colors = {'POSITIVE': 'FFC845', 'NEGATIVE': '52565E'}
72
 
 
 
 
 
 
 
 
 
 
 
73
  # Map sentiment to colours and apply to review column
74
+ df['sentiment'] = df['sentiment'].apply(lambda x: f'<span style="color: {sentiment_colors[x]}">{x}</span>')
75
 
76
  # Create HTML table with no border and centered text
77
+ table_html = (df.style
78
  .set_properties(**{'text-align': 'center'})
79
+ .set_table_styles([{'selector': 'th', 'props': [('border', '0px')]},
80
+ {'selector': 'td', 'props': [('border', '0px')]}])
81
  .to_html(escape=False))
82
 
83
+ # Add the title of the table
84
+ st.title("Sentiment Analysis Results")
85
+
86
+ # Create a space in the sidebar
87
+ empty_slot = st.sidebar.empty()
88
+
89
+ # Add the selectbox to the space created above
90
+ filter_sentiment = empty_slot.selectbox("Filter Sentiment", ["All"] + list(sentiment_colors.keys()))
91
+
92
+ # Filter the dataframe based on the selected sentiment
93
+ if filter_sentiment != "All":
94
+ df = df[df['sentiment'].str.contains(filter_sentiment)]
95
+
96
+ # Display the table and the selectbox widget beside the title
97
  st.write(table_html, unsafe_allow_html=True)
98
 
99
+
100
  else:
101
  st.write("Please upload a CSV file.")