Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 190 |
-
if
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 234 |
-
|
| 235 |
-
with gr.Tab("
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
|
| 240 |
-
# Connect the paraphrasing function to the button
|
| 241 |
-
|
| 242 |
|
| 243 |
-
#
|
| 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
|
|
|