streamlit-fastapi-model-serving
streamlit-fastapi-model-serving copied to clipboard
Streamlit requests may fail if FastAPI backend hasn't initialized yet
As the app is started with docker-compose up, the streamlit service is likely the fastest to come online (the fastapi service needs to do the PyTorch model load). If the user visits the streamlit page and fires a call, the result may be

because the fastapi service is not responding yet.
The user should just wait a bit and then results should be returned OK, but it would be better to implement some sort of healthcheck so that streamlit requests can be handled more gracefully.
This example might help
Can this not be resolved in the docker-compose file by only starting the streamlit container after the FastAPI service is up and healthy?
Already the project has the depends_on: in the docker-compose. In addition you can add configuration to wait until that fastapi service is up and healthy. The top rated answer here from SvenHornberg gives some details on how to do that in the docker-compose.yml file - https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y