Spaces:
Runtime error
Runtime error
new app file
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import DistilBertForSequenceClassification, DistilBertTokenizerFast
|
4 |
+
|
5 |
+
def translate(text):
|
6 |
+
model_name = 'sbenel/emotion-distilbert'
|
7 |
+
tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
|
8 |
+
model= DistilBertForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
input = tokenizer(text, return_tensors="pt")
|
11 |
+
labels = torch.tensor([1]).unsqueeze(0) # Batch size 1
|
12 |
+
output = model(**input, labels=labels)
|
13 |
+
# output = model.generate(input["input_ids"], max_length=40, num_beams=4, early_stopping=True)
|
14 |
+
|
15 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
16 |
+
|
17 |
+
title = "Text Emotion Classification"
|
18 |
+
inputs = gr.inputs.Textbox(lines=1, label="Text")
|
19 |
+
outputs = [gr.outputs.Textbox(label="Emotions")]
|
20 |
+
|
21 |
+
description = "Here use the [emotion-distilbert](https://huggingface.co/sbenel/emotion-distilbert) that was trained with [emotion dataset](https://huggingface.co/datasets/emotion)."
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=translate, inputs=inputs, outputs=outputs, theme="grass", title=title, description=description)
|
24 |
+
iface.launch(enable_queue=True)
|