DataWizard9742 commited on
Commit
29e2d3c
·
1 Parent(s): f30407a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from textblob import TextBlob
4
+
5
+
6
+ def load_data(csv_file):
7
+ df = pd.read_csv(csv_file)
8
+ return df
9
+
10
+
11
+ def convert_to_rating(sentiment):
12
+ if sentiment > 0:
13
+ return 5
14
+ elif sentiment == 0:
15
+ return 3
16
+ else:
17
+ return 1
18
+
19
+
20
+ def main():
21
+ st.title("Review to Rating Converter")
22
+
23
+ # Upload CSV file
24
+ uploaded_file = st.file_uploader("Upload a CSV file", type="csv")
25
+
26
+ if uploaded_file is not None:
27
+ # Load the CSV file
28
+ df = load_data(uploaded_file)
29
+
30
+ # Perform sentiment analysis and convert to ratings
31
+ df['Sentiment'] = df['Review'].apply(lambda x: TextBlob(x).sentiment.polarity)
32
+ df['Rating'] = df['Sentiment'].apply(convert_to_rating)
33
+
34
+ # Display the converted ratings
35
+ st.subheader("Converted Ratings:")
36
+ st.dataframe(df[['Review', 'Rating']])
37
+
38
+ # Download the converted ratings as CSV
39
+ st.download_button(
40
+ label="Download Converted Ratings",
41
+ data=df[['Review', 'Rating']].to_csv(index=False),
42
+ file_name="converted_ratings.csv",
43
+ mime="text/csv"
44
+ )
45
+
46
+
47
+ if __name__ == '__main__':
48
+ main()