Spaces:
Runtime error
Runtime error
Commit
·
523d9cf
1
Parent(s):
93b6f05
app init
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
import time
|
5 |
+
import torch
|
6 |
+
from transformers import pipeline, GPT2Tokenizer, OPTForCausalLM
|
7 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
+
|
9 |
+
model=OPTForCausalLM.from_pretrained('pushkarraj/opt_paraphraser')
|
10 |
+
tokenizer=GPT2Tokenizer.from_pretrained('pushkarraj/opt_paraphraser',truncation=True)
|
11 |
+
|
12 |
+
generator=pipeline("text-generation",model=model,tokenizer=tokenizer,device=device)
|
13 |
+
|
14 |
+
def cleaned_para(input_sentence):
|
15 |
+
p=generator('<s>'+input_sentence+ '</s>>>>><p>',do_sample=True,max_length=len(input_sentence.split(" "))+200,temperature = 0.9,repetition_penalty=1.2)
|
16 |
+
return p[0]['generated_text'].split('</s>>>>><p>')[1].split('</p>')[0]
|
17 |
+
|
18 |
+
from spacy.lang.en import English # updated
|
19 |
+
|
20 |
+
def sentensizer(raw_text):
|
21 |
+
nlp = English()
|
22 |
+
nlp.add_pipe("sentencizer") # updated
|
23 |
+
doc = nlp(raw_text)
|
24 |
+
sentences = [sent for sent in doc.sents]
|
25 |
+
print(sentences)
|
26 |
+
return sentences
|
27 |
+
|
28 |
+
|
29 |
+
def paraphraser(text):
|
30 |
+
begin=time.time()
|
31 |
+
x=[cleaned_para(str(i)) for i in sentensizer(text)]
|
32 |
+
end=time.time()
|
33 |
+
return (".".join(x))
|
34 |
+
|
35 |
+
interface=gr.Interface(fn=paraphraser,inputs="text",outputs=["text"],title="Paraphraser",description="A paraphrasing tool to kill quillbot")
|
36 |
+
interface.launch()
|