Spaces:
Runtime error
Runtime error
Create app.py
Browse filesmain file responsible for launching and building app
app.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion")
|
5 |
+
model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-emotion")
|
6 |
+
def get_emotion(text):
|
7 |
+
input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
|
8 |
+
output = model.generate(input_ids=input_ids,max_length=2)
|
9 |
+
dec = [tokenizer.decode(ids) for ids in output]
|
10 |
+
label = dec[0]
|
11 |
+
return label.split()[1]
|
12 |
+
|
13 |
+
iface = gr.Interface(fn=get_emotion, inputs=["textbox"], outputs="text").launch()
|
14 |
+
iface
|