I'm designing a web application for image analysis using AI. My API for CRUD operations is written in Django. Now I want to add the AI functionality which loads the model once on the startup, receives images, and returns the results. In the future, it would also allow for annotating data and fine-tuning the models.
First, I wanted to load the models in the Django application, but then I'd have to store a variable with the loaded models, which is not a good design. Is that correct?
What alternative do I have? The AI server must be stateful, and I need some kind of API. Is there any clean solution to this?
###############################################
The AI models are implemented in Keras and loaded from *.h5 files. I have considered a message queue and a separate AI server but besides image processing, the server would have to expose some API for settings. If I'd go for implementing a separate AI server with API, then why not use the Django server I already have? In such a case where to store the model's object?
An additional problem is that one of the objects I need to store is a thread, which continuously monitors a server checking for new images to be analyzed. If I declare this variable for example in settings.py, it blocks the further execution, because it never leaves the namespace it's declared in.
I'm asking for recommendations regarding the design for this problem.