Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve how can I config root_path dynamically? #4968 #5081

Merged
merged 6 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-wolves-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:solve how can I config root_path dynamically? #4968
11 changes: 7 additions & 4 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = None,
_frontend: bool = True,
app_kwargs: dict[str, Any] | None = None,
) -> tuple[FastAPI, str, str]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
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
Expand Down