Thanks for reading the post.
Gunicorn workers are not going to have access to the global context (clf) and that’s why you’re seeing the error. Details here:
If you’re using gunicorn you have to think of each function as a self-contained unit. In this case that means that we have to load the classifier every time the function is called. You can either (1) read from disk using joblib.load or (2) setup a memory store like Redis and load from memory for faster access. If latency is an issue I recommend the second option. I’ve written some code that you might want to reference (apologies for poor documentation in advance):