File size: 1,633 Bytes
4b4bf72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)