File size: 802 Bytes
f46ab08
 
 
 
 
 
 
a96facb
f46ab08
 
 
 
 
 
 
 
a96facb
f46ab08
7597d10
 
97df024
7597d10
 
 
 
97df024
7597d10
 
 
 
 
 
f46ab08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53

from fastai.text.all import*
import gradio as gr

learn = load_learner('nlp_model.pkl')

labels = learn.dls.vocab
emotion_labels = labels[1]

examples = ["I can't believe you lied to me again! This is unacceptable!",
            "Got a surprise gift today, feeling overjoyed!"]



def classify_text(text):
    pred,pred_idx,probs = learn.predict(text)
    return {emotion_labels[i]: float(probs[i]) for i in range(len(emotion_labels))}

interface = gr.Interface(
    fn=classify_text,
    inputs=gr.components.Textbox(
        placeholder="Enter Text here",
        label='Input text',
        lines=5
    ),
    outputs=gr.components.Label(
        num_top_classes=4,
        label='Emotion in the Text'
    ),
    title="Emotion Classifier",
    theme='soft'
)

interface.launch()