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