Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("cude" if torch.cuda.is_available() else "cpu")
|
9 |
+
model = model.to(device)
|
10 |
+
|
11 |
+
def generate_text(inp):
|
12 |
+
text = "paraphrase: "+context + " </s>"
|
13 |
+
context = inp
|
14 |
+
encoding = tokenizer.encode_plus(text, max_length=256, padding=True, return_tensors="pt")
|
15 |
+
input_ids, attention_mask = encoding["input_ids"].to(device), encoding["attention_mask"].to(device_
|
16 |
+
model.eval()
|
17 |
+
diverse_beams_output = model.generate(
|
18 |
+
input_ids = input_ids, attention_mask = max_length=256, early_stopping = True, num_beams = 5, num_beam_groups = 5, num_return_sequences = 5, diversity_penalty = 0,70)
|
19 |
+
|
20 |
+
sent = tokenizer.decode(diverse_beams_outputs[0], skip_special_tokens = True, clean_up_tokenization_spaces = True)
|
21 |
+
return sent
|
22 |
+
|
23 |
+
output_text = gr.outputs.Textbox()
|
24 |
+
gr.Interface(generate_text, "textbox", output_text).launch(inline=False)
|