Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -148,19 +148,18 @@ def correct_spelling(text):
|
|
148 |
def replace_with_synonyms(text):
|
149 |
doc = nlp(text)
|
150 |
replaced_words = []
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
157 |
if relevant_synonyms:
|
158 |
-
# Randomly choose a synonym from the
|
159 |
-
synonym = random.choice(relevant_synonyms)
|
160 |
-
|
161 |
-
|
162 |
-
else:
|
163 |
-
replaced_words.append(token.text)
|
164 |
else:
|
165 |
replaced_words.append(token.text) # No relevant synonym found
|
166 |
else:
|
|
|
148 |
def replace_with_synonyms(text):
|
149 |
doc = nlp(text)
|
150 |
replaced_words = []
|
151 |
+
|
152 |
+
for index, token in enumerate(doc):
|
153 |
+
# Replace every 2nd and 4th word
|
154 |
+
if (index + 1) % 2 == 0 or (index + 1) % 4 == 0:
|
155 |
+
# Check if the token has synonyms in the dictionary
|
156 |
+
if token.text in synonyms_dict:
|
157 |
+
relevant_synonyms = synonyms_dict[token.text]
|
158 |
if relevant_synonyms:
|
159 |
+
# Randomly choose a synonym from the available options
|
160 |
+
synonym = random.choice(relevant_synonyms)
|
161 |
+
# Add the synonym instead of the original word
|
162 |
+
replaced_words.append(synonym)
|
|
|
|
|
163 |
else:
|
164 |
replaced_words.append(token.text) # No relevant synonym found
|
165 |
else:
|