def generate(bot, update, args): ''' Generate random message starting from words given (/with command) ''' argument = ' '.join(args) B = Board(9) B.generate_puzzle(1, to_remove=30) draw_matrix(B.grid, name='puzzle.png') bot.send_photo(chat_id=update.message.chat_id, photo=open('puzzle.png', 'rb'))
from sklearn.preprocessing import StandardScaler import sys import argparse parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('task', help='Solve or generate') parser.add_argument('-i', help='Image to solve') parser.add_argument('--method', help='Which ML algorithm to use - cnn or knn') parser.add_argument( '--model', help='Location of the model.json and model.h5 files for CNN') args = parser.parse_args() if args.task == 'generate': B = Board(9) B.generate_puzzle(1, to_remove=30) draw_matrix(B.grid, name='puzzle.png') # solution_img(B.solution(), B.grid, 'solution.png') sys.exit() elif args.task == 'solve': img = imread(args.i, IMREAD_GRAYSCALE) if args.method == 'knn': scaler = StandardScaler() model = KNeighborsClassifier(n_neighbors=3) x_train, y_train = generate_dataset(250) x_train = x_train.reshape(250, 784) scaler.fit(x_train) model.fit(x_train, y_train) elif args.method == 'cnn': json_file = open(args.model + '.json', 'r') loaded_model_json = json_file.read()