File size: 1,292 Bytes
b06040d
 
 
971c80c
b06040d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# required imports
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# loading the model from the repository
REPO_ID = "adith-ds/deberta-classifier-v1"
tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
model = AutoModelForSequenceClassification.from_pretrained(REPO_ID)

# denoting the labels
LABEL_COLUMNS = ['anger', 'fear', 'joy', 'sadness', 'surprise']

#helper function to make a prediction using the model
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)}

# gradio configuration stuff
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. "]
    ]
)

# running the application
demo.launch()