ipvikas commited on
Commit
7025527
1 Parent(s): bee2bf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -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
 
@@ -294,9 +294,9 @@ bot_name = "Sam"
294
 
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,16 +318,16 @@ print("Let's chat! (type 'quit' to exit)")
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
 
@@ -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 .launch()
 
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()