File size: 1,135 Bytes
2dffec1 c499e4d 2dffec1 c499e4d 13054b8 c499e4d 13054b8 c499e4d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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()
|