Deploying a dockerized MLOps app in Streamlit Cloud with Streamlit and FastAPI

Hi! I am new with Streamlit and Machine Learning and I have just developed a MLOps app with Streamlit and FastAPI. It can be viewed in my GitHub repository: GitHub - albaMCh/ProyectoFinal_ML-FastApi-Streamlit: Este proyecto se basa en el análisis de un database sobre distintos hábitos de vida y como influyen en la probabilidad de desarrollar cáncer, incluye el desarrollo y elección del modelo predictivo, la creación posterior de la api y el desarrollo de una app con Streamlit en el cual tu puedes hacer el test y ver la probabilidad de desarrollar cáncer

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

Thanks so much for the help!

Hi @albaMCh and welcome to our forums! :raised_hands:

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:

  1. 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.

  1. 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.

  1. 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.

Best wishes,
Charly

Ok, Charly. This is what I supposed.

Thank you so much for the entire and detailed explanation.

1 Like

You’re very welcome, @albaMCh!

Let us know how it goes! :slight_smile:

Charly

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.