yusiqo commited on
Commit
c226acf
·
verified ·
1 Parent(s): b893cd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import nltk
2
  import streamlit as st
3
  from nltk.chat.util import Chat, reflections
 
4
 
5
  # Eğitim veri seti
6
  training_data = [
@@ -23,11 +24,15 @@ chatbot = train_bot(training_data)
23
  def run_chatbot():
24
  print("Merhaba! Benim adım ChatBot. Size nasıl yardımcı olabilirim? (Çıkış için 'çıkış' yazabilirsiniz)")
25
 
26
-
27
  user_input = st.text_area("Siz: ")
28
  if user_input:
29
- response = chatbot.respond(user_input)
30
- st.write("ChatBot: "+response)
 
 
 
 
 
31
 
32
  # Sohbet botunu başlat
33
  run_chatbot()
 
1
  import nltk
2
  import streamlit as st
3
  from nltk.chat.util import Chat, reflections
4
+ from difflib import get_close_matches
5
 
6
  # Eğitim veri seti
7
  training_data = [
 
24
  def run_chatbot():
25
  print("Merhaba! Benim adım ChatBot. Size nasıl yardımcı olabilirim? (Çıkış için 'çıkış' yazabilirsiniz)")
26
 
 
27
  user_input = st.text_area("Siz: ")
28
  if user_input:
29
+ # En yakın eşleşmeyi bul
30
+ closest_match = get_close_matches(user_input.lower(), chatbot._pairs.keys(), n=1, cutoff=0.6)
31
+ if closest_match:
32
+ response = chatbot.respond(closest_match[0])
33
+ st.write("ChatBot: " + response)
34
+ else:
35
+ st.write("ChatBot: Üzgünüm, anlayamadım. Lütfen tekrar deneyin.")
36
 
37
  # Sohbet botunu başlat
38
  run_chatbot()