Example #1
0
def predict():
    if request.method == 'POST':
        # check if the request has the file part
        if 'file' not in request.files:
            flash(
                'NOTE: No file received by the server. Please select a file...'
            )
            return redirect('/')

        pic_file = request.files['file']

        # check if the user has chosen a file
        if pic_file.filename == '':
            flash('NOTE: No file selected. Please select a file...')
            return redirect('/')

        pic_name = secure_filename(pic_file.filename)
        pic_extension = pic_name.split('.')[1].lower()

        # check if the uploaded file is an image of the following types
        if pic_extension not in ('png', 'jpg', 'jpeg'):
            flash(
                'NOTE: Wrong file type selected. Only png, jpg and jpeg files are accepted...'
            )
            return redirect('/')

        pic_path = os.path.join(tempfile.gettempdir(), pic_name)
        pic_file.save(pic_path)

        output = prediction(pic_path)

        os.remove(pic_path)

        return redirect(url_for('output', output=output))
Example #2
0
def get_model_pred():

    if request.is_json:
        try:
            req = request.get_json()
            features_list = req.get("audio_features")
            result_str = model.prediction(features_list)
            result = json.loads(result_str)
            return result["0"]
        except Exception as e:
            print(e)
            return "Error getting prediction", 400
    else:
        return "Request body must be a JSON object"
Example #3
0
 def predictTomorrow(self, name):
     self.__code = Service.STOCK_CODES[name.lower()]
     self.__data = make_data_for_tomorrow(self.__code)
     self.__pred = prediction(self.__code, self.__data)
     print(self.__pred)
     return self.__pred
Example #4
0
 def prediction(self, name, data):
     self.__code = Service.STOCK_CODES[name.lower()]
     self.__pred = prediction(self.__code, data)
     print(self.__pred)
     return self.__pred