amitkayal imseldrith commited on
Commit
04018cb
β€’
0 Parent(s):

Duplicate from imseldrith/Article-Rewriter

Browse files

Co-authored-by: Ashiq Hussain <[email protected]>

Files changed (4) hide show
  1. .gitattributes +31 -0
  2. README.md +13 -0
  3. app.py +37 -0
  4. requirements.txt +5 -0
.gitattributes ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zst filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Article Rewriter
3
+ emoji: πŸ“‰
4
+ colorFrom: indigo
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.4.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: imseldrith/Article-Rewriter
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import PegasusForConditionalGeneration, PegasusTokenizer
3
+
4
+ model_name = 'tuner007/pegasus_paraphrase'
5
+ torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
6
+ tokenizer = PegasusTokenizer.from_pretrained(model_name)
7
+ model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
8
+
9
+ def get_response(input_text,num_return_sequences):
10
+ batch = tokenizer.prepare_seq2seq_batch([input_text],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
11
+ translated = model.generate(**batch,max_length=60,num_beams=10, num_return_sequences=num_return_sequences, temperature=1.5)
12
+ tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
13
+ return tgt_text
14
+
15
+ from sentence_splitter import SentenceSplitter, split_text_into_sentences
16
+
17
+ splitter = SentenceSplitter(language='en')
18
+
19
+ def paraphraze(text):
20
+ sentence_list = splitter.split(text)
21
+ paraphrase = []
22
+
23
+ for i in sentence_list:
24
+ a = get_response(i,1)
25
+ paraphrase.append(a)
26
+ paraphrase2 = [' '.join(x) for x in paraphrase]
27
+ paraphrase3 = [' '.join(x for x in paraphrase2) ]
28
+ paraphrased_text = str(paraphrase3).strip('[]').strip("'")
29
+ return paraphrased_text
30
+
31
+ import gradio as gr
32
+ def summarize(text):
33
+
34
+ paraphrased_text = paraphraze(text)
35
+ return paraphrased_text
36
+ gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=7, placeholder="Enter text here"), outputs=[gr.outputs.Textbox(label="Paraphrased Text")],examples=[["This Api is the best quillbot api alternative with no words limit."
37
+ ]]).launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ sentence-splitter
4
+ SentencePiece
5
+ yake