Uvini commited on
Commit
10d74d4
·
1 Parent(s): 24f37e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -30,21 +30,21 @@ if file is not None:
30
  )
31
 
32
  # Apply the sentiment analysis model to each review and store the results in a new column
33
- df["sentiment"] = df["review"].apply(lambda x: sentiment_model(x)[0]["label"])
34
 
35
  # Generate pie chart
36
  # Define custom colors
37
  colors = ['#FFC845', '#52565E']
38
 
39
  # Generate pie chart
40
- sentiment_counts = df["sentiment"].value_counts()
41
  fig = px.pie(sentiment_counts, values=sentiment_counts.values, names=sentiment_counts.index,
42
  color_discrete_sequence=colors)
43
  st.plotly_chart(fig)
44
 
45
  # Create word clouds for positive and negative reviews
46
- positive_reviews = " ".join(df[df["sentiment"] == "POSITIVE"]["review"].tolist())
47
- negative_reviews = " ".join(df[df["sentiment"] == "NEGATIVE"]["review"].tolist())
48
 
49
  st.markdown(
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>',
@@ -66,28 +66,19 @@ if file is not None:
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': '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
  .to_html(escape=False))
83
 
84
- # Add the title of the table and the selectbox to filter sentiments
85
- st.title("Sentiment Analysis Results")
86
- filter_sentiment = st.selectbox("Filter Sentiment", ["All"] + list(sentiment_colors.keys()))
87
 
88
  # Filter the dataframe based on the selected sentiment
89
  if filter_sentiment != "All":
90
- df = df[df['sentiment'].str.contains(filter_sentiment)]
91
 
92
  # Display the table and the selectbox widget beside the title
93
  st.write(table_html, unsafe_allow_html=True)
 
30
  )
31
 
32
  # Apply the sentiment analysis model to each review and store the results in a new column
33
+ df["Sentiment"] = df["Review"].apply(lambda x: sentiment_model(x)[0]["label"])
34
 
35
  # Generate pie chart
36
  # Define custom colors
37
  colors = ['#FFC845', '#52565E']
38
 
39
  # Generate pie chart
40
+ sentiment_counts = df["Sentiment"].value_counts()
41
  fig = px.pie(sentiment_counts, values=sentiment_counts.values, names=sentiment_counts.index,
42
  color_discrete_sequence=colors)
43
  st.plotly_chart(fig)
44
 
45
  # Create word clouds for positive and negative reviews
46
+ positive_reviews = " ".join(df[df["Sentiment"] == "POSITIVE"]["Review"].tolist())
47
+ negative_reviews = " ".join(df[df["Sentiment"] == "NEGATIVE"]["Review"].tolist())
48
 
49
  st.markdown(
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>',
 
66
  unsafe_allow_html=True
67
  )
68
 
 
 
 
 
 
 
 
69
  # Create HTML table with no border and centered text
70
  table_html = (df.style
71
+ .set_properties(**{'text-align': 'left','font-size': '14px'})
72
  .set_table_styles([{'selector': 'th', 'props': [('border', '0px')]},
73
  {'selector': 'td', 'props': [('border', '0px')]}])
 
74
  .to_html(escape=False))
75
 
76
+ # Add the selectbox to filter sentiments
77
+ filter_sentiment = st.selectbox("Filter Sentiments", ["All"] + list(sentiment_colors.keys()))
 
78
 
79
  # Filter the dataframe based on the selected sentiment
80
  if filter_sentiment != "All":
81
+ df = df[df['Sentiment'].str.contains(filter_sentiment)]
82
 
83
  # Display the table and the selectbox widget beside the title
84
  st.write(table_html, unsafe_allow_html=True)