502 error on Flask Docker application for training ML models

59 Views Asked by At

I've created a Flask web application for training and testing ML models using datasets provided by the users and I've created a docker image of this application.

The docker container runs fine locally, but when I call the service from the deployed docker container I get a 502 Bad Gateway error. I don't know if it is a problem of my docker image or if it is a problem of the server where I deploy my docker container.

Here is the Dockerfile I've created:

FROM python:3.9.1

WORKDIR /app

COPY requirements.txt requirements.txt

RUN pip install --upgrade pip

RUN pip install -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--chdir", "manila", "app:app", "-w", "2", "--timeout", "600"]

Here is the Python service, basically I generate the testing code dinamically using information provided by the user and then I execute it:

class Run(Resource):
    def post(self):
        params = request.form.to_dict()
        params.update({"web": "web"})
        data_extension = params.get("extension")
        data = request.files["dataset"].read()
        try:
            folder_name = generate_code(params)
            metrics, model = run_experiment(data, folder_name, data_extension)
        except Exception as e:
            app.logger.error(e.with_traceback(e.__traceback__).args)
            message = json.dumps({"error": str(e)})
            return Response(message, status=500, mimetype="application/json")
        results = {"models": {}, "metrics": {}}
        for k in metrics.keys():
            if k == "fairness_method" or k == "model":
                results["models"][k] = metrics[k]
            else:
                results["metrics"][k] = metrics[k]
        response = make_response({"results": results, "model_path": model}, 200)
        response.headers["Content-Type"] = "application/json"
        return response

Unfortunately I don't have access to the configuration of the server where the docker container is deployed.

0

There are 0 best solutions below