-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix ZeroGPU handling for gr.Server
#13210
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8727511
changes
abidlabs a8c640b
add changeset
gradio-pr-bot eae3ef3
changes
abidlabs b45975d
add changeset
gradio-pr-bot 73b3b0e
Merge branch 'main' into server-zerogpu
abidlabs 0fcac1f
Merge branch 'main' into server-zerogpu
abidlabs b99857c
Merge branch 'main' into server-zerogpu
abidlabs bfb5587
changes
abidlabs 1f0477a
changes
abidlabs 4616f04
Merge branch 'main' into server-zerogpu
abidlabs 92a604c
changes
abidlabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@gradio/client": patch | ||
| "@self/app": patch | ||
| "@self/spa": patch | ||
| "gradio": patch | ||
| --- | ||
|
|
||
| fix:Fix ZeroGPU handling for `gr.Server` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| const ZEROGPU_HEADERS_MESSAGE = "supports-zerogpu-headers"; | ||
|
|
||
| let zerogpu_handshake_initialized = false; | ||
|
|
||
| function supports_browser_handshake(): boolean { | ||
| return ( | ||
| typeof window !== "undefined" && | ||
| typeof document !== "undefined" && | ||
| typeof window.addEventListener === "function" | ||
| ); | ||
| } | ||
|
|
||
| export function get_zerogpu_origin(hostname: string): string | null { | ||
| if (hostname.includes(".dev.")) { | ||
| return `https://moon-${hostname.split(".")[1]}.dev.spaces.huggingface.tech`; | ||
| } | ||
| if (hostname.endsWith(".hf.space")) { | ||
| return "https://huggingface.co"; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export function initialize_zerogpu_handshake(): void { | ||
| if (!supports_browser_handshake() || zerogpu_handshake_initialized) { | ||
| return; | ||
| } | ||
|
|
||
| window.addEventListener("message", (event) => { | ||
| if (event.data === ZEROGPU_HEADERS_MESSAGE) { | ||
| window.supports_zerogpu_headers = true; | ||
| } | ||
| }); | ||
|
|
||
| zerogpu_handshake_initialized = true; | ||
|
|
||
| const origin = get_zerogpu_origin(window.location.hostname); | ||
| if (origin && window.parent !== window) { | ||
| window.parent.postMessage(ZEROGPU_HEADERS_MESSAGE, origin); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this happening here?
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.
Where else could it go? I put it module init because it needs to finish before the first user request. Otherwise that first request can race the iframe auth handshake and not include the forwarded headers.
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 was thinking it'd go in submit.ts or the client init. But let me know if I'm misunderstanding!
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 don't think we should put it in submit.ts because either we'd have to block until we have the headers or it might not get the headers quickly enough. We could do it in Client init I think (happy to move it there), but this is the closest to what we had previously (when we had it happen as part of the page initialization itself)
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 let's keep as is then! But it's also currently being called in submit.ts. Is it intentional?
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 that seems unnecessary, will remove
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.
Didn't see this sorry.
I'd put this in Client init, that way user has some control over when it gets called. As it is, this would fire as soon as the module is imported and means that the entire module has side-effects which can cause issues when bundling.