segestic commited on
Commit
d02bf04
·
1 Parent(s): bbc9b64

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
32
+ # def summarize(text):
33
+
34
+ # paraphrased_text = paraphraze(text)
35
+ # return paraphrased_text
36
+
37
+
38
+ import streamlit as st
39
+ from paraphraser import get_paraphrased_sentences, model, tokenizer
40
+
41
+
42
+ def app():
43
+ st.title('Paraphraser')
44
+ st.write('Please provide the text to be paraphrased')
45
+ col1, spacer, col2 = st.columns([3,1,3]) #st.beta_columns((2,1,1,1))
46
+
47
+ x = 0
48
+ output = ['Result ']
49
+ with col1:
50
+ user_input = st.text_area('Enter text','', height=200)
51
+
52
+ paraphraseNo = st.slider('Number of Parapharases',1,10,2)
53
+ if st.button('Paraphrase'):
54
+ with st.spinner(text="This may take a moment..."):
55
+ output = get_paraphrased_sentences(model, tokenizer, user_input, num_beams=10, num_return_sequences=paraphraseNo)
56
+
57
+ #with spacer:
58
+
59
+ with col2:
60
+ for x, element in enumerate(output):
61
+ user_output = st.text_area(label="", value=output[x], height=150 )