Spaces:
Sleeping
Sleeping
| 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() |