Prepare the generate function
Browse files
test.py
CHANGED
|
@@ -4,4 +4,18 @@ from keras.saving import load_model
|
|
| 4 |
from keras_self_attention import SeqSelfAttention
|
| 5 |
from vecs import *
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from keras_self_attention import SeqSelfAttention
|
| 5 |
from vecs import *
|
| 6 |
|
| 7 |
+
with open("dataset.json", "r") as f:
|
| 8 |
+
dset = json.load(f)
|
| 9 |
+
|
| 10 |
+
model = load_model("chatbot.keras", custom_objects={"SeqSelfAttention": SeqSelfAttention})
|
| 11 |
+
|
| 12 |
+
def find_line_number(array):
|
| 13 |
+
return sorted(zip(list(array), [x for x in range(len(array))]), key=lambda x:x[0], reverse=True)[0][1] # yeah, one big line, find the biggest value and return the number of the line
|
| 14 |
+
|
| 15 |
+
def generate(text):
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__": # if this code is not being imported, open the chat
|
| 19 |
+
while True:
|
| 20 |
+
inp = input("User: ")
|
| 21 |
+
print(f"Bot: {generate(inp)}")
|