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 |
|
@@ -294,9 +294,9 @@ bot_name = "Sam"
|
|
294 |
|
295 |
|
296 |
|
297 |
-
def get_response(
|
298 |
-
|
299 |
-
X = bag_of_words(
|
300 |
X = X.reshape(1, X.shape[0])
|
301 |
X = torch.from_numpy(X).to(device)
|
302 |
|
@@ -318,16 +318,16 @@ print("Let's chat! (type 'quit' to exit)")
|
|
318 |
while True:
|
319 |
# sentence = "do you use credit cards?"
|
320 |
try:
|
321 |
-
|
322 |
-
if
|
323 |
break
|
324 |
except EOFError as e:
|
325 |
print(end="")
|
326 |
#if sentence== "quit":
|
327 |
#break
|
328 |
|
329 |
-
|
330 |
-
X = bag_of_words(
|
331 |
X = X.reshape(1, X.shape[0])
|
332 |
X = torch.from_numpy(X).to(device)
|
333 |
|
@@ -354,4 +354,4 @@ while True:
|
|
354 |
title = "ChatBOT"
|
355 |
|
356 |
chatbot_demo = gr.Interface(fn=get_response, inputs = 'text',outputs='text',title = title,description = 'Chat BOT')
|
357 |
-
chatbot_demo
|
|
|
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 |
|
|
|
294 |
|
295 |
|
296 |
|
297 |
+
def get_response(input_text):
|
298 |
+
sentence= tokenize(input_text)
|
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 |
|
|
|
318 |
while True:
|
319 |
# sentence = "do you use credit cards?"
|
320 |
try:
|
321 |
+
sentence= input("You: ")
|
322 |
+
if sentence== "Quit":
|
323 |
break
|
324 |
except EOFError as e:
|
325 |
print(end="")
|
326 |
#if sentence== "quit":
|
327 |
#break
|
328 |
|
329 |
+
sentence= tokenize(sentence)
|
330 |
+
X = bag_of_words(sentence, all_words)
|
331 |
X = X.reshape(1, X.shape[0])
|
332 |
X = torch.from_numpy(X).to(device)
|
333 |
|
|
|
354 |
title = "ChatBOT"
|
355 |
|
356 |
chatbot_demo = gr.Interface(fn=get_response, inputs = 'text',outputs='text',title = title,description = 'Chat BOT')
|
357 |
+
chatbot_demo.launch()
|