julien-c HF staff commited on
Commit
20649e6
1 Parent(s): 53c37b5

Use `demo.run_forever` from @freddy

Browse files
Files changed (1) hide show
  1. app.py +3 -26
app.py CHANGED
@@ -8,24 +8,9 @@ CUSTOM_CSS = """
8
  #output_box textarea {
9
  font-family: IBM Plex Mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
10
  }
11
- #run_button {
12
- visibility: hidden;
13
- }
14
  """
15
 
16
- CUSTOM_JS_ON_LOAD = """
17
- async () => {
18
- console.log("page.load");
19
- window.itv = setInterval(() => {
20
- const root = document.querySelector('body > gradio-app').shadowRoot || document.querySelector('body > gradio-app');
21
- // ≠ in local or in Spaces for some reason
22
- const btn = root.querySelector("#run_button");
23
- btn.click();
24
- }, 1000);
25
- // otherwise JS error
26
- return [];
27
- }
28
- """
29
 
30
 
31
  def run():
@@ -69,18 +54,10 @@ with gr.Blocks(css=CUSTOM_CSS) as demo:
69
  inputs=[custom_command, secret],
70
  outputs=output,
71
  )
72
- custom_command_btn.click(
73
- fn=None,
74
- inputs=[],
75
- outputs=[],
76
- _js="(...args) => { console.log('itv', window.itv, args); clearInterval(window.itv); return args; }",
77
- )
78
 
79
  output.render()
80
 
81
- run_btn = gr.Button("Run", elem_id="run_button")
82
- run_btn.click(fn=run, inputs=[], outputs=output)
83
- demo.load(_js=CUSTOM_JS_ON_LOAD)
84
 
85
 
86
- demo.launch()
 
8
  #output_box textarea {
9
  font-family: IBM Plex Mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
10
  }
 
 
 
11
  """
12
 
13
+
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
 
16
  def run():
 
54
  inputs=[custom_command, secret],
55
  outputs=output,
56
  )
 
 
 
 
 
 
57
 
58
  output.render()
59
 
60
+ demo.run_forever(fn=run, inputs=None, outputs=output, every=1 * gr.Time.seconds)
 
 
61
 
62
 
63
+ demo.queue().launch()