Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
from sklearn.feature_extraction.text import CountVectorizer | |
from transformers import pipeline | |
from bertopic import BERTopic | |
# Emotion classification pipeline (can use AraBERT or any emotion classifier) | |
emotion_classifier = pipeline("text-classification", model="arpanghoshal/bert-base-uncased-emotion") | |
# Function to process CSV file and return emotion and topic model | |
def process_file(uploaded_file): | |
# Load CSV | |
df = pd.read_csv(uploaded_file) | |
# Display basic info about the CSV | |
st.write("CSV Loaded Successfully!") | |
st.write(f"Data Preview: {df.head()}") | |
# Preprocess the text: assuming the CSV has a 'text' column | |
texts = df['text'].dropna().tolist() # Modify this according to your column name | |
# Emotion Classification: Classify emotions for each text | |
emotions = [emotion_classifier(text)[0]['label'] for text in texts] | |
df['emotion'] = emotions | |
# Topic Modeling using BERTopic (install bertopic first if not installed) | |
topic_model = BERTopic() | |
topics, _ = topic_model.fit_transform(texts) | |
df['topic'] = topics | |
# Display the results | |
st.write("Emotions classified for each entry:") | |
st.write(df[['text', 'emotion', 'topic']]) | |
return df | |
# Streamlit App | |
st.title("Topic Modeling & Emotion Classification") | |
st.write("Upload a CSV file to perform topic modeling and emotion classification on the text.") | |
# File upload widget | |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"]) | |
if uploaded_file is not None: | |
# Process the file | |
result_df = process_file(uploaded_file) | |