def get_word(): task_id = request.form['task_id'] show_details = request.form['show_details'] == 'true' record = SubmitRecord.query.filter_by(task_id=task_id).first() data = json.loads(record.result) generator = WordGenerator(record.file_name, data, show_details) generator.generate() filename = generator.filename return filename
from word_generator import WordGenerator import re import pickle model = WordGenerator() word_list = open("first_names.all.txt", "r").read() word_list = re.sub(r"[^a-zA-Z0-9@#$%\^\\/&\*\(\):;\?!'\-\n]", "", word_list).split("\n") model.train(word_list, 3, 2) pickle.dump(model, open("model.pkl", "wb")) for approx_length in range(3, 15): print("generated word of (approximate) length", approx_length, "is", model.generate(approx_length))