Exemple #1
0
def model(id):
    model = mlModels.query.get(id)
    form = PredictForm()
    if form.validate_on_submit():
        task = predictions(data=form.data.data.filename, model_id=id)
        db.session.add(task)
        db.session.commit()

        s3Client.put_object(Bucket=S3Name,
                            Key=str(task.creationdate) +
                            form.data.data.filename,
                            Body=form.data.data)

        SQS.send_message(QueueUrl=predictQueue,
                         MessageBody=json.dumps({'id': task.pred_id}))

        return redirect(url_for('results', id=task.pred_id))
    data = json.loads(model.data)
    dictionary = json.loads(model.dict)
    return render_template(
        'model.html',
        form=form,
        model=model,
        date=model.creationdate.strftime("%m/%d/%Y, %H:%M:%S"),
        layers=dictionary['layers'],
        sampling=dictionary['sampling'],
        custom=dictionary['custom'],
        customDesc=dictionary['model'],
        dataType=data['dataType'])
Exemple #2
0
def demo_heart(request):
    context = {
        "model": None,
        "predictform": None,
        "predictionresult": None,
        "input": None,
    }

    model = get_object_or_404(ClassificationModel, pk=2)
    context["model"] = model

    predictform = PredictForm(model.variables)
    context["predictform"] = predictform

    if request.method == "POST":
        predictform = PredictForm(model.variables, request.POST)
        if predictform.is_valid():
            cd = predictform.cleaned_data
            prediction_result = prediction(cd, model)
            if prediction_result == False:
                messages.warning(request,
                                 "Something went wrong with the prediction.")
            else:
                context["predictionresult"] = prediction_result
                context["predictform"] = predictform
                context["input"] = cd
        else:
            messages.warning(request,
                             "Something went wrong with the prediction.")

    return render(request, "app/predict.html", context)
Exemple #3
0
def text_predict(request):
    if request.method == 'POST':
        form = PredictForm(request.POST)
        if form.is_valid():
            my_dict = request.POST.dict()
            result = predict(my_dict)
            print(result)
            messages.success(request, {result})

    form = PredictForm()
    return render(request, 'predict_form.html', {'form': form})
Exemple #4
0
def predict():
    result_LinearSVC = ""
    result_NuSVC = ""
    result_DecisionTree = ""
    result_sentiment = ""
    f1_LinearSVC, acc_LinearSVC = None, None
    f1_NuSVC, acc_NuSVC = None, None
    f1_DecisionTree, acc_DecisionTree = None, None

    form = PredictForm()

    if form.validate_on_submit():

        result_LinearSVC = prediction(form.parent_text.data,
                                      form.child_text.data, 'LinearSVC')
        f1_LinearSVC, acc_LinearSVC = cross_validation('LinearSVC')

        result_NuSVC = prediction(form.parent_text.data, form.child_text.data,
                                  'NuSVC')
        f1_NuSVC, acc_NuSVC = cross_validation('NuSVC')

        result_DecisionTree = prediction(form.parent_text.data,
                                         form.child_text.data, 'DecisionTree')
        f1_DecisionTree, acc_DecisionTree = cross_validation('DecisionTree')

        result_sentiment = sentiment_predict(form.parent_text.data,
                                             form.child_text.data)

        return render_template('predict.html',
                               result_LinearSVC=result_LinearSVC,
                               result_NuSVC=result_NuSVC,
                               result_DecisionTree=result_DecisionTree,
                               form=form,
                               f1_LinearSVC=f1_LinearSVC,
                               f1_DecisionTree=f1_DecisionTree,
                               f1_NuSVC=f1_NuSVC,
                               acc_LinearSVC=acc_LinearSVC,
                               acc_DecisionTree=acc_DecisionTree,
                               acc_NuSVC=acc_NuSVC,
                               result_sentiment=result_sentiment)

    return render_template('predict.html',
                           result_LinearSVC=result_LinearSVC,
                           result_NuSVC=result_NuSVC,
                           result_DecisionTree=result_DecisionTree,
                           form=form,
                           f1_LinearSVC=f1_LinearSVC,
                           f1_DecisionTree=f1_DecisionTree,
                           f1_NuSVC=f1_NuSVC,
                           acc_LinearSVC=acc_LinearSVC,
                           acc_DecisionTree=acc_DecisionTree,
                           acc_NuSVC=acc_NuSVC,
                           result_sentiment=result_sentiment)
Exemple #5
0
def predict():
    form = PredictForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            key_array = []
            prediction_array = []
            for key in request.files.keys():
                key_array.append(key)
            images = request.files.getlist(key_array[0])
            for img in images:
                filename = os.path.join(app.config['UPLOAD_FOLDER'],
                                        save_file(img))
                filename_array = filename.split('\\')
                name = filename_array[len(filename_array) -
                                      1].split('.')[0].split('_')[0]
                prediction_object = {
                    'name': name,
                    'prediction': predict_file(filename, form.project.data)
                }
                prediction_array.append(prediction_object)
            return render_template('predictions.html',
                                   prediction=prediction_array)
    return render_template('predict.html', title='Predict', form=form)
Exemple #6
0
def predictdata():
    form = PredictForm.new()
    if form.validate_on_submit():
        assets_dir = os.path.join(os.path.dirname(app.instance_path), 'assets')

        input_data = form.datasheet.data
        input_filename = secure_filename(input_data.filename)
        model_name = form.model_name.data
        input_data.save(os.path.join(assets_dir, 'tempdata', input_filename))

        results_array = easy_ai_prediction.prediction(input_filename,
                                                      model_name)
        session['results'] = results_array.tolist()
        os.remove('C:/Users/Matt/Documents/graymatter-flask/assets/tempdata/' +
                  input_filename)
        return redirect(url_for('results'))
    return render_template('predictdata.html', title='Predict Data', form=form)
Exemple #7
0
def PredictHeartDisease():
    form = PredictForm()
    return render_template('predict.html', title='Predict', form=form)