GV05 commited on
Commit
bb74ac5
1 Parent(s): 8d1fbc7

push the app

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ model_id = "GV05/distilbert-base-uncased-finetuned-emotion"
5
+ classifier = pipeline("text-classification", model=model_id)
6
+
7
+ label_to_emotion = {
8
+ 'LABEL_0': 'sadness',
9
+ 'LABEL_1': 'joy',
10
+ 'LABEL_2': 'love',
11
+ 'LABEL_3': 'anger',
12
+ 'LABEL_4': 'fear',
13
+ 'LABEL_5': 'surprise',
14
+ }
15
+
16
+ def classify_emotion(text):
17
+ preds = classifier(text, return_all_scores=True)
18
+ res = {}
19
+ for x in preds[0]:
20
+ res[label_to_emotion[x['label']]] = x['score']
21
+ return res
22
+
23
+ image = gr.Textbox()
24
+ label = gr.Label()
25
+ examples = ["you are not too sensitive. you are not overreacting",
26
+ "Thinking of you keeps me awake. Dreaming of you keeps me asleep. Being with you keeps me alive."]
27
+
28
+ title = "Emotion Detector"
29
+ description = "This model is a fine-tuned version of distilbert-base-uncased on the emotion dataset"
30
+
31
+ intf = gr.Interface(fn=classify_emotion, inputs=image, outputs=label, examples=examples, title=title,
32
+ description=description)
33
+
34
+ intf.launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ gradio