Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,23 +25,15 @@ def autocomplete(query):
|
|
25 |
matches = process.extract(query, data, scorer=fuzz.partial_ratio, limit=5)
|
26 |
return "\n".join([match[0] for match in matches]) # Return matches as a multi-line string
|
27 |
|
28 |
-
# Semantic search function
|
29 |
-
def semantic_search(query):
|
30 |
-
if not query.strip():
|
31 |
-
return [] # Return empty if query is blank
|
32 |
-
query_embedding = model.encode(query, convert_to_tensor=True)
|
33 |
-
results = util.semantic_search(query_embedding, embeddings, top_k=5)
|
34 |
-
return [data[result['corpus_id']] for result in results[0]]
|
35 |
-
|
36 |
# Gradio interface
|
37 |
with gr.Blocks() as demo:
|
38 |
-
gr.Markdown("### Typo-Tolerant Autocomplete
|
39 |
|
40 |
-
#
|
41 |
-
query = gr.Textbox(label="Start typing for autocomplete"
|
42 |
autocomplete_output = gr.Textbox(label="Autocomplete Suggestions", lines=5)
|
43 |
|
44 |
-
#
|
45 |
-
query.
|
46 |
|
47 |
demo.launch()
|
|
|
25 |
matches = process.extract(query, data, scorer=fuzz.partial_ratio, limit=5)
|
26 |
return "\n".join([match[0] for match in matches]) # Return matches as a multi-line string
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# Gradio interface
|
29 |
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("### Typo-Tolerant Autocomplete")
|
31 |
|
32 |
+
# Create a Textbox without live=True
|
33 |
+
query = gr.Textbox(label="Start typing for autocomplete")
|
34 |
autocomplete_output = gr.Textbox(label="Autocomplete Suggestions", lines=5)
|
35 |
|
36 |
+
# Trigger autocomplete on input submission
|
37 |
+
query.submit(fn=autocomplete, inputs=query, outputs=autocomplete_output)
|
38 |
|
39 |
demo.launch()
|