StSAdmin commited on
Commit
a66405d
·
verified ·
1 Parent(s): 066718d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
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
- # Embed user message
67
- user_embedding = model.encode(message, convert_to_tensor=True)
68
- # Compute cosine similarity with FAQ questions
69
- scores = util.pytorch_cos_sim(user_embedding, faq_embeddings)[0]
70
- best_score_idx = scores.argmax().item()
71
- best_score = scores[best_score_idx]
 
 
72
 
73
- if best_score > 0.6: # adjust threshold if needed
74
- return faq_data[faq_questions[best_score_idx]]
 
75
  else:
76
- return "I'm still learning! Try asking about our services, support, or cybersecurity solutions."
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)