FirstEver / app.py
samiNCL
Update code to be 1 task only
3173d64
raw
history blame
744 Bytes
import pandas as pd
from transformers import pipeline
import gradio as gr
import io
# Initialize sentiment analysis pipeline
sentiment_pipeline = pipeline('sentiment-analysis')
def process_csv(file):
df = pd.read_csv(io.StringIO(file.decode('utf-8')))
sentiments = []
for _, row in df.iterrows():
text = row['Content']
sentiment = analyze_sentiment(text)
sentiments.append(sentiment)
df['sentiment'] = sentiments
return df.to_csv(index=False)
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0]
sentiment = result['label']
return sentiment
iface = gr.Interface(fn=process_csv, inputs=gr.inputs.Textbox(lines=13, label="Paste CSV Here"), outputs="text")
iface.launch()