FahadAlam commited on
Commit
36f8039
1 Parent(s): a1ff5a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -1,20 +1,14 @@
1
- import gradio as gr
2
  import torch
3
- from transformers import PegasusForConditionalGeneration, PegasusTokenizer
4
 
5
- model_name = 'tuner007/pegasus_paraphrase'
6
- torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
7
- tokenizer = PegasusTokenizer.from_pretrained(model_name)
8
- model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
9
-
10
- def paraphrase_text(input_text, max_length):
11
- batch = tokenizer([input_text],truncation=True,padding='longest',max_length=int(max_length), return_tensors="pt").to(torch_device)
12
- translated = model.generate(**batch,max_length=int(max_length),num_beams=3, num_return_sequences=3, temperature=1.5)
13
- tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
14
- return tgt_text[0], tgt_text[1], tgt_text[2]
15
 
 
 
 
 
16
 
17
  examples = [["Begin your professional career by learning data science skills with Data science Dojo, a globally recognized e-learning platform where we teach students how to learn data science, data analytics, machine learning and more.", "45"], ["Hello, I am a paraphrasing tool. How can I help you?", "30"]]
18
 
19
- demo = gr.Interface(fn=paraphrase_text, inputs=["text", "text"], outputs=["text", "text", "text"], title="Paraphrase", examples=examples)
20
  demo.launch( debug = True )
 
1
+ from parrot import Parrot
2
  import torch
 
3
 
4
+ parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=False)
 
 
 
 
 
 
 
 
 
5
 
6
+ def paraphrase_text(input_text):
7
+ para_phrases = parrot.augment(input_phrase=phrase,
8
+ max_return_phrases = 3)
9
+ return para_phrases[0][0], para_phrases[1][0] if para_phrases[1][0] else '' , para_phrases[2][0] if para_phrases[2][0] else ''
10
 
11
  examples = [["Begin your professional career by learning data science skills with Data science Dojo, a globally recognized e-learning platform where we teach students how to learn data science, data analytics, machine learning and more.", "45"], ["Hello, I am a paraphrasing tool. How can I help you?", "30"]]
12
 
13
+ demo = gr.Interface(fn=paraphrase_text, inputs="text", outputs=["text", "text", "text"], title="Paraphrase", examples=examples)
14
  demo.launch( debug = True )