|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
classifier = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion") |
|
|
|
def classify_emotion(text): |
|
|
|
predictions = classifier(text) |
|
return {item["label"]: item["score"] for item in predictions} |
|
|
|
|
|
gr.Interface( |
|
fn=classify_emotion, |
|
inputs=gr.Textbox( |
|
placeholder="Enter text to analyze...", |
|
label="Input Text", |
|
lines=4 |
|
), |
|
outputs=gr.JSON(), |
|
title="Emotion Detection with DistilBERT", |
|
description="This app uses the DistilBERT model fine-tuned for emotion detection. Enter a piece of text to analyze its emotional content!", |
|
examples=[ |
|
"I am so happy to see you!", |
|
"I'm really angry about what happened.", |
|
"The sunset was absolutely beautiful today.", |
|
"I'm worried about the upcoming exam.", |
|
"Fear is the mind-killer. I will face my fear." |
|
] |
|
).launch() |
|
|