import streamlit as st import pandas as pd from transformers import pipeline from collections import Counter model = pipeline('text-classification', model='SentimentAnalysis') st.title("Sentiment Analysis") uploaded_file = st.file_uploader('Upload CSV file', type='csv') def get_predictions(filename): try: df = pd.read_csv(filename) first_hu = df.head(1000) if 'text' not in df.columns: st.error("The uploaded CSV must contain a 'text' column.") return with st.spinner("Generating predictions..."): predictions = [] for text in first_hu['text']: output = model(text) if output[0]["score"]>=0.50 and output[0]['score']<=0.60 and output[0]['label']=="LABEL_1": predictions.append('Neutral') elif output[0]['score']>0.60 and output[0]['label']=="LABEL_1": predictions.append('Positive') else: predictions.append('Negative') sentiment_counts = Counter(predictions) sentiment_df = pd.DataFrame.from_dict(sentiment_counts, orient='index', columns=['Count']) st.bar_chart(sentiment_df) st.success("Predictions generated successfully!") except Exception as e: st.error(f"An error occurred: {str(e)}") if uploaded_file is not None: get_predictions(uploaded_file)