sashtech commited on
Commit
c35eed6
·
verified ·
1 Parent(s): 59b2b8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -22
app.py CHANGED
@@ -169,7 +169,7 @@ def correct_spelling(text):
169
  corrected_words.append(corrected_word)
170
  return ' '.join(corrected_words)
171
 
172
- # Function to rephrase text and replace words with synonyms while maintaining form
173
  def rephrase_with_synonyms(text):
174
  doc = nlp(text)
175
  rephrased_text = []
@@ -186,17 +186,21 @@ def rephrase_with_synonyms(text):
186
  pos_tag = wordnet.ADV
187
 
188
  if pos_tag:
189
- synonym = get_synonym(token.text, pos_tag)
190
- if token.pos_ == "VERB":
191
- if token.morph.get("Tense") == "Past":
192
- synonym = synonym + 'ed'
193
- elif token.tag_ == "VBG": # Present participle
194
- synonym = synonym + 'ing'
195
- elif token.tag_ == "VBZ": # Third-person singular present
196
- synonym = synonym + 's'
197
- elif token.pos_ == "NOUN" and token.tag_ == "NNS": # Plural nouns
198
- synonym += 's' if not synonym.endswith('s') else ""
199
- rephrased_text.append(synonym)
 
 
 
 
200
  else:
201
  rephrased_text.append(token.text)
202
 
@@ -230,15 +234,14 @@ with gr.Blocks() as demo:
230
  score1 = gr.Textbox(lines=1, label='Prob')
231
 
232
  # Connect the prediction function to the button
233
- button1.click(predict_en, inputs=[t1], outputs=[label1, score1], api_name='predict_en')
234
-
235
- with gr.Tab("Humanifier"):
236
- text_input = gr.Textbox(lines=5, label="Input Text")
237
- paraphrase_button = gr.Button("Paraphrase & Correct")
238
- result_output = gr.Textbox(lines=10, label="Humanified Text")
239
 
240
- # Connect the paraphrasing function to the button
241
- paraphrase_button.click(paraphrase_and_correct, inputs=[text_input], outputs=[result_output])
242
 
243
- # Launch the app
244
- demo.launch()
 
169
  corrected_words.append(corrected_word)
170
  return ' '.join(corrected_words)
171
 
172
+ # Function to rephrase text and replace words with their synonyms while maintaining form
173
  def rephrase_with_synonyms(text):
174
  doc = nlp(text)
175
  rephrased_text = []
 
186
  pos_tag = wordnet.ADV
187
 
188
  if pos_tag:
189
+ synonyms = get_synonyms_nltk(token.text, pos_tag)
190
+ if synonyms:
191
+ synonym = synonyms[0] # Just using the first synonym for simplicity
192
+ if token.pos_ == "VERB":
193
+ if token.tag_ == "VBG": # Present participle (e.g., running)
194
+ synonym = synonym + 'ing'
195
+ elif token.tag_ == "VBD" or token.tag_ == "VBN": # Past tense or past participle
196
+ synonym = synonym + 'ed'
197
+ elif token.tag_ == "VBZ": # Third-person singular present
198
+ synonym = synonym + 's'
199
+ elif token.pos_ == "NOUN" and token.tag_ == "NNS": # Plural nouns
200
+ synonym += 's' if not synonym.endswith('s') else ""
201
+ rephrased_text.append(synonym)
202
+ else:
203
+ rephrased_text.append(token.text)
204
  else:
205
  rephrased_text.append(token.text)
206
 
 
234
  score1 = gr.Textbox(lines=1, label='Prob')
235
 
236
  # Connect the prediction function to the button
237
+ button1.click(fn=predict_en, inputs=t1, outputs=[label1, score1])
238
+
239
+ with gr.Tab("Paraphrasing & Grammar Correction"):
240
+ t2 = gr.Textbox(lines=5, label='Enter text for paraphrasing and grammar correction')
241
+ button2 = gr.Button("🔄 Paraphrase and Correct")
242
+ result2 = gr.Textbox(lines=5, label='Corrected Text')
243
 
244
+ # Connect the paraphrasing and correction function to the button
245
+ button2.click(fn=paraphrase_and_correct, inputs=t2, outputs=result2)
246
 
247
+ demo.launch(share=True) # Share=True to create a public link