Pedro Cuenca commited on
Commit
cd29368
·
0 Parent(s):

Fake outputs, radio button selection.

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .DS_Store
2
+ __pycache__/
app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ import os
4
+ import random
5
+ from typing import List
6
+ import gradio as gr
7
+ from collections import defaultdict
8
+ from functools import partial
9
+ from PIL import Image
10
+
11
+ block = gr.Blocks(css=".container { max-width: 800px; margin: auto; }")
12
+
13
+ SELECT_LABEL = "Select as seed"
14
+ selectors: List[gr.Radio] = []
15
+
16
+ def infer(prompt):
17
+ print(f"Current selection: {current_selection()}")
18
+ response = defaultdict(list)
19
+ for i in range(1, 7):
20
+ response["images"].append(Image.open(f"sample_outputs/{i}.png"))
21
+ response["seeds"].append(random.randint(0, 2 ** 32 -1))
22
+ image1.value = response["images"][0]
23
+ return response["images"]
24
+
25
+
26
+ def image_block():
27
+ return gr.Image(
28
+ interactive=False, show_label=False
29
+ ).style(
30
+ # border = (True, True, False, True),
31
+ rounded = (True, True, False, False),
32
+ )
33
+
34
+ selectors_state = [''] * 6
35
+ def did_select(radio: gr.Radio):
36
+ new_state = list(map(lambda r: SELECT_LABEL if r == radio else '', selectors))
37
+ return new_state
38
+
39
+ def update_state(radio: gr.Radio, *state):
40
+ global selectors_state
41
+ if list(state) != selectors_state:
42
+ selectors_state = did_select(radio)
43
+ return selectors_state
44
+
45
+ def current_selection():
46
+ try:
47
+ return selectors_state.index(SELECT_LABEL)
48
+ except:
49
+ return -1
50
+
51
+ def radio_block():
52
+ radio = gr.Radio(
53
+ choices=[SELECT_LABEL], interactive=True, show_label=False,
54
+ ).style(
55
+ # border = (False, True, True, True),
56
+ # rounded = (False, False, True, True)
57
+ container=False
58
+ )
59
+ return radio
60
+
61
+ with block:
62
+ gr.Markdown("<h1><center>Latent Diffusion Demo</center></h1>")
63
+ with gr.Group():
64
+ with gr.Box():
65
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
66
+ text = gr.Textbox(
67
+ label="Enter your prompt", show_label=False, max_lines=1
68
+ ).style(
69
+ border=(True, False, True, True),
70
+ # margin=False,
71
+ rounded=(True, False, False, True),
72
+ container=False,
73
+ )
74
+ btn = gr.Button("Run").style(
75
+ margin=False,
76
+ rounded=(False, True, True, False),
77
+ )
78
+
79
+ ## Can we create a Component with these, so it can participate as an output?
80
+ with gr.Row():
81
+ with gr.Box().style(border=None):
82
+ image1 = image_block()
83
+ select1 = radio_block()
84
+ with gr.Box().style(border=None):
85
+ image2 = image_block()
86
+ select2 = radio_block()
87
+ with gr.Box().style(border=None):
88
+ image3 = image_block()
89
+ select3 = radio_block()
90
+ with gr.Row():
91
+ with gr.Box().style(border=None):
92
+ image4 = image_block()
93
+ select4 = radio_block()
94
+ with gr.Box().style(border=None):
95
+ image5 = image_block()
96
+ select5 = radio_block()
97
+ with gr.Box().style(border=None):
98
+ image6 = image_block()
99
+ select6 = radio_block()
100
+
101
+ images = [image1, image2, image3, image4, image5, image6]
102
+ selectors += [select1, select2, select3, select4, select5, select6]
103
+
104
+ for radio in selectors:
105
+ radio.change(fn=partial(update_state, radio), inputs=selectors, outputs=selectors)
106
+
107
+ text.submit(infer, inputs=text, outputs=images)
108
+ btn.click(infer, inputs=text, outputs=images)
109
+
110
+ block.launch(enable_queue=False)
sample_outputs/1.png ADDED
sample_outputs/2.png ADDED
sample_outputs/3.png ADDED
sample_outputs/4.png ADDED
sample_outputs/5.png ADDED
sample_outputs/6.png ADDED