File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import gradio as gr
2+
3+ def print_message (n ):
4+ return "Welcome! This page has loaded for " + n
5+
6+ with gr .Blocks () as demo :
7+ t = gr .Textbox ("Frank" , label = "Name" )
8+ t2 = gr .Textbox (label = "Output" )
9+ demo .load (print_message , t , t2 )
10+
11+
12+ if __name__ == "__main__" :
13+ demo .launch ()
Original file line number Diff line number Diff line change 2424 }
2525
2626 interface Dependency {
27- trigger: " click " | " change " ;
27+ trigger: string ;
2828 targets: Array <number >;
29- inputs: Array <string >;
30- outputs: Array <string >;
29+ inputs: Array <number >;
30+ outputs: Array <number >;
3131 queue: boolean ;
3232 }
3333
121121 instance_map [t ]
122122 ]);
123123
124+ // page events
125+ if (
126+ targets .length === 0 &&
127+ ! handled_dependencies [i ]?.includes (- 1 ) &&
128+ trigger === " load" &&
129+ // check all input + output elements are on the page
130+ outputs .every ((v ) => instance_map [v ].instance ) &&
131+ inputs .every ((v ) => instance_map [v ].instance )
132+ ) {
133+ fn (
134+ " predict" ,
135+ {
136+ fn_index: i ,
137+ data: inputs .map ((id ) => instance_map [id ].value )
138+ },
139+ queue ,
140+ () => {}
141+ ).then ((output ) => {
142+ output .data .forEach ((value , i ) => {
143+ instance_map [outputs [i ]].value = value ;
144+ });
145+ });
146+
147+ handled_dependencies [i ] = [- 1 ];
148+ }
149+
124150 target_instances .forEach (([id , { instance }]: [number , Instance ]) => {
125151 // console.log(id, handled_dependencies[i]?.includes(id) || !instance);
126152 if (handled_dependencies [i ]?.includes (id ) || ! instance ) return ;
You can’t perform that action at this time.
0 commit comments