import pandas as pd import spacy import gradio as gr from nrclex import NRCLex from transformers import pipeline from rake_nltk import Rake import io import spacy.cli # Download the spaCy model spacy.cli.download("en_core_web_sm") # Initialize objects emotion_pipeline = pipeline('sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment') nlp = spacy.load('en_core_web_sm') rake = Rake() def process_csv(file): df = pd.read_csv(io.StringIO(file.decode('utf-8'))) emotions = [] sentiments = [] entities = [] keywords = [] for _, row in df.iterrows(): text = row['Content'] nrc_obj = NRCLex(text) emotion_scores = nrc_obj.affect_frequencies emotions.append(emotion_scores) sentiment = analyze_emotion(text) sentiments.append(sentiment) entities.append(analyze_entities(text)) keywords.append(extract_keywords(text)) df['emotions'] = emotions df['sentiment'] = sentiments df['entities'] = entities df['keywords'] = keywords return df.to_csv(index=False) def analyze_emotion(text): result = emotion_pipeline(text)[0] sentiment = result['label'] return sentiment def analyze_entities(text): doc = nlp(text) entities = [(ent.text, ent.label_) for ent in doc.ents] return entities def extract_keywords(text): rake.extract_keywords_from_text(text) return rake.get_ranked_phrases() iface = gr.Interface(fn=process_csv, inputs=gr.inputs.Textbox(lines=13, label="Paste CSV Here"), outputs="text") iface.launch()