Spaces:
Running
Running
Commit
·
690a42b
1
Parent(s):
8c9a81a
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,8 @@ torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
8 |
tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
9 |
model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
|
10 |
|
11 |
-
def paraphrase_text(input_text
|
|
|
12 |
batch = tokenizer.prepare_seq2seq_batch([input_text], truncation=True, padding='longest', max_length=60,
|
13 |
return_tensors="pt").to(torch_device)
|
14 |
translated = model.generate(**batch, max_length=60, num_beams=10, num_return_sequences=num_return_sequences,
|
@@ -16,7 +17,7 @@ def paraphrase_text(input_text, num_return_sequences = 3):
|
|
16 |
paraphrased_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
|
17 |
return paraphrased_text[0], paraphrased_text[1], paraphrased_text[2]
|
18 |
|
19 |
-
examples = [["Uploading a video to YouTube can help exposure for your business."
|
20 |
|
21 |
demo = gr.Interface(fn=paraphrase_text, inputs=gr.Textbox(lines=3, placeholder="Enter sample text here", label="Original text"), outputs=[gr.Textbox(label="Paraphrasing 1"), gr.Textbox(label="Paraphrasing 2"), gr.Textbox(label="Paraphrasing 3")], examples=examples)
|
22 |
demo.launch( debug = True )
|
|
|
8 |
tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
9 |
model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
|
10 |
|
11 |
+
def paraphrase_text(input_text):
|
12 |
+
num_return_sequences = 3
|
13 |
batch = tokenizer.prepare_seq2seq_batch([input_text], truncation=True, padding='longest', max_length=60,
|
14 |
return_tensors="pt").to(torch_device)
|
15 |
translated = model.generate(**batch, max_length=60, num_beams=10, num_return_sequences=num_return_sequences,
|
|
|
17 |
paraphrased_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
|
18 |
return paraphrased_text[0], paraphrased_text[1], paraphrased_text[2]
|
19 |
|
20 |
+
examples = [["Uploading a video to YouTube can help exposure for your business."], ["Niagara Falls is viewed by thousands of tourists every year."]]
|
21 |
|
22 |
demo = gr.Interface(fn=paraphrase_text, inputs=gr.Textbox(lines=3, placeholder="Enter sample text here", label="Original text"), outputs=[gr.Textbox(label="Paraphrasing 1"), gr.Textbox(label="Paraphrasing 2"), gr.Textbox(label="Paraphrasing 3")], examples=examples)
|
23 |
demo.launch( debug = True )
|