ipvikas commited on
Commit
e3365b8
1 Parent(s): 5433d51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -19,12 +19,12 @@ nltk.download('punkt')
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,8 +295,8 @@ bot_name = "Sam"
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
 
@@ -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
- input_text= str(input("You: "))
321
- if input_text== "quit":
 
 
 
322
  break
323
 
324
- input_text= tokenize(input_text)
325
- X = bag_of_words(input_text, all_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(input_text):
346
 
347
- #return classifier(input_text)
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