Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
-
|
4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
model = AutoModelForSeq2SeqLM.from_pretrained("ramsrigouthamg/t5-large-paraphraser-diverse-high-quality")
|
6 |
tokenizer = AutoTokenizer.from_pretrained("ramsrigouthamg/t5-large-paraphraser-diverse-high-quality")
|
7 |
-
|
8 |
-
device = torch.device("
|
9 |
-
model = model.to(device)
|
10 |
-
|
11 |
def generate_text(inp):
|
12 |
-
text = "paraphrase: "+context + " </s>"
|
13 |
context = inp
|
14 |
-
|
15 |
-
|
|
|
16 |
model.eval()
|
17 |
-
|
18 |
-
input_ids=input_ids,
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
return sent
|
22 |
|
23 |
-
title = "Paraphraser One"
|
24 |
-
description = "Paraphrase means to express meaning using different words. Write or paste your text below, submit, and the machine will attempt to express your meaning using different words."
|
25 |
-
|
26 |
output_text = gr.outputs.Textbox()
|
27 |
-
gr.Interface(generate_text,
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
model = AutoModelForSeq2SeqLM.from_pretrained("ramsrigouthamg/t5-large-paraphraser-diverse-high-quality")
|
4 |
tokenizer = AutoTokenizer.from_pretrained("ramsrigouthamg/t5-large-paraphraser-diverse-high-quality")
|
5 |
+
import torch
|
6 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
+
model = model.to(device)# Diverse Beam search
|
|
|
8 |
def generate_text(inp):
|
|
|
9 |
context = inp
|
10 |
+
text = "paraphrase: "+context + " </s>"
|
11 |
+
encoding = tokenizer.encode_plus(text,max_length =128, padding=True, return_tensors="pt")
|
12 |
+
input_ids,attention_mask = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
|
13 |
model.eval()
|
14 |
+
diverse_beam_outputs = model.generate(
|
15 |
+
input_ids=input_ids,attention_mask=attention_mask,
|
16 |
+
max_length=128,
|
17 |
+
early_stopping=True,
|
18 |
+
num_beams=5,
|
19 |
+
num_beam_groups = 5,
|
20 |
+
num_return_sequences=5,
|
21 |
+
diversity_penalty = 0.70)
|
22 |
+
sent = tokenizer.decode(diverse_beam_outputs[0], skip_special_tokens=True,clean_up_tokenization_spaces=True)
|
23 |
return sent
|
24 |
|
|
|
|
|
|
|
25 |
output_text = gr.outputs.Textbox()
|
26 |
+
gr.Interface(generate_text,"textbox", output_text).launch(inline=False)
|