Exemplo n.º 1
0
def handle_request():
    if request.method == 'POST':
        if request.files:
            username = '******'

            filename = images.save(request.files['image'])
            url = images.url(filename)

            #---------------------

            result = predict(filename)

            #---------------------

            user = User.query.filter_by(username=username).first()
            if user is None: user = User(username=username)

            report = Report(user=user, data=json.dumps(result))

            image = Image(report=report)

            image.image_filename = filename
            image.image_url = url

            db.session.add(user)
            db.session.add(report)
            db.session.add(image)

            db.session.commit()

            return 'Report Generated'
        return 'No Files Recieved'
    return 'Method not POST'
Exemplo n.º 2
0
def upload():
    form = UploadForm()
    if request.method == 'POST':
        if form.validate_on_submit():

            username = form.username.data

            filename = images.save(request.files['image'])
            url = images.url(filename)

            #---------------------

            result = predict(filename)

            #---------------------

            user = User.query.filter_by(username=username).first()
            if user is None: user = User(username=username)

            report = Report(user=user, data=json.dumps(result))

            image = Image(report=report)

            image.image_filename = filename
            image.image_url = url

            db.session.add(user)
            db.session.add(report)
            db.session.add(image)

            db.session.commit()

            flash(
                'User Report for username: {} generated. '.format(
                    form.username.data), 'success')
            return redirect(url_for('report', report_id=report.id))
        else:
            flash_errors(form)
            flash('ERROR! Report was not generated.', 'error')

    return render_template('upload.html', title='Upload', form=form)