You will not have access to local IP addresses on Streamlit Cloud. I think you will need a different method of deployment where you have network control.
You should deploy the FastAPI server part of the application standalone in another cloud. The sample above as is, is only suitable for local development.
In Streamlit Cloud the Streamlit front end app would have to mediate all communications with the FastAPI server, because only Streamlit’s server (may) have access to localhost:5000. It’s something I could try with that sample later.
I updated the app to start FastAPI on 127.0.0.1:5000. Calls are now routed to the 127.0.0.1:5000 endpoints, and the FastAPI server can be shutdown (and restarted).
In conclusion, for apps deployed in Streamlit Cloud:
The server-side code can access a FastAPI server running on localhost (specifically 127.0.0.1) which I tested with a new endpoint that returns a JSON response.
Client-side links of course can’t access the FastAPI server running on 127.0.0.1 in the cloud environment.
There are plenty of use cases that can use this simple FastAPI integration approach