bixentemal commited on
Commit
53ca93c
1 Parent(s): bebff77

paraphrasing task T5

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -2,12 +2,15 @@ from transformers import T5ForConditionalGeneration, T5Tokenizer
2
  import gradio as grad
3
  text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
4
  mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
5
- def text2text_sentiment(text):
6
- inp = "cola sentence: "+text
7
- enc = text2text_tkn(inp, return_tensors="pt")
 
 
8
  tokens = mdl.generate(**enc)
9
  response=text2text_tkn.batch_decode(tokens)
10
  return response
11
- para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
12
- out=grad.Textbox(lines=1, label="Sentiment")
13
- grad.Interface(text2text_sentiment, inputs=para, outputs=out).launch()
 
 
2
  import gradio as grad
3
  text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
4
  mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
5
+ def text2text_paraphrase(sentence1,sentence2):
6
+ inp1 = "mrpc sentence1: "+sentence1
7
+ inp2 = "sentence2: "+sentence2
8
+ combined_inp=inp1+" "+inp2
9
+ enc = text2text_tkn(combined_inp, return_tensors="pt")
10
  tokens = mdl.generate(**enc)
11
  response=text2text_tkn.batch_decode(tokens)
12
  return response
13
+ sent1=grad.Textbox(lines=1, label="Sentence1", placeholder="Text in English")
14
+ sent2=grad.Textbox(lines=1, label="Sentence2", placeholder="Text in English")
15
+ out=grad.Textbox(lines=1, label="Whether the sentence is acceptable or not")
16
+ grad.Interface(text2text_paraphrase, inputs=[sent1,sent2], outputs=out).launch()