Exemplo n.º 1
0
def prediction():
    form = SubmissionForm(request.form)

    # Form has been submitted
    if request.method == 'POST' and form.validate():

        data = {
            "Inputs": {
                "input1": [{
                    'Salary_class_2-8-greater8': "1",
                    'FG': form.FG.data.lower(),
                    'PTS': form.PTS.data.lower(),
                    'FGA': form.FGA.data.lower(),
                    'Two_P': form.Two_P.data.lower()
                }],
            },
            # "GlobalParameters":  {
            # }
            "GlobalParameters": {
                'The initial learning weights diameter': "0.01",
            }
        }
        # Serialize the input data into json string
        body = str.encode(json.dumps(data))

        # Formulate the request
        req = urllib.request.Request(NBA_ML_URL, body, HEADERS)

        # Send this request to the AML service and render the results on page
        try:
            response = urllib.request.urlopen(req)
            respdata = response.read()
            result = json.loads(str(respdata, 'utf-8'))
            result = get_prediction_data(result)
            return render_template(
                'result.html',
                title="This is the result from AzureML running our prediction:",
                result=result,
                bucket=s3_bucket)

        # An HTTP error
        except urllib.error.HTTPError as err:
            result = "The request failed with status code: " + str(err.code)
            return render_template('result.html',
                                   title='There was an error',
                                   result=result,
                                   bucket=s3_bucket)

    # Just serve up the input form
    return render_template(
        'form.html',
        form=form,
        title='Run App',
        message='Demonstrating a website using Azure ML Api',
        bucket=s3_bucket)
Exemplo n.º 2
0
def submit_problem(pid):
    form = SubmissionForm(pid = pid)
    if request.method == 'POST' and form.validate():
        submit = Submit(runid = Submit.query.count() + 1, userid = current_user.userid,pid = form.pid.data, language = form.language.data, src = form.src.data, submit_time = get_now_time())
        submit.save()
        print "submit successfully"
        return redirect(url_for('status'))
    error = get_error(form)
    if error:
        flash(error)
    return render_template('submit.html',form = form,pid = pid)
Exemplo n.º 3
0
def submit_problem(pid):
    form = SubmissionForm(pid=pid)
    if request.method == 'POST' and form.validate():
        submit = Submit(runid=Submit.query.count() + 1,
                        userid=current_user.userid,
                        pid=form.pid.data,
                        language=form.language.data,
                        src=form.src.data,
                        submit_time=get_now_time())
        submit.save()
        print "submit successfully"
        return redirect(url_for('status'))
    error = get_error(form)
    if error:
        flash(error)
    return render_template('submit.html', form=form, pid=pid)