def index(): if request.method == "POST": file_content = flask.request.files.get('file_content', '') if not file_content: prediction = "select an image!!" else: filename = secure_filename(file_content.filename) save_path = os.path.join("faceorplace", "static", "undecided", filename) file_content.save(save_path) prediction = model.make_prediction(file_content) move_path = os.path.join("faceorplace", "static", prediction + "s", filename) os.rename(save_path, move_path) time.sleep(0.1) if request.method == "GET": prediction = "..." imgs_faces = get_image_files(os.path.join("faceorplace", "static", "faces")) imgs_faces = ["static/faces/" + f for f in imgs_faces] imgs_places = get_image_files( os.path.join("faceorplace", "static", "places")) imgs_places = ["static/places/" + f for f in imgs_places] return render_template('index.jinja2', imgs_faces=imgs_faces, imgs_places=imgs_places, prediction=prediction)
def model_prediction(): # We retrieve the data payload of the POST request data = request.get_json(force=True) # We then preprocess our data, and use our pretrained model to make a # prediction. output = make_prediction(data, static_model) # We finally package this prediction as a JSON object to deliver a valid # response with our API. return jsonify(output)
def main(train_file, test_file, model_path, output_path, plot_flag): if train_file: click.echo('Loading training data') X_train, y_train = load_data(train_file, model_path) click.echo('Generating corr heatmap') if plot_flag: try: plot_corr(X_train, y_train, output_path, plot_it=False) except: click.echo('Failed to plot correlation heatmap') click.echo('Model traninig') train_xgbr(X_train, y_train, INITIAL_PARAM, PARAM_1, PARAM_2, model_path=model_path, test_size=0.2) click.echo('Loading test data') X_test, y_test = load_data(test_file, model_path) click.echo('Making prediction') pred = make_prediction(X_test, model_path, output_path) click.echo('Evaluating and plot') _, scores = evaluate(pred, y_test, X_test, output_path, window_size=WIN_SIZE, top=TOP, ranks=RANK)
def model_prediction(): file_name = flask.request.values.get('file_name') return model.make_prediction(file_name)
import csv import model # make a prediction given the data predictions = [] with open('./train.csv') as data_file: data = data_file.read() for row in data: predictions.append(model.make_prediction(row)) # write the data to a file to submit fieldnames = ['PassengerId', 'Survived'] with open('predictions.csv', 'w+') as csv_file: writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() for prediction in predictions: writer.writerow(prediction)