| |
| import gradio as gr |
| import torch |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
| |
| REPO_ID = "adith-ds/deberta-classifier-v1" |
| tokenizer = AutoTokenizer.from_pretrained(REPO_ID) |
| model = AutoModelForSequenceClassification.from_pretrained(REPO_ID) |
|
|
| |
| LABEL_COLUMNS = ['anger', 'fear', 'joy', 'sadness', 'surprise'] |
|
|
| |
| def predict(text): |
| input = tokenizer(text, return_tensors="pt") |
| with torch.no_grad(): |
| outputs = model(**input) |
| logits = outputs.logits |
| probs = torch.sigmoid(logits)[0] |
| return {label: float(prob) for label, prob in zip(LABEL_COLUMNS, probs)} |
|
|
| |
| demo = gr.Interface( |
| fn=predict, |
| inputs=gr.Textbox(label="Enter your text here"), |
| outputs=gr.Label(num_top_classes=5, label="Emotions detected"), |
| title="Emotion Classifier (using finetuned DeBERTa)", |
| description="Classify your text into the following emotions: Anger, Fear, Joy, Sadness, Surprise", |
| examples=[ |
| ["Yikes! What a scare."], |
| ["I hated this movie, it was so boring."], |
| ["Oh wow! The effects were incredible. "] |
| ] |
| ) |
|
|
| |
| demo.launch() |