pushkarraj
commited on
Commit
·
bb88a84
1
Parent(s):
23af3dc
Delete app.py
Browse files
app.py
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
-
import os
|
4 |
-
import time
|
5 |
-
from transformers import pipeline,GPT2Tokenizer,OPTForCausalLM
|
6 |
-
|
7 |
-
model=OPTForCausalLM.from_pretrained('pushkarraj/pushkar_OPT_paraphaser')
|
8 |
-
tokenizer=GPT2Tokenizer.from_pretrained('pushkarraj/pushkar_OPT_paraphaser',truncation=True)
|
9 |
-
|
10 |
-
generator=pipeline("text-generation",model=model,tokenizer=tokenizer,device=0)
|
11 |
-
|
12 |
-
def cleaned_para(input_sentence):
|
13 |
-
p=generator('<s>'+input_sentence+ '</s>>>>><p>',do_sample=True,max_length=len(input_sentence.split(" "))+200,temperature = 0.8,repetition_penalty=1.2,top_p=0.4,top_k=1)
|
14 |
-
return p[0]['generated_text'].split('</s>>>>><p>')[1].split('</p>')[0]
|
15 |
-
|
16 |
-
from __future__ import unicode_literals, print_function
|
17 |
-
from spacy.lang.en import English # updated
|
18 |
-
|
19 |
-
def sentensizer(raw_text):
|
20 |
-
nlp = English()
|
21 |
-
nlp.add_pipe("sentencizer") # updated
|
22 |
-
doc = nlp(raw_text)
|
23 |
-
sentences = [sent for sent in doc.sents]
|
24 |
-
print(sentences)
|
25 |
-
return sentences
|
26 |
-
|
27 |
-
def paraphraser(text):
|
28 |
-
begin=time.time()
|
29 |
-
x=[cleaned_para(str(i)) for i in sentensizer(text)]
|
30 |
-
end=time.time()
|
31 |
-
return (".".join(x))
|
32 |
-
|
33 |
-
interface=gr.Interface(fn=paraphraser,inputs="text",outputs="text",title="Paraphraser")
|
34 |
-
|
35 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|