|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
model_id = "Subhajit01/distilbert-base-uncased-finetuned-emotion" |
|
classifier = pipeline("text-classification", model=model_id) |
|
labels = ['sadness', 'joy', 'love', 'anger', 'fear', 'surprise'] |
|
|
|
def predict(text): |
|
max_prob_id = 0 |
|
max_prob = 0 |
|
preds = classifier(text, return_all_scores=True) |
|
for i in range(len(preds[0])): |
|
if (preds[0][i]["score"] > max_prob): |
|
max_prob = preds[0][i]["score"] |
|
max_prob_id = i |
|
return labels[max_prob_id] |
|
|
|
iface = gr.Interface(fn=predict, |
|
inputs="text", |
|
outputs="text", |
|
title="Sentiment Analyzer", |
|
description="Enter text to analyze its sentiment.") |
|
|
|
iface.launch(share= True) |