Amitontheweb
commited on
Commit
·
7966d73
1
Parent(s):
ccb90bc
Paraphraser app code
Browse files
app.py
CHANGED
@@ -1,7 +1,59 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
+
#---------------------AI Paraphraser - iFrame code -----------------------------
|
2 |
+
# With direct model load
|
3 |
+
#----------------------------------------------------------------
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base")
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("humarin/chatgpt_paraphraser_on_T5_base")
|
10 |
+
|
11 |
+
def paraphrase(
|
12 |
+
question,
|
13 |
+
num_beams=5,
|
14 |
+
num_beam_groups=5,
|
15 |
+
num_return_sequences=5,
|
16 |
+
repetition_penalty=10.0,
|
17 |
+
diversity_penalty=3.0,
|
18 |
+
no_repeat_ngram_size=2,
|
19 |
+
temperature=0.7,
|
20 |
+
max_length=128
|
21 |
+
):
|
22 |
+
input_ids = tokenizer(
|
23 |
+
f'paraphrase: {question}',
|
24 |
+
return_tensors="pt", padding="longest",
|
25 |
+
max_length=max_length,
|
26 |
+
truncation=True,
|
27 |
+
).input_ids
|
28 |
+
|
29 |
+
outputs = model.generate(
|
30 |
+
input_ids, temperature=temperature, repetition_penalty=repetition_penalty,
|
31 |
+
num_return_sequences=num_return_sequences, no_repeat_ngram_size=no_repeat_ngram_size,
|
32 |
+
num_beams=num_beams, num_beam_groups=num_beam_groups,
|
33 |
+
max_length=max_length, diversity_penalty=diversity_penalty
|
34 |
+
)
|
35 |
+
|
36 |
+
res = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
37 |
+
res1 = res [0]
|
38 |
+
res2 = res [1]
|
39 |
+
res3 = res [3]
|
40 |
+
res4 = res [4]
|
41 |
+
|
42 |
+
return res1, res2, res3
|
43 |
+
|
44 |
+
|
45 |
+
iface = gr.Interface(fn=paraphrase,
|
46 |
+
inputs=["text"],
|
47 |
+
outputs=["text","text","text"],
|
48 |
+
title="AI Paraphraser",
|
49 |
+
description="Paste text in the input box and press 'Submit'. The output need not be better than the original.",
|
50 |
+
examples=[
|
51 |
+
["Therefore, when we share we need to create real hype for users to want to be involved."],
|
52 |
+
["Ideas like this I am open to your suggestions, so we can really push through."],
|
53 |
+
["The main goal is for readers/users to feel the need to purchase the product."],
|
54 |
+
["The weather is getting more and more unpredictable these days."],
|
55 |
+
],
|
56 |
+
cache_examples=True,
|
57 |
+
)
|
58 |
+
|
59 |
iface.launch()
|