Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,6 +41,9 @@ def bag_of_words(s, words):
|
|
41 |
for i, w in enumerate(words):
|
42 |
if w == se:
|
43 |
bag[i] = 1
|
|
|
|
|
|
|
44 |
return np.array(bag)
|
45 |
|
46 |
|
@@ -51,12 +54,17 @@ def chat(message, history=None):
|
|
51 |
try:
|
52 |
print("User message:", message) # Debugging
|
53 |
bag = bag_of_words(message, words)
|
54 |
-
print("Bag
|
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."
|
|
|
41 |
for i, w in enumerate(words):
|
42 |
if w == se:
|
43 |
bag[i] = 1
|
44 |
+
|
45 |
+
if not any(bag): # Check if bag is all zeros
|
46 |
+
print("Warning: No matching words found in vocabulary.")
|
47 |
return np.array(bag)
|
48 |
|
49 |
|
|
|
54 |
try:
|
55 |
print("User message:", message) # Debugging
|
56 |
bag = bag_of_words(message, words)
|
57 |
+
print("Bag representation:", bag) # Debugging
|
58 |
results = model.predict([bag])
|
59 |
print("Prediction results:", results) # Debugging
|
60 |
+
|
61 |
+
if not results.any(): # Handle empty or invalid predictions
|
62 |
+
raise ValueError("Model returned no valid predictions.")
|
63 |
+
|
64 |
results_index = np.argmax(results)
|
65 |
tag = labels[results_index]
|
66 |
print("Predicted tag:", tag) # Debugging
|
67 |
+
|
68 |
except Exception as e:
|
69 |
print(f"Error during processing: {e}") # Log the error
|
70 |
response = "I'm sorry, I couldn't understand your message."
|