Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,28 +32,33 @@ model.load("MentalHealthChatBotmodel.tflearn")
|
|
32 |
|
33 |
def bag_of_words(s, words):
|
34 |
bag = [0 for _ in range(len(words))]
|
35 |
-
|
36 |
s_words = nltk.word_tokenize(s)
|
|
|
37 |
s_words = [stemmer.stem(word.lower()) for word in s_words]
|
|
|
38 |
|
39 |
for se in s_words:
|
40 |
for i, w in enumerate(words):
|
41 |
if w == se:
|
42 |
bag[i] = 1
|
43 |
-
|
44 |
return np.array(bag)
|
45 |
|
46 |
|
47 |
def chat(message, history=None):
|
48 |
-
|
49 |
-
history = []
|
50 |
message = message.lower()
|
51 |
|
52 |
try:
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
results_index = np.argmax(results)
|
55 |
tag = labels[results_index]
|
|
|
56 |
except Exception as e:
|
|
|
57 |
response = "I'm sorry, I couldn't understand your message."
|
58 |
history.append((message, response))
|
59 |
return history, history
|
|
|
32 |
|
33 |
def bag_of_words(s, words):
|
34 |
bag = [0 for _ in range(len(words))]
|
|
|
35 |
s_words = nltk.word_tokenize(s)
|
36 |
+
print("Tokenized words:", s_words) # Debugging
|
37 |
s_words = [stemmer.stem(word.lower()) for word in s_words]
|
38 |
+
print("Stemmed words:", s_words) # Debugging
|
39 |
|
40 |
for se in s_words:
|
41 |
for i, w in enumerate(words):
|
42 |
if w == se:
|
43 |
bag[i] = 1
|
|
|
44 |
return np.array(bag)
|
45 |
|
46 |
|
47 |
def chat(message, history=None):
|
48 |
+
history = history or []
|
|
|
49 |
message = message.lower()
|
50 |
|
51 |
try:
|
52 |
+
print("User message:", message) # Debugging
|
53 |
+
bag = bag_of_words(message, words)
|
54 |
+
print("Bag of words:", bag) # Debugging
|
55 |
+
results = model.predict([bag])
|
56 |
+
print("Prediction results:", results) # Debugging
|
57 |
results_index = np.argmax(results)
|
58 |
tag = labels[results_index]
|
59 |
+
print("Predicted tag:", tag) # Debugging
|
60 |
except Exception as e:
|
61 |
+
print(f"Error during processing: {e}") # Log the error
|
62 |
response = "I'm sorry, I couldn't understand your message."
|
63 |
history.append((message, response))
|
64 |
return history, history
|