Update app.py
Browse files
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 |
-
|
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 |
-
|
303 |
-
|
304 |
-
|
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 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
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 |
-
|
341 |
else:
|
342 |
-
|
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 |
|