Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,16 +34,20 @@ autocomplete_embeddings = model.encode(autocomplete_data, convert_to_tensor=True
|
|
| 34 |
def find_synonym(word, top_n=1):
|
| 35 |
query_embedding = model.encode(word, convert_to_tensor=True)
|
| 36 |
results = util.semantic_search(query_embedding, autocomplete_embeddings, top_k=top_n)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Function to correct spellings
|
| 40 |
def correct_spelling(word):
|
| 41 |
-
matches = process.extract(word, autocomplete_data, scorer=fuzz.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
score = matches[0]
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
# Autocomplete function with tracking
|
| 49 |
def autocomplete(query):
|
|
|
|
| 34 |
def find_synonym(word, top_n=1):
|
| 35 |
query_embedding = model.encode(word, convert_to_tensor=True)
|
| 36 |
results = util.semantic_search(query_embedding, autocomplete_embeddings, top_k=top_n)
|
| 37 |
+
|
| 38 |
+
if results[0]:
|
| 39 |
+
return [autocomplete_data[result['corpus_id']] for result in results[0] if result['score'] > 0.6] # Only return synonyms with good confidence
|
| 40 |
+
return [word] # Return original word if no synonym is found
|
| 41 |
|
| 42 |
# Function to correct spellings
|
| 43 |
def correct_spelling(word):
|
| 44 |
+
matches = process.extract(word, autocomplete_data, scorer=fuzz.partial_ratio, limit=3)
|
| 45 |
+
|
| 46 |
+
if matches:
|
| 47 |
+
best_match, score, _ = matches[0] # Extract the best match string & score
|
| 48 |
+
if score > 70: # Lowered threshold to allow for more typo tolerance
|
| 49 |
+
return best_match
|
| 50 |
+
return word # Return the original word if no good match is found
|
| 51 |
|
| 52 |
# Autocomplete function with tracking
|
| 53 |
def autocomplete(query):
|