Jaehan commited on
Commit
cc66336
·
1 Parent(s): 1f91fcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -2,17 +2,17 @@ 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)
 
2
  import gradio as gr
3
 
4
  model_name = "t5-small"
5
+ text2text_token= T5Tokenizer.from_pretrained(model_name)
6
  model = T5ForConditionalGeneration.from_pretrained(model_name)
7
 
8
  def text2text_sentiment(text):
9
+ input = "sst2 sentence: " + text
10
+ encoded = text2text_token(input, return_tensors="pt")
11
+ tokens = model.generate(**encoded)
12
+ response = text2text_token.batch_decode(tokens)
13
+ return response
14
 
15
+ # UX
16
+ in_para = gr.Textbox(lines=1, label="Input text in English", placeholder="Place your text in English...")
17
  out = gr.Textbox(lines=1, label="Sentiment")
18
+ grad.Interface(text2text_sentiment, inputs=in_para, outputs=out).launch()