Esempio n. 1
0
def index():

    # Handle request from form
    form = DataForm()
    if form.validate_on_submit():

        # If the form is submitted and validated, store all the
        # inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value

        # Preprocess data
        data = preprocess(session)

        # Get model outputs
        pred = predict(data)

        # Postprocess results
        pred = postprocess(pred)

        # Create the payload (we use session)
        session['pred'] = pred

        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Esempio n. 2
0
def start_by_mode(mode):
    if mode == '1' or mode == 'train':
        from app import train
        train.train()
    elif mode == '2' or mode == 'predict':
        from app import predict
        if len(sys.argv) == 3:
            img_path = sys.argv[2]
        else:
            img_path = input('Enter image path: ')

        model = predict.get_model()
        prediction = predict.predict(img_path, model)
        print(prediction)
    elif mode == '3' or mode == 'start_server':
        from app import server
        app = server.get_app()
        app.run(debug=True, host='0.0.0.0', port=19000)
    elif mode == '4' or mode == 'generate_oidv4':
        if len(sys.argv) == 3:
            label = sys.argv[2]
        else:
            label = input('Enter oidv4 label: ')

        from app import generate_oidv4
        generate_oidv4.generate(label)
    elif mode == '5' or mode == 'augment_data':
        from app import augmentor
        if len(sys.argv) == 3:
            img_dir = sys.argv[2]
        else:
            img_dir = input('Enter image directory: ')
        augmentor.start(img_dir)
    elif mode == 'q':
        exit()
Esempio n. 3
0
def estimate(features):
    features_dict = ast.literal_eval(features)

    estimated_price = predict(features_dict)
    feature_houses = cluster(features_dict)

    neighborhood = features_dict['property_type']
    features_dict['property_type'] = getPropertyType(neighborhood)

    return render_template('result.html',
                           page='result',
                           features=features_dict,
                           estimated_price=estimated_price,
                           feature_houses=feature_houses)
Esempio n. 4
0
def index():

    """
    We grab the form defined in `forms.py`. 
    If the form is submitted (and passes the validators) 
    then we grab all the values entered by the user and 
    predict. 
    """


    # Handle request from form
    form = DataForm()
    if form.validate_on_submit():

        # If the form is submitted and validated, store all the 
        # inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value

        session['csrf_token'] = ''
        # Get additional user data
        user_info = request.headers.get('User-Agent')
        white = "\033[1;37;40m"
        print("\033[1;32;40m Preprocess  \n",white)
        # Preprocess data
        print(f"Pre preprocess: {session}")
        data = preprocess(session)
        print(f"Post preprocess: {data}")
        print("\033[1;32;40m Predict  \n",white)
        # Get model outputs 
        pred = predict(data)
        print("\033[1;32;40m Postprocess  \n",white)
        # Postprocess results
        pred = postprocess(pred)

        # Create the payload (we use session)
        session['user_info'] = user_info
        session['pred'] = pred


        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Esempio n. 5
0
def welcome_post():
    model = predict.get_model()
    img_str = request.form.get('img')
    img_str_clean = img_str.replace('data:image/jpeg;base64,',
                                    '').replace('data:image/png;base64,', '')

    img_data = base64.b64decode(img_str_clean)
    ts = time.time()
    file_name = '/tmp/' + str(ts) + '.jpg'
    with open(file_name, 'wb') as f:
        f.write(img_data)

    prediction = predict.predict(file_name, model)

    #  if prediction == 'adalah organic':
    #    os.system('xdotool key 1 && xdotool key 0')
    #  else:
    #    os.system('xdotool key 2 && xdotool key 0')

    return '<h1>Prediction:  ' + prediction + '</h1><br /><br /><a href="/">Home</a>'
Esempio n. 6
0
def index():
    """
    We grab the form defined in `forms.py`.
    If the form is submitted (and passes the validators)
    then we grab all the values entered by the user and
    predict.
    """

    # Handle request from form
    form = DataForm()
    if form.validate_on_submit():

        session.clear()
        # If the form is submitted and validated, store all the
        # inputs in session
        for fieldname, value in form.data.items():
            session[fieldname] = value

        # Get additional user data
        user_info = request.headers.get('User-Agent')

        # Preprocess data
        data = preprocess(session)

        # Get model outputs
        pred = predict(data)

        # Postprocess results
        pred = postprocess(pred)

        # Create the payload (we use session)
        session['user_info'] = user_info
        session['pred'] = pred

        return redirect(url_for('index'))

    return render_template('index.html', form=form)