Spaces:
Runtime error
Runtime error
inclusive-ml
commited on
Commit
•
4d7061c
1
Parent(s):
a8a6883
initial commit
Browse files- app.py +32 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
#print ("device ",device)
|
8 |
+
model = model.to(device)# Diverse Beam search
|
9 |
+
#print ("\n\n")
|
10 |
+
#print ("Original: ",context)
|
11 |
+
|
12 |
+
def generate_text(inp):
|
13 |
+
context = inp
|
14 |
+
text = "paraphrase: "+context + " </s>"
|
15 |
+
encoding = tokenizer.encode_plus(text,max_length =128, padding=True, return_tensors="pt")
|
16 |
+
input_ids,attention_mask = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
|
17 |
+
model.eval()
|
18 |
+
diverse_beam_outputs = model.generate(
|
19 |
+
input_ids=input_ids,attention_mask=attention_mask,
|
20 |
+
max_length=128,
|
21 |
+
early_stopping=True,
|
22 |
+
num_beams=5,
|
23 |
+
num_beam_groups = 5,
|
24 |
+
num_return_sequences=5,
|
25 |
+
diversity_penalty = 0.70)
|
26 |
+
|
27 |
+
sent = tokenizer.decode(diverse_beam_outputs[0], skip_special_tokens=True,clean_up_tokenization_spaces=True)
|
28 |
+
return sent
|
29 |
+
|
30 |
+
|
31 |
+
output_text = gr.outputs.Textbox()
|
32 |
+
gr.Interface(generate_text,"textbox", output_text).launch(inline=False)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
sentencepiece
|
3 |
+
torch
|