Skip to content

Instantly share code, notes, and snippets.

@dte dte/
Created Mar 26, 2018

What would you like to do?
import os
from flask import Flask, redirect, url_for, request, render_template, send_from_directory
from werkzeug import secure_filename
import not_hotdog_model
# todo: more pretty interface
# folder to upload pictures
UPLOAD_FOLDER = 'uploads/'
# what files can upload
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
# start + config
app = Flask(__name__)
# main route
def index():
return render_template('upload.html')
# is file allowed to be uploaded?
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
# result of model prediction
def classification(result):
return render_template('result.html', result=result)
# file upload route
@app.route('/upload', methods=['POST'])
def upload():
# Get the name of the uploaded file
file = request.files['file']
# Check if the file is one of the allowed types/extensions
if file and allowed_file(file.filename):
# remove unsupported chars etc
filename = secure_filename(file.filename)
#save path
save_to=os.path.join(app.config['UPLOAD_FOLDER'], filename)
#save file
#pass file to model and return bool
#show if photo is a photo of hotdog
return redirect(url_for('classification', result=is_hotdog))
#file show route (not using now)
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.