ipvikas commited on
Commit
0bc96cb
1 Parent(s): 361538c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -31
app.py CHANGED
@@ -220,8 +220,8 @@ for epoch in range(num_epochs):
220
  loss.backward()
221
  optimizer.step()
222
 
223
- if (epoch+1) % 100 == 0:
224
- print (f'Epoch [{epoch+1}/{num_epochs}], Loss: {loss.item():.4f}')
225
 
226
 
227
  #print(f'final loss: {loss.item():.4f}')#commented
@@ -290,35 +290,18 @@ model.eval()
290
 
291
  bot_name = "Sam"
292
 
293
- def get_response(input_text):
294
- sentence= tokenize(input_text)
295
- X = bag_of_words(sentence, all_words)
296
- X = X.reshape(1, X.shape[0])
297
- X = torch.from_numpy(X).to(device)
298
-
299
- output = model(X)
300
- _, predicted = torch.max(output, dim=1)
301
 
302
- tag = tags[predicted.item()]
303
-
304
- probs = torch.softmax(output, dim=1)
305
- prob = probs[0][predicted.item()]
306
- if prob.item() > 0.75:
307
- for intent in intents['intents']:
308
- if tag == intent["tag"]:
309
- return random.choice(intent['responses'])
310
-
311
- return "I do not understand..."
312
-
313
- print("Let's chat! (type 'quit' to exit)")
314
- while True:
315
  # sentence = "do you use credit cards?"
316
- try:
317
- sentence= input("You: ")
318
- if sentence== "Quit":
319
- break
320
- except EOFError as e:
321
- print(end="")
322
  #if sentence== "quit":
323
  #break
324
 
@@ -337,9 +320,9 @@ while True:
337
  if prob.item() > 0.75:
338
  for intent in intents['intents']:
339
  if tag == intent["tag"]:
340
- print(f"{bot_name}: {random.choice(intent['responses'])}")
341
  else:
342
- print(f"{bot_name}: I do not understand...")
343
 
344
 
345
 
 
220
  loss.backward()
221
  optimizer.step()
222
 
223
+ #if (epoch+1) % 100 == 0:
224
+ #print (f'Epoch [{epoch+1}/{num_epochs}], Loss: {loss.item():.4f}')
225
 
226
 
227
  #print(f'final loss: {loss.item():.4f}')#commented
 
290
 
291
  bot_name = "Sam"
292
 
293
+ ###removed
 
 
 
 
 
 
 
294
 
295
+ def get_response(input_text):
296
+ #print("Let's chat! (type 'quit' to exit)")
297
+ #while True:
 
 
 
 
 
 
 
 
 
 
298
  # sentence = "do you use credit cards?"
299
+ #try:
300
+ #sentence= input("You: ")
301
+ #if sentence== "Quit":
302
+ #break
303
+ #except EOFError as e:
304
+ #print(end="")
305
  #if sentence== "quit":
306
  #break
307
 
 
320
  if prob.item() > 0.75:
321
  for intent in intents['intents']:
322
  if tag == intent["tag"]:
323
+ return random.choice(intent['responses'])
324
  else:
325
+ return "I do not understand..."
326
 
327
 
328