Uvini commited on
Commit
ad58ea2
·
1 Parent(s): 8486637

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -50,14 +50,14 @@ if file is not None:
50
  f'<div style="background-color: #FFC845; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-bottom: 40px;"> Causes behind Positive Reviews</div>',
51
  unsafe_allow_html=True
52
  )
53
- wc = WordCloud(width=800, height=400, background_color="white", colormap="copper").generate(positive_reviews)
54
  st.image(wc.to_array())
55
 
56
  st.markdown(
57
  f'<div style="background-color: #52565E; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-bottom: 40px; margin-top: 60px;"> Causes behind Negative Reviews</div>',
58
  unsafe_allow_html=True
59
  )
60
- wc = WordCloud(width=800, height=400, background_color="white", colormap="copper").generate(negative_reviews)
61
  st.image(wc.to_array())
62
 
63
  # Display the sentiment of each review as cards
@@ -68,26 +68,23 @@ if file is not None:
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":
@@ -96,6 +93,5 @@ if file is not None:
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.")
 
50
  f'<div style="background-color: #FFC845; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-bottom: 40px;"> Causes behind Positive Reviews</div>',
51
  unsafe_allow_html=True
52
  )
53
+ wc = WordCloud(width=800, height=400, background_color="white", colormap="Greens").generate(positive_reviews)
54
  st.image(wc.to_array())
55
 
56
  st.markdown(
57
  f'<div style="background-color: #52565E; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-bottom: 40px; margin-top: 60px;"> Causes behind Negative Reviews</div>',
58
  unsafe_allow_html=True
59
  )
60
+ wc = WordCloud(width=800, height=400, background_color="white", colormap="Greens").generate(negative_reviews)
61
  st.image(wc.to_array())
62
 
63
  # Display the sentiment of each review as cards
 
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': 'left'})
79
  .set_table_styles([{'selector': 'th', 'props': [('border', '0px')]},
80
  {'selector': 'td', 'props': [('border', '0px')]}])
81
+ .background_gradient(subset=['sentiment'], cmap=sentiment_colors)
82
+ .hide_index()
83
  .to_html(escape=False))
84
 
85
+ # Add the title of the table and the selectbox to filter sentiments
86
  st.title("Sentiment Analysis Results")
87
+ filter_sentiment = st.selectbox("Filter Sentiment", ["All"] + list(sentiment_colors.keys()))
 
 
 
 
 
88
 
89
  # Filter the dataframe based on the selected sentiment
90
  if filter_sentiment != "All":
 
93
  # Display the table and the selectbox widget beside the title
94
  st.write(table_html, unsafe_allow_html=True)
95
 
 
96
  else:
97
  st.write("Please upload a CSV file.")