I made a REST API that I want to use for deploying machine learning models. The one posted below is a simple one for the iris dataset and it works perfectly offline, but when I upload it to Beanstalk it gives me a HTTP 500 error. This one should take a PUSH request and it doesn't work, but when I made a simpler one with GET request returning "Hello World" it worked. What is wrong with my code below?
Thanks in advance.
from flask import Flask, request, jsonify
from sklearn.externals import joblib
application = Flask(__name__)
iris_path = os.path.join(application.root_path, 'iris.pkl')
iris_model = joblib.load(iris_path, "r")
@application.route("/", methods=["POST"])
def iris():
data = request.get_json(force=True)
sepal_length = float(data['sepal length (cm)'])
sepal_width = float(data['sepal width (cm)'])
petal_length = float(data['petal length (cm)'])
petal_width = float(data['petal width (cm)'])
response = iris_model.predict([[sepal_length, sepal_width, petal_length, petal_width]]).tolist()
return jsonify(response)
if __name__ == "__main__":
application.run(debug = True)
I take the model file, python file and requirements file and zip it and then upload it to Elastic Beanstalk, but it doesn't work with post requests.