douglasgoodwin's picture
more involved
c499e4d verified
raw
history blame
1.14 kB
import gradio as gr
from transformers import pipeline
# Load the Hugging Face pipeline
classifier = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
def classify_emotion(text):
# Make predictions using the Hugging Face pipeline
predictions = classifier(text)
return {item["label"]: item["score"] for item in predictions}
# Create a custom Gradio interface with title, description, and examples
gr.Interface(
fn=classify_emotion,
inputs=gr.Textbox(
placeholder="Enter text to analyze...",
label="Input Text",
lines=4
),
outputs=gr.JSON(), # Display results in JSON format
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()