danielferreira's picture
Added emotion classification
fef0bcc
raw
history blame
756 Bytes
import gradio as gr
from transformers import pipeline
pipeline = pipeline("text-classification", model="bhadresh-savani/bert-base-uncased-emotion", return_all_scores=True)
def predict(input_text):
preds = pipeline(input_text)
pred= preds[0]
res = {"Sadness 😭": pred[0]["score"],
"Joy πŸ˜‚": pred[1]["score"],
"Love 😍": pred[2]["score"],
"Anger 😠": pred[3]["score"],
"Fear 😨": pred[4]["score"],
"Surprise 😲": pred[5]["score"],
}
return res
iface = gr.Interface(fn = predict,
inputs = "text",
outputs = gr.outputs.Label(num_top_classes=None, type="auto", label=None),
title = 'Sentiment Analysis')
iface.launch()