Esempio n. 1
0
def about():
    file_object = open("log_file/FlaskApi_log.txt", 'a+')
    logger.log(file_object, '============= About Page Opened =============')
    if request.method == 'POST':
        logger.log(file_object, 'Returning about page')
        file_object.close()
        return render_template('about.html')
Esempio n. 2
0
def predict():
    file_object = open("log_file/FlaskApi_log.txt", 'a+')
    try:
        if request.method == 'POST':
            logger.log(
                file_object,
                '============= Single Prediction Started =============')
            message = request.form['message']
            logger.log(file_object, 'Data taken for single prediction')
            data = [message]
            my_prediction = model.predict(t.transform(data))
            logger.log(file_object, 'Data passed to model for prediction ')
            logger.log(
                file_object,
                '============= Single Prediction Completed =============')
            file_object.close()
        return render_template('result.html', prediction=my_prediction)
    except Exception as e:
        logger.log(file_object,
                   'Single Prediction Failed . ERROR message :  ' + str(e))
        file_object.close()
        return 'Something went wrong'
Esempio n. 3
0
def retrain():
    file_object = open("log_file/FlaskApi_log.txt", 'a+')
    try:
        logger.log(file_object,
                   '============= Retraining Model Started =============')
        if request.method == "POST":
            file = request.files['retrain_file']
            if file:
                file.save(secure_filename(file.filename))
                a = trainModel()
                a.trainingModel(file.filename, file_object)
                logger.log(
                    file_object,
                    '============= Model Retraining Done =============')
                os.remove(file.filename)
                file_object.close()
                return render_template(
                    'home.html', text=".... Model Retrained Successfully ....")
    except Exception as e:
        logger.log(file_object,
                   'Model Retraining Failed . ERROR message :  ' + str(e))
        file_object.close()
        return 'Something went wrong , check your file extension .(should be .csv )'
Esempio n. 4
0
def bulk_predict():
    file_object = open("log_file/FlaskApi_log.txt", 'a+')
    logger.log(file_object,
               '============= Bulk Prediction Started =============')
    if request.method == "POST":
        try:
            f = request.files['csvfile']
            logger.log(file_object, 'File submitted for bulk prediction')
            if f:
                f.save(secure_filename(f.filename))
                logger.log(file_object, 'File saved to directory')
                try:
                    with open(f.filename, encoding='Latin1') as file:
                        csvfile = csv.reader(file)
                        data = []
                        review_prediction = []
                        for row in csvfile:
                            data.append(row)
                except Exception as e:
                    os.remove(f.filename)
                    logger.log(file_object, "File uploded is not csv ..")

                for review in data:
                    review_prediction.append(model.predict(
                        t.transform(review)))
                logger.log(file_object, 'Data passed to model ')
                length = len(data)
                os.remove(f.filename)
                logger.log(file_object, 'Saved file removed successfully')
                file.close()
                logger.log(
                    file_object,
                    '============= Bulk Prediction Complete =============')
                file_object.close()
                return render_template("bulk.html",
                                       predict_data=review_prediction,
                                       data=data,
                                       length=length)
        except Exception as e:
            logger.log(file_object,
                       'Bulk Upload Failed . ERROR message :  ' + str(e))
            file_object.close()
            return "File uploded should be be csv (.csv extension) "
Esempio n. 5
0
def home():
    file_object = open("log_file/FlaskApi_log.txt", 'a+')
    logger.log(file_object, '============= Home Page Opened =============')
    file_object.close()
    return render_template('home.html')