Jaehan commited on
Commit
1f91fcf
1 Parent(s): 0d8ac20

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
2
+ import gradio as gr
3
+
4
+ model_name = "t5-small"
5
+ text2text_tokenizer = T5Tokenizer.from_pretrained(model_name)
6
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
7
+
8
+ def text2text_sentiment(text):
9
+ input = "Sentiment analysis for this sentence:" + text
10
+ encoded = text2text_tokenizer(input, return_tensors="pt")
11
+ tokens = model.generate(**encoded)
12
+ response = text2text_tokenizer.batch_decode(tokens)
13
+ return response
14
+
15
+ in_para = gr.Textbox(lines=1, label="English text", placeholder="Text in English")
16
+ out = gr.Textbox(lines=1, label="Sentiment")
17
+
18
+ gr.Interface(text2text_sentiment, inputs=in_para, outputs=out)