ravijoe commited on
Commit
fbdb406
1 Parent(s): 734fec5

Create app.py

Browse files

main file responsible for launching and building app

Files changed (1) hide show
  1. app.py +14 -0
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