segestic commited on
Commit
ce29745
·
1 Parent(s): 857723c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -39,7 +39,7 @@ def paraphraze(text, how_many=1):
39
  paraphrase.append(a)
40
  paraphrase2 = [' '.join(x) for x in paraphrase]
41
  paraphrase3 = [' '.join(x for x in paraphrase2) ]
42
- paraphrased_text = str(paraphrase3).strip('[]').strip("'")
43
  return paraphrased_text
44
 
45
 
@@ -49,23 +49,23 @@ def summarize(text):
49
  return paraphrased_text
50
  ########################################################################################################
51
 
52
- # from transformers import *
53
 
54
- # model = PegasusForConditionalGeneration.from_pretrained("tuner007/pegasus_paraphrase")
55
- # tokenizer = PegasusTokenizerFast.from_pretrained("tuner007/pegasus_paraphrase")
56
 
57
 
58
- # def get_paraphrased_sentences(model, tokenizer, sentence, num_return_sequences=5, num_beams=5):
59
- # # tokenize the text to be form of a list of token IDs
60
- # inputs = tokenizer([sentence], truncation=False, padding="longest", return_tensors="pt")
61
- # # generate the paraphrased sentences
62
- # outputs = model.generate(
63
- # **inputs,
64
- # num_beams=num_beams,
65
- # num_return_sequences=num_return_sequences,
66
- # )
67
- # # decode the generated sentences using the tokenizer to get them back to text
68
- # return tokenizer.batch_decode(outputs, skip_special_tokens=True)
69
 
70
 
71
 
@@ -81,11 +81,16 @@ def app():
81
  user_input = st.text_area('Enter text','', height=200)
82
 
83
  paraphraseNo = st.slider('Number of Parapharases',1,10,2)
84
- if st.button('Paraphrase'):
85
  with st.spinner(text="This may take a moment..."):
86
- #output = get_paraphrased_sentences(model, tokenizer, user_input, num_beams=10, num_return_sequences=paraphraseNo)
87
- output = summarize(user_input)
88
-
 
 
 
 
 
89
  #with spacer:
90
 
91
  with col2:
 
39
  paraphrase.append(a)
40
  paraphrase2 = [' '.join(x) for x in paraphrase]
41
  paraphrase3 = [' '.join(x for x in paraphrase2) ]
42
+ paraphrased_text = paraphrase #str(paraphrase3).strip('[]').strip("'")
43
  return paraphrased_text
44
 
45
 
 
49
  return paraphrased_text
50
  ########################################################################################################
51
 
52
+ from transformers import *
53
 
54
+ model = PegasusForConditionalGeneration.from_pretrained("tuner007/pegasus_paraphrase")
55
+ tokenizer = PegasusTokenizerFast.from_pretrained("tuner007/pegasus_paraphrase")
56
 
57
 
58
+ def get_paraphrased_sentences(model, tokenizer, sentence, num_return_sequences=5, num_beams=5):
59
+ # tokenize the text to be form of a list of token IDs
60
+ inputs = tokenizer([sentence], truncation=False, padding="longest", return_tensors="pt")
61
+ # generate the paraphrased sentences
62
+ outputs = model.generate(
63
+ **inputs,
64
+ num_beams=num_beams,
65
+ num_return_sequences=num_return_sequences,
66
+ )
67
+ # decode the generated sentences using the tokenizer to get them back to text
68
+ return tokenizer.batch_decode(outputs, skip_special_tokens=True)
69
 
70
 
71
 
 
81
  user_input = st.text_area('Enter text','', height=200)
82
 
83
  paraphraseNo = st.slider('Number of Parapharases',1,10,2)
84
+ if st.button('Single-Paraphrase'):
85
  with st.spinner(text="This may take a moment..."):
86
+ output = summarize(user_input)
87
+
88
+ if st.button('Multiple-Paraphrase'):
89
+ with st.spinner(text="This may take a moment..."):
90
+ output = get_paraphrased_sentences(model, tokenizer, user_input, num_beams=10, num_return_sequences=paraphraseNo)
91
+
92
+
93
+
94
  #with spacer:
95
 
96
  with col2: