radames commited on
Commit
684a7eb
1 Parent(s): 9a942f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -16,13 +16,25 @@ get_window_url_params = """
16
  return [text_input, url_params];
17
  }
18
  """
 
 
 
 
 
 
 
 
19
  with block:
20
  url_params = gr.JSON({}, visible=True, label="URL Params")
21
  text_input = gr.Text(label="Input")
22
  text_output = gr.Text(label="Output")
23
 
24
- btn = gr.Button("Run")
25
  btn.click(fn=predict, inputs=[text_input, url_params],
26
  outputs=[text_output, url_params], _js=get_window_url_params)
27
 
 
 
 
 
28
  block.launch(debug=True)
 
16
  return [text_input, url_params];
17
  }
18
  """
19
+ set_window_url_params = """
20
+ function(text_input, url_params) {
21
+ const state = {text_input:text_input}
22
+ const queryString = '?' + new URLSearchParams(state).toString();
23
+ window.postMessage({ queryString: queryString }, "*")
24
+ return [text_input, state];
25
+ }
26
+ """
27
  with block:
28
  url_params = gr.JSON({}, visible=True, label="URL Params")
29
  text_input = gr.Text(label="Input")
30
  text_output = gr.Text(label="Output")
31
 
32
+ btn = gr.Button("Get Params")
33
  btn.click(fn=predict, inputs=[text_input, url_params],
34
  outputs=[text_output, url_params], _js=get_window_url_params)
35
 
36
+ btn2 = gr.Button("Set Params")
37
+ btn2.click(fn=predict, inputs=[text_input, url_params],
38
+ outputs=[text_output, url_params], _js=set_window_url_params)
39
+
40
  block.launch(debug=True)