Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,17 +63,20 @@ faq_questions = list(faq_data.keys())
|
|
| 63 |
faq_embeddings = model.encode(faq_questions, convert_to_tensor=True)
|
| 64 |
|
| 65 |
def chatbot(message, history):
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
if
|
| 74 |
-
|
|
|
|
| 75 |
else:
|
| 76 |
-
return "I'm still learning
|
| 77 |
|
| 78 |
iface = gr.ChatInterface(fn=chatbot, type="messages")
|
| 79 |
iface.launch(share=True)
|
|
|
|
| 63 |
faq_embeddings = model.encode(faq_questions, convert_to_tensor=True)
|
| 64 |
|
| 65 |
def chatbot(message, history):
|
| 66 |
+
# Convert input to lowercase for better matching
|
| 67 |
+
user_input = message.lower()
|
| 68 |
+
|
| 69 |
+
# Extract the list of questions
|
| 70 |
+
questions = list(faq_data.keys())
|
| 71 |
+
|
| 72 |
+
# Use difflib to find closest match
|
| 73 |
+
closest_match = difflib.get_close_matches(user_input, questions, n=1, cutoff=0.5)
|
| 74 |
|
| 75 |
+
if closest_match:
|
| 76 |
+
matched_question = closest_match[0]
|
| 77 |
+
return faq_data[matched_question]
|
| 78 |
else:
|
| 79 |
+
return "I'm still learning. Try asking about our services, support, cybersecurity, or backups."
|
| 80 |
|
| 81 |
iface = gr.ChatInterface(fn=chatbot, type="messages")
|
| 82 |
iface.launch(share=True)
|