Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
|
|
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 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
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()
|