Spaces:
Sleeping
Sleeping
Create App.py
Browse files
App.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model = AutoModelForSequenceClassification.from_pretrained("vangmayy/emotion")
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("vangmayy/emotion")
|
6 |
+
labels = ["sadness", "Joy", "love", "anger", "fear", "surprise"]
|
7 |
+
label_map={
|
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 |
+
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, device=0)
|
16 |
+
|
17 |
+
def run_inference(text):
|
18 |
+
emotion = label_map[pipe(text)[0]['label']]
|
19 |
+
return "Emotion detected: " + emotion
|
20 |
+
|
21 |
+
intf = gr.Interface(fn = run_inference, inputs =["text"], outputs = ["text"], examples = ["Woah this is so cool", "I feel sad about what happened", "That room is so dark! I am not going inside"])
|
22 |
+
intf.launch()
|