File tree 8 files changed +27
-12
lines changed
js/app/src/routes/[...catchall]
8 files changed +27
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @gradio/client " : minor
3
+ " @self/app " : minor
4
+ " gradio " : minor
5
+ ---
6
+
7
+ feat:[ ZeroGPU] Handshake-based postMessage
Original file line number Diff line number Diff line change @@ -7,5 +7,6 @@ declare global {
7
7
gradio_api_info : ApiInfo < ApiData > | { api : ApiInfo < ApiData > } ;
8
8
__is_colab__ : boolean ;
9
9
__gradio_space__ : string | null ;
10
+ supports_zerogpu_headers ?: boolean ;
10
11
}
11
12
}
Original file line number Diff line number Diff line change @@ -254,7 +254,6 @@ export interface Dependency {
254
254
trigger_mode : "once" | "multiple" | "always_last" ;
255
255
final_event : Payload | null ;
256
256
show_api : boolean ;
257
- zerogpu ?: boolean ;
258
257
rendered_in : number | null ;
259
258
connection : "stream" | "sse" ;
260
259
time_limit : number ;
Original file line number Diff line number Diff line change @@ -566,15 +566,14 @@ export function submit(
566
566
? `https://moon-${ hostname . split ( "." ) [ 1 ] } .${ hfhubdev } `
567
567
: `https://huggingface.co` ;
568
568
569
- const is_iframe =
569
+ const is_zerogpu_iframe =
570
570
typeof window !== "undefined" &&
571
571
typeof document !== "undefined" &&
572
- window . parent != window ;
573
- const is_zerogpu_space = dependency . zerogpu && config . space_id ;
574
- const zerogpu_auth_promise =
575
- is_iframe && is_zerogpu_space
576
- ? post_message < Headers > ( "zerogpu-headers" , origin )
577
- : Promise . resolve ( null ) ;
572
+ window . parent != window &&
573
+ window . supports_zerogpu_headers ;
574
+ const zerogpu_auth_promise = is_zerogpu_iframe
575
+ ? post_message < Map < string , string > > ( "zerogpu-headers" , origin )
576
+ : Promise . resolve ( null ) ;
578
577
const post_data_promise = zerogpu_auth_promise . then ( ( headers ) => {
579
578
return post_data (
580
579
`${ config . root } ${ api_prefix } /${ SSE_DATA_URL } ?${ url_params } ` ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ declare global {
12
12
parentIFrame ?: {
13
13
scrollTo : ( x : number , y : number ) => void ;
14
14
} ;
15
+ supports_zerogpu_headers ?: boolean ;
15
16
}
16
17
}
17
18
Original file line number Diff line number Diff line change @@ -547,7 +547,6 @@ def __init__(
547
547
self .queue = False if fn is None else queue
548
548
self .scroll_to_output = False if utils .get_space () else scroll_to_output
549
549
self .show_api = show_api
550
- self .zero_gpu = hasattr (self .fn , "zerogpu" )
551
550
self .types_generator = inspect .isgeneratorfunction (
552
551
self .fn
553
552
) or inspect .isasyncgenfunction (self .fn )
@@ -608,7 +607,6 @@ def get_config(self):
608
607
"trigger_only_on_success" : self .trigger_only_on_success ,
609
608
"trigger_mode" : self .trigger_mode ,
610
609
"show_api" : self .show_api ,
611
- "zerogpu" : self .zero_gpu ,
612
610
"rendered_in" : self .rendered_in ._id if self .rendered_in else None ,
613
611
"connection" : self .connection ,
614
612
"time_limit" : self .time_limit ,
Original file line number Diff line number Diff line change @@ -500,8 +500,6 @@ def _setup_events(self) -> None:
500
500
501
501
submit_triggers = [self .textbox .submit , self .chatbot .retry ]
502
502
submit_fn = self ._stream_fn if self .is_generator else self ._submit_fn
503
- if hasattr (self .fn , "zerogpu" ):
504
- submit_fn .__func__ .zerogpu = self .fn .zerogpu # type: ignore
505
503
506
504
synchronize_chat_state_kwargs = {
507
505
"fn" : lambda x : x ,
Original file line number Diff line number Diff line change 215
215
css_ready = true ;
216
216
window .__is_colab__ = config .is_colab ;
217
217
218
+ const supports_zerogpu_headers = " supports-zerogpu-headers" ;
219
+ window .addEventListener (" message" , (event ) => {
220
+ if (event .data === supports_zerogpu_headers ) {
221
+ window .supports_zerogpu_headers = true ;
222
+ }
223
+ });
224
+ const hostname = window .location .hostname ;
225
+ const origin = hostname .includes (" .dev." )
226
+ ? ` https://moon-${hostname .split (" ." )[1 ]}.dev.spaces.huggingface.tech `
227
+ : ` https://huggingface.co ` ;
228
+ window .parent .postMessage (supports_zerogpu_headers , origin );
229
+
218
230
dispatch (" loaded" );
219
231
220
232
if (config .dev_mode ) {
You can’t perform that action at this time.
0 commit comments