Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -69,19 +69,28 @@ if file is not None:
|
|
69 |
# Define sentiment colors
|
70 |
sentiment_colors = {'POSITIVE': 'FFC845', 'NEGATIVE': '52565E'}
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Map sentiment to colours and apply to review column
|
73 |
-
|
74 |
|
75 |
# Create HTML table with no border and centered text
|
76 |
-
table_html = (
|
77 |
.set_properties(**{'text-align': 'center'})
|
78 |
.set_table_styles(
|
79 |
-
|
80 |
-
.
|
81 |
|
82 |
# Display the table
|
83 |
st.write(table_html, unsafe_allow_html=True)
|
84 |
|
85 |
-
|
86 |
else:
|
87 |
st.write("Please upload a CSV file.")
|
|
|
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.")
|