Spaces:
Sleeping
Sleeping
Pedro Cuenca
commited on
Commit
·
039fd33
1
Parent(s):
d840f35
Simplify state.
Browse files
app.py
CHANGED
@@ -11,11 +11,9 @@ SELECT_LABEL = "Select as seed"
|
|
11 |
|
12 |
with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
|
13 |
state = gr.Variable({
|
14 |
-
'
|
15 |
'seeds': []
|
16 |
})
|
17 |
-
# selectors_state = [''] * 6
|
18 |
-
# seeds = []
|
19 |
|
20 |
def infer_seeded_image(prompt, seed):
|
21 |
print(f"Prompt: {prompt}, seed: {seed}")
|
@@ -41,7 +39,7 @@ with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
|
|
41 |
image_with_seed = None
|
42 |
visible = (False, False)
|
43 |
|
44 |
-
if seed_index :=
|
45 |
seed = state["seeds"][seed_index]
|
46 |
image_with_seed = infer_seeded_image(prompt, seed)
|
47 |
visible = (False, True)
|
@@ -67,22 +65,14 @@ with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
|
|
67 |
others_value = None
|
68 |
else:
|
69 |
others_value = ''
|
70 |
-
|
71 |
-
new_state[selected_index] = SELECT_LABEL
|
72 |
-
state["selectors"] = new_state
|
73 |
others = gr.Radio.update(value=others_value)
|
74 |
return [others] * 5 + [state]
|
75 |
|
76 |
-
def current_selection(state):
|
77 |
-
try:
|
78 |
-
return state["selectors"].index(SELECT_LABEL)
|
79 |
-
except:
|
80 |
-
return -1
|
81 |
-
|
82 |
def clear_seed(state):
|
83 |
"""Update state of Radio buttons, grid, seeded_box"""
|
84 |
-
state["
|
85 |
-
return
|
86 |
|
87 |
def radio_block():
|
88 |
radio = gr.Radio(
|
|
|
11 |
|
12 |
with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
|
13 |
state = gr.Variable({
|
14 |
+
'selected': -1,
|
15 |
'seeds': []
|
16 |
})
|
|
|
|
|
17 |
|
18 |
def infer_seeded_image(prompt, seed):
|
19 |
print(f"Prompt: {prompt}, seed: {seed}")
|
|
|
39 |
image_with_seed = None
|
40 |
visible = (False, False)
|
41 |
|
42 |
+
if seed_index := state["selected"] > -1:
|
43 |
seed = state["seeds"][seed_index]
|
44 |
image_with_seed = infer_seeded_image(prompt, seed)
|
45 |
visible = (False, True)
|
|
|
65 |
others_value = None
|
66 |
else:
|
67 |
others_value = ''
|
68 |
+
state["selected"] = selected_index
|
|
|
|
|
69 |
others = gr.Radio.update(value=others_value)
|
70 |
return [others] * 5 + [state]
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
def clear_seed(state):
|
73 |
"""Update state of Radio buttons, grid, seeded_box"""
|
74 |
+
state["selected"] = -1
|
75 |
+
return [''] * 6 + [gr.Box.update(visible=True), gr.Box.update(visible=False)] + [state]
|
76 |
|
77 |
def radio_block():
|
78 |
radio = gr.Radio(
|