How to get server address (local host or URL in case of deploying) within the app

Hello All
I am currently preparing a streamlit app that allows both training and inference of a model. I am looking for something that can give me the server address of the app in the python script itself. The reason behind this is that I am using streamlit as a handy interface. However, when the app is deployed, I don’t want to show the training functions, but rather only the inference. On the other hand, if the app is started locally, the training functions can show.
Can anyone help me if there is a python function to call that would return e.g “localhost” when the app will start locally and would return some URL of the deployed app when the app is indeed deployed and started from some web address?

“Local” is a relative term. From the point of view of the application, it is always running locally and it is the requests that can come from the outside or not. I guess the web server knows whether that is the case, but there are no stable API to access the server from streamlit.

I suggest making the application take a command line parameter, let’s say --allow-training, to control whether the training interface should be visible or not.

https://docs.python.org/3/howto/argparse.html

Thanks @Goyo I will definitely consider this.

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