daspartho commited on
Commit
1b28f25
β€’
1 Parent(s): d3a8a50

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, TextClassificationPipeline
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("daspartho/text-emotion")
5
+ model = AutoModelForSequenceClassification.from_pretrained("daspartho/text-emotion") # i've uploaded the model on HuggingFace :)
6
+
7
+ pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, top_k=6)
8
+
9
+ label_map={
10
+ 'LABEL_0':'πŸ™',
11
+ 'LABEL_1':'πŸ˜ƒ',
12
+ 'LABEL_2':'πŸ₯°',
13
+ 'LABEL_3':'😠',
14
+ 'LABEL_4':'😬',
15
+ 'LABEL_5':'😳'
16
+ }
17
+
18
+ def classify_text(text):
19
+ predictions = pipe(text)[0]
20
+ return {label_map[pred['label']]: float(pred['score']) for pred in predictions}
21
+
22
+ iface = gr.Interface(
23
+ title='Text Emotion',
24
+ description = "enter a text and the model will attempt to predict the emotion.",
25
+ article = "<p style='text-align: center'><a href='https://github.com/daspartho/text-emotion' target='_blank'>Github</a></p>",
26
+ fn=classify_text,
27
+ inputs=gr.inputs.Textbox(label="type the text here"),
28
+ outputs=gr.outputs.Label(label='what the model thinks'),
29
+ )
30
+ iface.launch()