Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
model_name = "ramsrigouthamg/t5_paraphraser"
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 7 |
+
|
| 8 |
+
def paraphrase_text(text):
|
| 9 |
+
input_text = "paraphrase: " + text + " </s>"
|
| 10 |
+
encoding = tokenizer.encode_plus(
|
| 11 |
+
input_text, padding="max_length", return_tensors="pt", max_length=256, truncation=True
|
| 12 |
+
)
|
| 13 |
+
outputs = model.generate(
|
| 14 |
+
input_ids=encoding["input_ids"],
|
| 15 |
+
attention_mask=encoding["attention_mask"],
|
| 16 |
+
max_length=256,
|
| 17 |
+
num_return_sequences=1,
|
| 18 |
+
temperature=1.5,
|
| 19 |
+
)
|
| 20 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(fn=paraphrase_text, inputs="text", outputs="text", title="Free Paraphraser")
|
| 23 |
+
demo.launch()
|