Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,23 +44,26 @@ def bag_of_words(s, words):
|
|
44 |
return np.array(bag)
|
45 |
|
46 |
|
47 |
-
def chat(message, history):
|
48 |
-
|
|
|
49 |
message = message.lower()
|
50 |
results = model.predict([bag_of_words(message, words)])
|
51 |
results_index = np.argmax(results)
|
52 |
tag = labels[results_index]
|
53 |
|
54 |
for tg in data["intents"]:
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
# print(random.choice(responses))
|
59 |
-
response = random.choice(responses)
|
60 |
-
|
61 |
history.append((message, response))
|
62 |
return history, history
|
63 |
|
|
|
64 |
chatbot = gr.Chatbot(label="Chat")
|
65 |
css = """
|
66 |
footer {display:none !important}
|
|
|
44 |
return np.array(bag)
|
45 |
|
46 |
|
47 |
+
def chat(message, history=None):
|
48 |
+
if history is None:
|
49 |
+
history = []
|
50 |
message = message.lower()
|
51 |
results = model.predict([bag_of_words(message, words)])
|
52 |
results_index = np.argmax(results)
|
53 |
tag = labels[results_index]
|
54 |
|
55 |
for tg in data["intents"]:
|
56 |
+
if tg['tag'] == tag:
|
57 |
+
responses = tg['responses']
|
58 |
+
response = random.choice(responses)
|
59 |
+
break
|
60 |
+
else:
|
61 |
+
response = "Sorry, I didn't understand that."
|
62 |
|
|
|
|
|
|
|
63 |
history.append((message, response))
|
64 |
return history, history
|
65 |
|
66 |
+
|
67 |
chatbot = gr.Chatbot(label="Chat")
|
68 |
css = """
|
69 |
footer {display:none !important}
|