File size: 813 Bytes
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

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

learn = load_learner('nlp_model.pkl')

labels = learn.dls.vocab

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 {labels[i]: float(probs[i]) for i in range(len(labels))}


interface = gr.Interface(fn=classify_text,
                        inputs = gr.inputs.Texbox(placeholder="Enter Text here", label='Input text',lines=5)),
                        outputs=gr.outputs.Label(num_top_classes=4, label='Emotion inthe Text'),
                        verbose=True,
                        title="Emotion Classifier",
                        theme='soft')

interface.launch()