Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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()
|