Set gradio api server from env (#6666)

* Use GRADIO_API_SERVER env

* Format the code

* add changeset

* Use env GRADIO_SHARE_SERVER_ADDRESS as default share_server_address

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
aisensiy 2023-12-06 10:09:42 +08:00 committed by GitHub
parent 51b54b3411
commit 30c9fbb5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": minor
---
feat:Set gradio api server from env

View File

@ -30,6 +30,7 @@ INITIAL_PORT_VALUE = int(os.getenv("GRADIO_SERVER_PORT", "7860"))
TRY_NUM_PORTS = int(os.getenv("GRADIO_NUM_PORTS", "100"))
LOCALHOST_NAME = os.getenv("GRADIO_SERVER_NAME", "127.0.0.1")
GRADIO_API_SERVER = "https://api.gradio.app/v2/tunnel-request"
GRADIO_SHARE_SERVER_ADDRESS = os.getenv("GRADIO_SHARE_SERVER_ADDRESS")
should_watch = bool(os.getenv("GRADIO_WATCH_DIRS", False))
GRADIO_WATCH_DIRS = (
@ -218,6 +219,11 @@ def start_server(
def setup_tunnel(
local_host: str, local_port: int, share_token: str, share_server_address: str | None
) -> str:
share_server_address = (
GRADIO_SHARE_SERVER_ADDRESS
if share_server_address is None
else share_server_address
)
if share_server_address is None:
try:
response = httpx.get(GRADIO_API_SERVER, timeout=30)