Spaces:
Sleeping
Sleeping
Arius XI
commited on
Commit
·
501e0f9
1
Parent(s):
6e1930a
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 2 |
+
import gradio as grad
|
| 3 |
+
|
| 4 |
+
text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
|
| 5 |
+
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")
|
| 6 |
+
|
| 7 |
+
def text2text_paraphrase(sentence1,sentence2):
|
| 8 |
+
inp1 = "mrpc sentence1: "+sentence1
|
| 9 |
+
inp2 = "sentence2: "+sentence2
|
| 10 |
+
combined_inp=inp1+" "+inp2
|
| 11 |
+
enc = text2text_tkn(combined_inp, return_tensors="pt")
|
| 12 |
+
tokens = mdl.generate(**enc)
|
| 13 |
+
response=text2text_tkn.batch_decode(tokens)
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
sent1=grad.Textbox(lines=1, label="Sentence1",placeholder="Text in English")
|
| 17 |
+
sent2=grad.Textbox(lines=1, label="Sentence2",placeholder="Text in English")
|
| 18 |
+
|
| 19 |
+
out=grad.Textbox(lines=1, label="Whether the sentence is acceptable or not")
|
| 20 |
+
|
| 21 |
+
grad.Interface(text2text_paraphrase, inputs=[sent1,sent2],outputs=out).launch()
|