Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,5 @@
|
|
1 |
import json
|
2 |
import streamlit as st
|
3 |
-
import nltk
|
4 |
-
from nltk.tokenize import word_tokenize
|
5 |
-
|
6 |
-
# Ensure 'punkt' resource is downloaded
|
7 |
-
nltk.download('punkt')
|
8 |
|
9 |
st.set_page_config(page_title="Self-Learning Chatbot")
|
10 |
st.title("Self-Learning Chatbot")
|
@@ -40,14 +35,14 @@ class ChatBot:
|
|
40 |
return response
|
41 |
|
42 |
def find_response(self, user_input):
|
43 |
-
|
44 |
for question in self.knowledge_base.get("questions", []):
|
45 |
-
if
|
46 |
return question['response']
|
47 |
return None
|
48 |
|
49 |
def teach_response(self, user_input, response):
|
50 |
-
new_question = {'question': user_input.lower(), 'response': response}
|
51 |
if 'questions' not in self.knowledge_base:
|
52 |
self.knowledge_base['questions'] = []
|
53 |
self.knowledge_base['questions'].append(new_question)
|
|
|
1 |
import json
|
2 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
st.set_page_config(page_title="Self-Learning Chatbot")
|
5 |
st.title("Self-Learning Chatbot")
|
|
|
35 |
return response
|
36 |
|
37 |
def find_response(self, user_input):
|
38 |
+
user_input = user_input.lower().strip()
|
39 |
for question in self.knowledge_base.get("questions", []):
|
40 |
+
if question['question'].lower() == user_input:
|
41 |
return question['response']
|
42 |
return None
|
43 |
|
44 |
def teach_response(self, user_input, response):
|
45 |
+
new_question = {'question': user_input.lower().strip(), 'response': response}
|
46 |
if 'questions' not in self.knowledge_base:
|
47 |
self.knowledge_base['questions'] = []
|
48 |
self.knowledge_base['questions'].append(new_question)
|