I can run my application in my local machine with docker compose. However, when I deploy my Streamlit app to the cloud, I can see that there is only one entry point.
So I have several questions.
Can I deploy the frontend and backend in the same app in Streamlit cloud?
Can I deploy the FastAPI app in another cloud app in order to connect both apps then?
In that case, I also tried to deploy my backend in another Streamlit Cloud app, but I see the error [Errno 98] error while attempting to bind on address ('127.0.0.1', 8000): address already in use
It’s great to see that you’re learning and experimenting with tools like Streamlit, FastAPI, and Docker for MLOps applications!
Let me try to answer your questions below:
Can I deploy the frontend and backend in the same app in Streamlit Cloud?
Streamlit is a great tool for building interactive, data-driven web apps, but it’s mainly designed for frontend purposes. You typically use it to present your machine learning models and not for running a backend like FastAPI.
Streamlit Cloud currently doesn’t provide support to run backend services, like FastAPI, concurrently with your Streamlit app. You will need to host your FastAPI backend somewhere else.
Can I deploy the FastAPI app in another cloud app in order to connect both apps then?
Yes, you can! You can deploy your FastAPI backend to a different cloud provider that supports running such applications. Services like AWS Elastic Beanstalk, Google Cloud Run, Heroku, Azure App Service can be used. Once your backend is deployed, you can connect to it from your Streamlit app by making HTTP requests to the URL where your FastAPI app is hosted.
Error: [Errno 98] error while attempting to bind on address (‘127.0.0.1’, 8000): address already in use
This error should mean that the port you’re trying to use (8000 in this case) is already being used by another process. I haven’t tried myself, but I believe you can usually resolve it by either stopping the process that’s currently using the port or by changing your application to use a different port.
I hope this answers your questions. Please try changing that port and see if it resolves your issues.
If not, there may be some other security considerations to review.