• import glob
    import pickle
    from flask import Flask, request
    from flasgger import Swagger
    import numpy as np
    import pandas as pd
    import os, fnmatch
    
    #location of saved prediction model for pickle library format
    with open('./randomforest2model.pkl', 'rb') as model_file:
        model = pickle.load(model_file)
    
    app = Flask(__name__,)
    swagger = Swagger(app)
    
    @app.route('/predict')
    def predictor_EEG():
        """Example file endpoint returning a prediction of iris
        ---
        parameters:
          -name: input_file
           in: formData
           type: file
           required: true
        """
    
        predictions = []
    
        listOfFiles = os.listdir('/home/nazmi')
        pattern = "*.csv"
        # BUYUK
        last_file = listOfFiles[len(listOfFiles) - 1]
        print("last file {}".format(last_file))
    
        for entry in [last_file]:
            if fnmatch.fnmatch(entry, pattern):
                read_File = pd.read_csv(entry, usecols = range(1, 5))
                print (read_File)
                #checks only the last row of the csv file to do prediction models,
    
                last_row = read_File.tail(20)
                prediction = model.predict(last_row)
    
                # append to list of predictions
                predictions.append(prediction)
    
    
        html = """"
        <html>
        <head>
        <title>Emotion Classification Page</title>
        <meta http-equiv="refresh" content="5" >
        </head>
        <body>
        <h1>This is a model representation of emotional space</h1>
        <h2>The last value on the right represents your current emotional state</h2>
        <p>Value "0" = Happy</p>
        <p>Value "1" = Scared</p>
        <p>Value "2" = Bored</p>
        <p>Value "3" = Calm</p>
        <img src="/static/Pictures/Slide1.PNG" width="50%" height="50%">
        <p>Predicted Emotion = {}</p>
        </body>
        </html>
        """.format(str(predictions))
    
        return html
    
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5000)
    Edited by Edham Arief Dawillah
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment