Jaehan's picture
Create app.py
1f91fcf
raw
history blame
695 Bytes
from transformers import T5ForConditionalGeneration, T5Tokenizer
import gradio as gr
model_name = "t5-small"
text2text_tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
def text2text_sentiment(text):
input = "Sentiment analysis for this sentence:" + text
encoded = text2text_tokenizer(input, return_tensors="pt")
tokens = model.generate(**encoded)
response = text2text_tokenizer.batch_decode(tokens)
return response
in_para = gr.Textbox(lines=1, label="English text", placeholder="Text in English")
out = gr.Textbox(lines=1, label="Sentiment")
gr.Interface(text2text_sentiment, inputs=in_para, outputs=out)