adith-ds commited on
Commit
b06040d
·
verified ·
1 Parent(s): feb1fbc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # required imports
2
+ import gradio as gr
3
+ import torch
4
+ from transformer import AutoTokenizer, AutoModelForSequenceClassification
5
+
6
+ # loading the model from the repository
7
+ REPO_ID = "adith-ds/deberta-classifier-v1"
8
+ tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
9
+ model = AutoModelForSequenceClassification.from_pretrained(REPO_ID)
10
+
11
+ # denoting the labels
12
+ LABEL_COLUMNS = ['anger', 'fear', 'joy', 'sadness', 'surprise']
13
+
14
+ #helper function to make a prediction using the model
15
+ def predict(text):
16
+ input = tokenizer(text, return_tensors="pt")
17
+ with torch.no_grad():
18
+ outputs = model(**input)
19
+ logits = outputs.logits
20
+ probs = torch.sigmoid(logits)[0]
21
+ return {label: float(prob) for label, prob in zip(LABEL_COLUMNS, probs)}
22
+
23
+ # gradio configuration stuff
24
+ demo = gr.Interface(
25
+ fn=predict,
26
+ inputs=gr.Textbox(label="Enter your text here"),
27
+ outputs=gr.Label(num_top_classes=5, label="Emotions detected"),
28
+ title="Emotion Classifier (using finetuned DeBERTa)",
29
+ description="Classify your text into the following emotions: Anger, Fear, Joy, Sadness, Surprise",
30
+ examples=[
31
+ ["Yikes! What a scare."],
32
+ ["I hated this movie, it was so boring."],
33
+ ["Oh wow! The effects were incredible. "]
34
+ ]
35
+ )
36
+
37
+ # running the application
38
+ demo.launch()