m3g4p0p commited on
Commit
ced082c
·
1 Parent(s): 0894424

add chained events

Browse files
Files changed (1) hide show
  1. myapp/app.py +13 -13
myapp/app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from pathlib import Path
2
  from tempfile import NamedTemporaryFile
3
  from typing import Any
@@ -24,26 +25,25 @@ with gr.Blocks() as demo:
24
  text = gr.Textbox(
25
  "https://wheelingvultures.bandcamp.com/album/ep", label="Text"
26
  )
27
- prompt = gr.TextArea("A vulture in black and white", label="Prompt")
28
  button = gr.Button("Generate")
29
  with gr.Column():
30
  background = gr.Image(visible=False, type="filepath")
31
  scale = gr.Slider(3, 15, 9, step=1, label="Scale")
32
  output = gr.Image()
33
 
34
- @gr.on(
35
- triggers=[button.click, prompt.submit],
 
 
 
 
36
  inputs=prompt,
37
- outputs=[button, background],
 
 
 
38
  )
39
- def generate_background(prompt):
40
- yield gr.update(interactive=False), None
41
- response = None
42
-
43
- try:
44
- response = client.text_to_image(prompt, width=400, height=400)
45
- finally:
46
- yield gr.update(interactive=True), response
47
 
48
  @gr.on(
49
  triggers=[text.submit, background.change, scale.change],
@@ -51,7 +51,7 @@ with gr.Blocks() as demo:
51
  outputs=output,
52
  )
53
  def generate_code(data: dict[Component, Any]):
54
- if data[background] is None:
55
  return None
56
 
57
  qr_code = segno.make(data[text], error="h")
 
1
+ from functools import partial
2
  from pathlib import Path
3
  from tempfile import NamedTemporaryFile
4
  from typing import Any
 
25
  text = gr.Textbox(
26
  "https://wheelingvultures.bandcamp.com/album/ep", label="Text"
27
  )
28
+ prompt = gr.TextArea("A psychedelic vulture", label="Prompt")
29
  button = gr.Button("Generate")
30
  with gr.Column():
31
  background = gr.Image(visible=False, type="filepath")
32
  scale = gr.Slider(3, 15, 9, step=1, label="Scale")
33
  output = gr.Image()
34
 
35
+ gr.on(
36
+ [button.click, prompt.submit],
37
+ partial(gr.update, interactive=False),
38
+ outputs=button,
39
+ ).then(
40
+ partial(client.text_to_image, width=400, height=400),
41
  inputs=prompt,
42
+ outputs=background,
43
+ ).then(
44
+ partial(gr.update, interactive=True),
45
+ outputs=button,
46
  )
 
 
 
 
 
 
 
 
47
 
48
  @gr.on(
49
  triggers=[text.submit, background.change, scale.change],
 
51
  outputs=output,
52
  )
53
  def generate_code(data: dict[Component, Any]):
54
+ if data.get(background) is None:
55
  return None
56
 
57
  qr_code = segno.make(data[text], error="h")