Update app.py
Browse files
app.py
CHANGED
@@ -19,12 +19,12 @@ nltk.download('punkt')
|
|
19 |
from nltk.stem.porter import PorterStemmer
|
20 |
stemmer = PorterStemmer()
|
21 |
|
22 |
-
def tokenize(
|
23 |
"""
|
24 |
split sentence into array of words/tokens
|
25 |
a token can be a word or punctuation character, or number
|
26 |
"""
|
27 |
-
return nltk.word_tokenize(
|
28 |
|
29 |
# print(tokenize('Hello how are you'))
|
30 |
|
@@ -295,8 +295,8 @@ bot_name = "Sam"
|
|
295 |
|
296 |
|
297 |
def get_response(msg):
|
298 |
-
|
299 |
-
X = bag_of_words(
|
300 |
X = X.reshape(1, X.shape[0])
|
301 |
X = torch.from_numpy(X).to(device)
|
302 |
|
@@ -317,12 +317,15 @@ def get_response(msg):
|
|
317 |
print("Let's chat! (type 'quit' to exit)")
|
318 |
while True:
|
319 |
# sentence = "do you use credit cards?"
|
320 |
-
|
321 |
-
|
|
|
|
|
|
|
322 |
break
|
323 |
|
324 |
-
|
325 |
-
X = bag_of_words(
|
326 |
X = X.reshape(1, X.shape[0])
|
327 |
X = torch.from_numpy(X).to(device)
|
328 |
|
@@ -342,9 +345,9 @@ while True:
|
|
342 |
|
343 |
|
344 |
|
345 |
-
#def get_chatbot(
|
346 |
|
347 |
-
#return classifier(
|
348 |
|
349 |
title = "ChatBOT"
|
350 |
|
|
|
19 |
from nltk.stem.porter import PorterStemmer
|
20 |
stemmer = PorterStemmer()
|
21 |
|
22 |
+
def tokenize(sentence):
|
23 |
"""
|
24 |
split sentence into array of words/tokens
|
25 |
a token can be a word or punctuation character, or number
|
26 |
"""
|
27 |
+
return nltk.word_tokenize(sentence)
|
28 |
|
29 |
# print(tokenize('Hello how are you'))
|
30 |
|
|
|
295 |
|
296 |
|
297 |
def get_response(msg):
|
298 |
+
sentence= tokenize(msg)
|
299 |
+
X = bag_of_words(sentence, all_words)
|
300 |
X = X.reshape(1, X.shape[0])
|
301 |
X = torch.from_numpy(X).to(device)
|
302 |
|
|
|
317 |
print("Let's chat! (type 'quit' to exit)")
|
318 |
while True:
|
319 |
# sentence = "do you use credit cards?"
|
320 |
+
try:
|
321 |
+
sentence= input("You: ")
|
322 |
+
except EOFError as e:
|
323 |
+
print(end="")
|
324 |
+
if sentence== "quit":
|
325 |
break
|
326 |
|
327 |
+
sentence= tokenize(sentence)
|
328 |
+
X = bag_of_words(sentence, all_words)
|
329 |
X = X.reshape(1, X.shape[0])
|
330 |
X = torch.from_numpy(X).to(device)
|
331 |
|
|
|
345 |
|
346 |
|
347 |
|
348 |
+
#def get_chatbot(sentence):
|
349 |
|
350 |
+
#return classifier(sentence)
|
351 |
|
352 |
title = "ChatBOT"
|
353 |
|