File size: 1,056 Bytes
bb74ac5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

model_id = "GV05/distilbert-base-uncased-finetuned-emotion"
classifier = pipeline("text-classification", model=model_id)

label_to_emotion = {
    'LABEL_0': 'sadness',
    'LABEL_1': 'joy',
    'LABEL_2': 'love',
    'LABEL_3': 'anger',
    'LABEL_4': 'fear',
    'LABEL_5': 'surprise',
}

def classify_emotion(text):
    preds = classifier(text, return_all_scores=True)
    res = {}
    for x in preds[0]:
        res[label_to_emotion[x['label']]] = x['score']
    return res

image = gr.Textbox()
label = gr.Label()
examples = ["you are not too sensitive. you are not overreacting",
            "Thinking of you keeps me awake. Dreaming of you keeps me asleep. Being with you keeps me alive."]

title = "Emotion Detector"
description = "This model is a fine-tuned version of distilbert-base-uncased on the emotion dataset"

intf = gr.Interface(fn=classify_emotion, inputs=image, outputs=label, examples=examples, title=title,
                    description=description)

intf.launch(inline=False)