Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
def paraphrase_text(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
top_p=0.95,
|
| 19 |
-
early_stopping=True
|
| 20 |
-
)
|
| 21 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
fn=paraphrase_text,
|
| 25 |
-
inputs=gr.Textbox(lines=
|
| 26 |
-
outputs=
|
| 27 |
-
title="AI Paraphraser
|
| 28 |
-
description="
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 3 |
|
| 4 |
+
# Load pretrained T5 model for paraphrasing
|
| 5 |
+
model_name = "Vamsi/T5_Paraphrase_Paws"
|
| 6 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 7 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
def paraphrase_text(input_text):
|
| 10 |
+
# Prepare input text
|
| 11 |
+
input_ids = tokenizer.encode("paraphrase: " + input_text + " </s>", return_tensors="pt", max_length=512, truncation=True)
|
| 12 |
+
|
| 13 |
+
# Generate paraphrase
|
| 14 |
+
outputs = model.generate(input_ids, max_length=256, num_return_sequences=1, temperature=1.5)
|
| 15 |
+
|
| 16 |
+
# Decode output
|
| 17 |
+
paraphrased_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return paraphrased_text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Create Gradio interface
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
fn=paraphrase_text,
|
| 23 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter text to paraphrase..."),
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="AI Paraphraser",
|
| 26 |
+
description="Paste any English text to get a paraphrased version using T5 model."
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Expose /run/predict endpoint
|
| 30 |
+
demo.launch()
|