FastAPI and Streamlit DEPLOY PORT ERROR

Hi,

i have a problem when try to deploy this FASTAPI and STREAMLIT integration on cloud .
This is the code : GitHub - asehmi/simple-streamlit-fastapi-integration: A minimal Streamlit app showing how to launch and stop a FastAPI process on demand

This is the error coused by port conflict .

Deployed app : https://intelligenzaartificiale-alexagpt-lrp-app-zrqfyj.streamlit.app/

Can anyone help me ?

i have change the port to 5000 and work fine, but now i have another problem …

Now the fastapi server go up:

but how i can access to the endpoint ?

I would need a way to publicly expose the created pages and endpoints. Does anyone know how I can do it?

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.

1 Like

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.

[Edited: see my update in following comment.]

1 Like

Hi,

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:

  1. 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.
  2. Client-side links of course can’t access the FastAPI server running on 127.0.0.1 in the cloud environment.
  3. There are plenty of use cases that can use this simple FastAPI integration approach :slight_smile:

You can see the app running here: https://simple-fastapi-integration.streamlit.app/

Updated source code on GitHub.

Arvindra

3 Likes

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