from flask import Flask, request, redirect, url_for, send_from_directory, render_template 
from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
from keras.models import Sequential, load_model
from werkzeug.utils import secure_filename
import numpy as np


ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'png'])
IMAGE_SIZE = (224,224)
UPLOAD_FOLDER = 'uploads'
vgg16 = load_model('model/vgg16.h5')



app = Flask(__name__)
#app.secret_key = "secret key"
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def allowed_file(filename):
	return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


def predict():
	img = load_img(file, target_size = IMAGE_SIZE)
	img = img_to_array(img) / 255.0
	img = np.expand_dims(img, axis = 0)
	probs = vgg16.predict(img)[0]
	output = {"Cat -> " : probs[0], 'Dog -> ' : probs[1]}
	return output


@app.route('/')
def template_test():
	return render_template('index.html', label = '', imagesource = 'file://null')

@app.route("/", methods = ['GET', "POST"])
def upload_file():
	if request.method == "POST":
		file = request.files['file']


		if file and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
			file.save(file_path)
			output = predict(file_path)
	return render_template("index.html", label = output, imagesource = file_path)

@app.route("/uploads/<filename>")
def uploaded_file(filename):
	return send_from_directory(app.config['UPLOAD_FOLDER'], filename)



if __name__ == "__main__":
	app.run(debug = False, threaded = False)
92f73e9896709838a8b386d03a98f51933499527
<mask token>


def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


def predict():
    img = load_img(file, target_size=IMAGE_SIZE)
    img = img_to_array(img) / 255.0
    img = np.expand_dims(img, axis=0)
    probs = vgg16.predict(img)[0]
    output = {'Cat -> ': probs[0], 'Dog -> ': probs[1]}
    return output


@app.route('/')
def template_test():
    return render_template('index.html', label='', imagesource='file://null')


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(file_path)
            output = predict(file_path)
    return render_template('index.html', label=output, imagesource=file_path)


@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)


<mask token>

<mask token>


def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


def predict():
    img = load_img(file, target_size=IMAGE_SIZE)
    img = img_to_array(img) / 255.0
    img = np.expand_dims(img, axis=0)
    probs = vgg16.predict(img)[0]
    output = {'Cat -> ': probs[0], 'Dog -> ': probs[1]}
    return output


@app.route('/')
def template_test():
    return render_template('index.html', label='', imagesource='file://null')


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(file_path)
            output = predict(file_path)
    return render_template('index.html', label=output, imagesource=file_path)


@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)


if __name__ == '__main__':
    app.run(debug=False, threaded=False)

<mask token>
ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'png'])
IMAGE_SIZE = 224, 224
UPLOAD_FOLDER = 'uploads'
vgg16 = load_model('model/vgg16.h5')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


def predict():
    img = load_img(file, target_size=IMAGE_SIZE)
    img = img_to_array(img) / 255.0
    img = np.expand_dims(img, axis=0)
    probs = vgg16.predict(img)[0]
    output = {'Cat -> ': probs[0], 'Dog -> ': probs[1]}
    return output


@app.route('/')
def template_test():
    return render_template('index.html', label='', imagesource='file://null')


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(file_path)
            output = predict(file_path)
    return render_template('index.html', label=output, imagesource=file_path)


@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)


if __name__ == '__main__':
    app.run(debug=False, threaded=False)

from flask import Flask, request, redirect, url_for, send_from_directory, render_template
from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
from keras.models import Sequential, load_model
from werkzeug.utils import secure_filename
import numpy as np
ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'png'])
IMAGE_SIZE = 224, 224
UPLOAD_FOLDER = 'uploads'
vgg16 = load_model('model/vgg16.h5')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


def predict():
    img = load_img(file, target_size=IMAGE_SIZE)
    img = img_to_array(img) / 255.0
    img = np.expand_dims(img, axis=0)
    probs = vgg16.predict(img)[0]
    output = {'Cat -> ': probs[0], 'Dog -> ': probs[1]}
    return output


@app.route('/')
def template_test():
    return render_template('index.html', label='', imagesource='file://null')


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(file_path)
            output = predict(file_path)
    return render_template('index.html', label=output, imagesource=file_path)


@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)


if __name__ == '__main__':
    app.run(debug=False, threaded=False)

from flask import Flask, request, redirect, url_for, send_from_directory, render_template 
from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
from keras.models import Sequential, load_model
from werkzeug.utils import secure_filename
import numpy as np


ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'png'])
IMAGE_SIZE = (224,224)
UPLOAD_FOLDER = 'uploads'
vgg16 = load_model('model/vgg16.h5')



app = Flask(__name__)
#app.secret_key = "secret key"
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def allowed_file(filename):
	return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


def predict():
	img = load_img(file, target_size = IMAGE_SIZE)
	img = img_to_array(img) / 255.0
	img = np.expand_dims(img, axis = 0)
	probs = vgg16.predict(img)[0]
	output = {"Cat -> " : probs[0], 'Dog -> ' : probs[1]}
	return output


@app.route('/')
def template_test():
	return render_template('index.html', label = '', imagesource = 'file://null')

@app.route("/", methods = ['GET', "POST"])
def upload_file():
	if request.method == "POST":
		file = request.files['file']


		if file and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
			file.save(file_path)
			output = predict(file_path)
	return render_template("index.html", label = output, imagesource = file_path)

@app.route("/uploads/<filename>")
def uploaded_file(filename):
	return send_from_directory(app.config['UPLOAD_FOLDER'], filename)



if __name__ == "__main__":
	app.run(debug = False, threaded = False)