YonasMersha's picture
Update app.py
1377c6b verified
raw
history blame contribute delete
805 Bytes
import gradio as gr
from transformers import pipeline
# Load the model and tokenizer from the same repository
classifier = pipeline(
"text-classification",
model="YonasMersha/fine-tuned-distilbert-emotion",
tokenizer="YonasMersha/fine-tuned-distilbert-emotion"
)
# Define the prediction function
def classify(text):
result = classifier(text)[0]
return result["label"]
# Create the Gradio interface
iface = gr.Interface(
fn=classify,
inputs=gr.Textbox(label="Enter a sentence", placeholder="e.g., I love this!"),
outputs=gr.Label(label="Predicted Emotion"),
title="Emotion Classifier",
description="Enter a sentence to classify its emotion (e.g., sadness, joy, love, anger, fear, surprise)."
)
# Launch the interface
if __name__ == "__main__":
iface.launch()