From a55ac54c1a5d8f70846ae29adab8887633a25f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B4=A2=E6=AF=85?= <944102712@qq.com> Date: Thu, 3 Aug 2023 23:20:40 +0800 Subject: [PATCH 1/5] solve how can I config root_path dynamically? #4968 --- gradio/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradio/routes.py b/gradio/routes.py index 74623ae81f736..2eaf7b17df2d9 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -142,7 +142,7 @@ def configure_app(self, blocks: gradio.Blocks) -> None: self.cwd = os.getcwd() self.favicon_path = blocks.favicon_path self.tokens = {} - self.root_path = blocks.root_path + self.root_path = os.environ.get("GRADIO_ROOT_PATH") or blocks.root_path def get_blocks(self) -> gradio.Blocks: if self.blocks is None: From a5bcec960ffc639caf58c255506898e7a94811ad Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Thu, 3 Aug 2023 19:30:09 +0000 Subject: [PATCH 2/5] add changeset --- .changeset/big-wolves-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/big-wolves-grab.md diff --git a/.changeset/big-wolves-grab.md b/.changeset/big-wolves-grab.md new file mode 100644 index 0000000000000..394d804e33701 --- /dev/null +++ b/.changeset/big-wolves-grab.md @@ -0,0 +1,5 @@ +--- +"gradio": minor +--- + +feat:solve how can I config root_path dynamically? #4968 From 6c5fba1108b034329ebdcdf9314ce540b1e3d4bf Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Thu, 3 Aug 2023 15:50:02 -0400 Subject: [PATCH 3/5] fixes --- gradio/blocks.py | 8 ++++---- gradio/routes.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gradio/blocks.py b/gradio/blocks.py index 8386ecf21fd5c..ba28693119b72 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -758,7 +758,7 @@ def __init__( self.allowed_paths = [] self.blocked_paths = [] - self.root_path = "" + self.root_path = os.environ.get("GRADIO_ROOT_PATH", "") self.root_urls = set() if not wasm_utils.IS_WASM and self.analytics_enabled: @@ -1690,7 +1690,7 @@ def launch( file_directories: list[str] | None = None, allowed_paths: list[str] | None = None, blocked_paths: list[str] | None = None, - root_path: str = "", + root_path: str = None, _frontend: bool = True, app_kwargs: dict[str, Any] | None = None, ) -> tuple[FastAPI, str, str]: @@ -1725,7 +1725,7 @@ def launch( file_directories: This parameter has been renamed to `allowed_paths`. It will be removed in a future version. allowed_paths: List of complete filepaths or parent directories that gradio is allowed to serve (in addition to the directory containing the gradio python file). Must be absolute paths. Warning: if you provide directories, any files in these directories or their subdirectories are accessible to all users of your app. blocked_paths: List of complete filepaths or parent directories that gradio is not allowed to serve (i.e. users of your app are not allowed to access). Must be absolute paths. Warning: takes precedence over `allowed_paths` and all other directories exposed by Gradio by default. - root_path: The root path (or "mount point") of the application, if it's not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application. For example, if the application is served at "https://example.com/myapp", the `root_path` should be set to "/myapp". + root_path: The root path (or "mount point") of the application, if it's not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application. For example, if the application is served at "https://example.com/myapp", the `root_path` should be set to "/myapp". Can be set by environment variable GRADIO_ROOT_PATH. Defaults to "". app_kwargs: Additional keyword arguments to pass to the underlying FastAPI app as a dictionary of parameter keys and argument values. For example, `{"docs_url": "/docs"}` Returns: app: FastAPI app object that is running the demo @@ -1766,7 +1766,7 @@ def reverse(text): self.width = width self.favicon_path = favicon_path self.ssl_verify = ssl_verify - self.root_path = root_path + self.root_path = root_path or os.environ.get("GRADIO_ROOT_PATH", "") if enable_queue is not None: self.enable_queue = enable_queue diff --git a/gradio/routes.py b/gradio/routes.py index 2eaf7b17df2d9..74623ae81f736 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -142,7 +142,7 @@ def configure_app(self, blocks: gradio.Blocks) -> None: self.cwd = os.getcwd() self.favicon_path = blocks.favicon_path self.tokens = {} - self.root_path = os.environ.get("GRADIO_ROOT_PATH") or blocks.root_path + self.root_path = blocks.root_path def get_blocks(self) -> gradio.Blocks: if self.blocks is None: From 7ed7081019bc50f054be1567e7adbcf57ba93fc0 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Thu, 3 Aug 2023 15:58:33 -0400 Subject: [PATCH 4/5] fixes --- gradio/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradio/blocks.py b/gradio/blocks.py index ba28693119b72..fa0fa82ac990d 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -1690,7 +1690,7 @@ def launch( file_directories: list[str] | None = None, allowed_paths: list[str] | None = None, blocked_paths: list[str] | None = None, - root_path: str = None, + root_path: str | None = None, _frontend: bool = True, app_kwargs: dict[str, Any] | None = None, ) -> tuple[FastAPI, str, str]: From 9552ec8b288ef8243dd43410ed144bf619f3f1b7 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Thu, 3 Aug 2023 16:09:10 -0400 Subject: [PATCH 5/5] fix --- gradio/blocks.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gradio/blocks.py b/gradio/blocks.py index fa0fa82ac990d..6c7372281104e 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -1766,7 +1766,10 @@ def reverse(text): self.width = width self.favicon_path = favicon_path self.ssl_verify = ssl_verify - self.root_path = root_path or os.environ.get("GRADIO_ROOT_PATH", "") + if root_path is None: + self.root_path = os.environ.get("GRADIO_ROOT_PATH", "") + else: + self.root_path = root_path if enable_queue is not None: self.enable_queue = enable_queue