yusiqo commited on
Commit
c603eb7
·
verified ·
1 Parent(s): 52c20e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,7 +1,8 @@
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 = [
@@ -20,19 +21,26 @@ def train_bot(training_data):
20
  # Sohbet botunu eğitme
21
  chatbot = train_bot(training_data)
22
 
 
 
 
 
 
 
23
  # Sohbet botunu çalıştırma
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(), [pattern for pattern, _ in chatbot._pairs], 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()
 
1
  import nltk
2
  import streamlit as st
3
  from nltk.chat.util import Chat, reflections
4
+ from nltk.metrics import jaccard_distance
5
+ import numpy as np
6
 
7
  # Eğitim veri seti
8
  training_data = [
 
21
  # Sohbet botunu eğitme
22
  chatbot = train_bot(training_data)
23
 
24
+ # Jaccard benzerliği hesapla
25
+ def jaccard_similarity(s1, s2):
26
+ s1 = set(s1.split())
27
+ s2 = set(s2.split())
28
+ return 1 - jaccard_distance(s1, s2)
29
+
30
  # Sohbet botunu çalıştırma
31
  def run_chatbot():
32
  print("Merhaba! Benim adım ChatBot. Size nasıl yardımcı olabilirim? (Çıkış için 'çıkış' yazabilirsiniz)")
33
 
34
  user_input = st.text_area("Siz: ")
35
  if user_input:
36
+ max_sim = -np.inf
37
+ response = ""
38
+ for pattern, responses in chatbot._pairs:
39
+ sim = jaccard_similarity(user_input.lower(), pattern.lower())
40
+ if sim > max_sim:
41
+ max_sim = sim
42
+ response = chatbot.respond(pattern)
43
+ st.write("ChatBot: " + response)
44
 
45
  # Sohbet botunu başlat
46
  run_chatbot()