ierhon commited on
Commit
c5cb10d
1 Parent(s): a282150

Add !gethash and using a hash as data

Browse files
Files changed (1) hide show
  1. chatbot_constructor.py +9 -2
chatbot_constructor.py CHANGED
@@ -16,15 +16,22 @@ def hash_str(data: str):
16
  return hashlib.md5(data.encode('utf-8')).hexdigest()
17
 
18
  def train(message: str = "", epochs: int = 16, learning_rate: float = 0.001, emb_size: int = 128, inp_len: int = 16, data: str = ""):
 
19
  if "→" not in data or "\n" not in data:
20
- return "Dataset example:\nquestion→answer\nquestion→answer\netc."
 
 
 
21
  dset, responses = todset(data)
22
  resps_len = len(responses)
23
  tokenizer = Tokenizer()
24
  tokenizer.fit_on_texts(list(dset.keys()))
25
 
26
  vocab_size = len(tokenizer.word_index) + 1
27
- data_hash = hash_str(data)+str(epochs)+str(learning_rate)+str(emb_size)+str(inp_len)+".keras"
 
 
 
28
  if data_hash in os.listdir("cache"):
29
  model = load_model("cache/"+data_hash)
30
  else:
 
16
  return hashlib.md5(data.encode('utf-8')).hexdigest()
17
 
18
  def train(message: str = "", epochs: int = 16, learning_rate: float = 0.001, emb_size: int = 128, inp_len: int = 16, data: str = ""):
19
+ data_hash = None
20
  if "→" not in data or "\n" not in data:
21
+ if data in os.listdir("cache"):
22
+ data_hash = data
23
+ else:
24
+ return "Dataset example:\nquestion→answer\nquestion→answer\netc."
25
  dset, responses = todset(data)
26
  resps_len = len(responses)
27
  tokenizer = Tokenizer()
28
  tokenizer.fit_on_texts(list(dset.keys()))
29
 
30
  vocab_size = len(tokenizer.word_index) + 1
31
+ if data_hash is None:
32
+ data_hash = hash_str(data)+str(epochs)+str(learning_rate)+str(emb_size)+str(inp_len)+".keras"
33
+ elif message == "!getmodelhash":
34
+ return data_hash
35
  if data_hash in os.listdir("cache"):
36
  model = load_model("cache/"+data_hash)
37
  else: