Spaces:
Running
Running
File size: 1,175 Bytes
5e0dcc9 |
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 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
from transformers import pipeline
# 1) Load the HF pipeline with all scores so we can show probabilities
classifier = pipeline(
"text-classification",
model="j-hartmann/emotion-english-roberta-large",
return_all_scores=True
)
# 2) Wrap it in a function that returns a label→score dict
def classify_emotion(text: str):
scores = classifier(text)[0] # returns list of {label, score}
return {item["label"]: float(item["score"]) for item in scores}
# 3) Build the Gradio interface
iface = gr.Interface(
fn=classify_emotion,
inputs=gr.Textbox(
lines=2,
placeholder="Type any English sentence here…",
label="Input Text"
),
outputs=gr.Label(
num_top_classes=6,
label="Emotion Probabilities"
),
examples=[
["I love you!"],
["The movie was heart breaking!"]
],
title="English Emotion Classifier",
description=(
"Predicts one of Ekman's 6 basic emotions plus neutral "
"(anger 🤬, disgust 🤢, fear 😨, joy 😀, neutral 😐, "
"sadness 😭, surprise 😲)."
)
)
if __name__ == "__main__":
iface.launch()
|