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 |
|
@@ -318,14 +318,16 @@ print("Let's chat! (type 'quit' to exit)")
|
|
318 |
while True:
|
319 |
# sentence = "do you use credit cards?"
|
320 |
try:
|
321 |
-
|
|
|
|
|
322 |
except EOFError as e:
|
323 |
print(end="")
|
324 |
-
if sentence== "quit":
|
325 |
-
break
|
326 |
|
327 |
-
|
328 |
-
X = bag_of_words(
|
329 |
X = X.reshape(1, X.shape[0])
|
330 |
X = torch.from_numpy(X).to(device)
|
331 |
|
|
|
19 |
from nltk.stem.porter import PorterStemmer
|
20 |
stemmer = PorterStemmer()
|
21 |
|
22 |
+
def tokenize(input_text):
|
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(input_text)
|
28 |
|
29 |
# print(tokenize('Hello how are you'))
|
30 |
|
|
|
295 |
|
296 |
|
297 |
def get_response(msg):
|
298 |
+
input_text= tokenize(msg)
|
299 |
+
X = bag_of_words(input_text, all_words)
|
300 |
X = X.reshape(1, X.shape[0])
|
301 |
X = torch.from_numpy(X).to(device)
|
302 |
|
|
|
318 |
while True:
|
319 |
# sentence = "do you use credit cards?"
|
320 |
try:
|
321 |
+
input_text= input("You: ")
|
322 |
+
if input_text== "Quit":
|
323 |
+
break
|
324 |
except EOFError as e:
|
325 |
print(end="")
|
326 |
+
#if sentence== "quit":
|
327 |
+
#break
|
328 |
|
329 |
+
input_text= tokenize(input_text)
|
330 |
+
X = bag_of_words(input_text, all_words)
|
331 |
X = X.reshape(1, X.shape[0])
|
332 |
X = torch.from_numpy(X).to(device)
|
333 |
|