Uvini commited on
Commit
3b4dcf9
1 Parent(s): f1f5a42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -16,7 +16,7 @@ st.set_page_config(page_title="review Analysis", page_icon=":smiley:")
16
  # Add image and heading
17
  st.image("img.png", use_column_width=True)
18
 
19
- file = st.file_uploader("", type=["csv"])
20
 
21
  # Define the app's functionality
22
  if file is not None:
@@ -25,7 +25,7 @@ if file is not None:
25
 
26
  # Write the total number of records
27
  st.markdown(
28
- f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 8px; font-size: 30px; font-family: Open-Sans; font-weight: bold; text-align: center; border-radius: 2rem"> {len(df)} reviews to analyse!</div>',
29
  unsafe_allow_html=True
30
  )
31
 
@@ -47,14 +47,14 @@ if file is not None:
47
  negative_reviews = " ".join(df[df["Sentiment"] == "NEGATIVE"]["Review"].tolist())
48
 
49
  st.markdown(
50
- f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-bottom: 40px; border-radius: 2rem"> Causes behind Positive Reviews</div>',
51
  unsafe_allow_html=True
52
  )
53
  wc = WordCloud(width=800, height=400, background_color="white", colormap="winter").generate(positive_reviews)
54
  st.image(wc.to_array(),use_column_width=True)
55
 
56
  st.markdown(
57
- f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-bottom: 40px; margin-top: 60px; border-radius: 2rem"> Causes behind Negative Reviews</div>',
58
  unsafe_allow_html=True
59
  )
60
  wc = WordCloud(width=800, height=400, background_color="white", colormap="winter").generate(negative_reviews)
@@ -62,7 +62,7 @@ if file is not None:
62
 
63
  # Display the sentiment of each review as cards
64
  st.markdown(
65
- f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 6px; font-size: 20px; font-family: Open-Sans; font-weight: bold; text-align: center; margin-top: 60px; border-radius: 2rem"> What customers said about us</div>',
66
  unsafe_allow_html=True
67
  )
68
 
@@ -75,7 +75,7 @@ if file is not None:
75
 
76
  # Create HTML table with no border and centered text
77
  table_html = (df.style
78
- .set_properties(**{'text-align': 'left','font-size': '15px','font-family': 'Open-Sans'})
79
  .set_table_styles([{'selector': 'th', 'props': [('border', '0px')]},
80
  {'selector': 'td', 'props': [('border', '0px')]}])
81
  .to_html(index=False, escape=False))
@@ -84,5 +84,18 @@ if file is not None:
84
  st.write(table_html, unsafe_allow_html=True)
85
 
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  else:
88
  st.write("Please upload a CSV file.")
 
16
  # Add image and heading
17
  st.image("img.png", use_column_width=True)
18
 
19
+ file = st.file_uploader("Upload the reviews to get started", type=["csv"])
20
 
21
  # Define the app's functionality
22
  if file is not None:
 
25
 
26
  # Write the total number of records
27
  st.markdown(
28
+ f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 8px; font-size: 30px; font-family: Verdana; font-weight: bold; text-align: center; border-radius: 2rem"> {len(df)} reviews to analyse!</div>',
29
  unsafe_allow_html=True
30
  )
31
 
 
47
  negative_reviews = " ".join(df[df["Sentiment"] == "NEGATIVE"]["Review"].tolist())
48
 
49
  st.markdown(
50
+ f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 6px; font-size: 20px; font-family: Verdana; font-weight: bold; text-align: center; margin-bottom: 40px; border-radius: 2rem"> Causes behind Positive Reviews</div>',
51
  unsafe_allow_html=True
52
  )
53
  wc = WordCloud(width=800, height=400, background_color="white", colormap="winter").generate(positive_reviews)
54
  st.image(wc.to_array(),use_column_width=True)
55
 
56
  st.markdown(
57
+ f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 6px; font-size: 20px; font-family: Verdana; font-weight: bold; text-align: center; margin-bottom: 40px; margin-top: 60px; border-radius: 2rem"> Causes behind Negative Reviews</div>',
58
  unsafe_allow_html=True
59
  )
60
  wc = WordCloud(width=800, height=400, background_color="white", colormap="winter").generate(negative_reviews)
 
62
 
63
  # Display the sentiment of each review as cards
64
  st.markdown(
65
+ f'<div style="background-color: #4AA6DD; color: #ffffff; padding: 6px; font-size: 20px; font-family: Verdana; font-weight: bold; text-align: center; margin-top: 60px; border-radius: 2rem"> What customers said about us</div>',
66
  unsafe_allow_html=True
67
  )
68
 
 
75
 
76
  # Create HTML table with no border and centered text
77
  table_html = (df.style
78
+ .set_properties(**{'text-align': 'left','font-size': '15px','font-family': 'Verdana'})
79
  .set_table_styles([{'selector': 'th', 'props': [('border', '0px')]},
80
  {'selector': 'td', 'props': [('border', '0px')]}])
81
  .to_html(index=False, escape=False))
 
84
  st.write(table_html, unsafe_allow_html=True)
85
 
86
 
87
+ def convert_df(df):
88
+ # IMPORTANT: Cache the conversion to prevent computation on every rerun
89
+ return df.to_csv().encode('utf-8')
90
+
91
+ csv = convert_df(df)
92
+
93
+ st.download_button(
94
+ label="Download data as CSV",
95
+ data=csv,
96
+ file_name='Review Sentiments.csv',
97
+ )
98
+
99
+
100
  else:
101
  st.write("Please upload a CSV file.")