-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Ssr part 2 #9339
base: 5.0-dev
Are you sure you want to change the base?
Ssr part 2 #9339
Conversation
gradio/blocks.py
Outdated
self.node_port = None | ||
|
||
if not Blocks.node_process: | ||
(node_server_name, node_process, node_port) = start_node_server( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than starting node in init, we can do in startup_events
method of gr.Blocks
. That way, if you're nesting multiple blocks in a single app, only one node process is started.
And startup_events
runs even when mounted in a larger FastAPI app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think we're only going to start one node process anyways with this implementation since we're attaching it to the class but I still think startup_events
is a bit cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah @abidlabs suggested that but we can't do it there if i remember from my testing because we need to know certain details before mounting the gradio app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to change it in another PR if i'm wrong, i just don't have time to test it atm, the process does only start once tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i might be wrong actually but I'd need to test
This is now resolved, nice @pngwn! |
Btw two quick suggestions for the DX: (1) I highly recommend renaming (2) I think its far more intuitive for this parameter to live in |
|
||
print("Unable to find node install path, falling back to SPA mode.") | ||
print( | ||
"If you wish to use the node backend, please install node 18 and/ or set the path with the GRADIO_NODE_PATH environment variable." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have node 20 installed and ssr works. Should this print statement be modified or are we lucky that it works with node 20?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should change it to 18+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pngwn awesome PR!
Left a couple of suggestions but will keep on testing. Bigger comments though:
SSR seems to apply different styles than non-ssr mode. For example the Error toast takes up the whole width:
And here is a side-by-side of the same app in ssr and non-ssr mode
Everything is stretched out horizontally.
Additionally, SSR mode does not respect my dark mode system setting and it does not respect the ?__theme
query parameter either.
gradio/node_server.py
Outdated
|
||
node_process = subprocess.Popen( | ||
[node_path, SSR_APP_PATH], | ||
# stdout=subprocess.PIPE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: delete
gradio/routes.py
Outdated
node_port: int, | ||
python_port: int, | ||
) -> Response: | ||
client = httpx.AsyncClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can create one client at the top level of the file and re-use it. It may even be better performance as it will use http connection pooling: https://www.python-httpx.org/advanced/clients/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that but it was erroring that i can't use a closed client or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait thats because of the with
usage, if i change that, it will work.
TYSM @pngwn, I can now confirm that I am able to build multiple demos successfully on the Windows machine, both with and without specifying |
Regarding 2, I'm not sure if we can. I think we create the app really early on and I need to know whether to attach the middleware when we create the app but I'll check. |
Let me see if I can put together a PR with my suggestions Edit: PR ready here: #9399 |
Fixing the issue around share links is more interesting. It appears to be a CORS issue since access to localhost links is blocked from external links, including gradio.live links, which would be an easy fix. But I actually think there's a deeper issue, which is that xxxx.gradio.live links are trying to fetch the config from a user's localhost url instead of using the relative xxxx.gradio.live/config url. Happy to sync with you on this afterwards @pngwn but I don't think its a blocker for the beta release |
Ah. The app just uses whatever the 'api' is listed as to get those links. Can sync later. |
Python unit tests should be passing now |
Description
Please include a concise summary, in clear English, of the changes in this pull request. If it closes an issue, please mention it here.
Closes: #(issue)
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh