Exemple #1
0
def cuteness_from_img():
    f = request.files['pic']
    if not f or not allowed_file(f.filename.lower()):
        return redirect(url_for('index'))

    now = str(time()).replace('.', '-') + '{:02d}'.format(randint(0, 100))
    img_path = UPLOAD_FOLDER + now + '.' + f.filename.split('.')[-1]
    f.save(img_path)

    res = judge(img_path)

    if request.method == 'POST':
        return redirect(url_for('view', img=img_path, score=res))
    return str(res)
Exemple #2
0
def cuteness_from_url():
    url_param = request.args.get('url', None)
    if 'url' in request.form:
        url_form = request.form['url']
    else:
        url_form = ''

    if url_param is None and url_form.strip() == '':
        return redirect(url_for('index'))

    url = url_param if url_param else url_form
    print(url)

    now = str(time()).replace('.', '-') + '{:02d}'.format(randint(0, 100))
    img_path = UPLOAD_FOLDER + now + '.' + url.split('.')[-1]

    get_img(url, img_path)
    res = judge(img_path)

    if request.method == 'POST':
        return redirect(url_for('view', img=img_path, score=res))
    return str(res)