Spaces:
Running
on
Zero
Running
on
Zero
wondervictor
commited on
Commit
•
ed16792
1
Parent(s):
cbb158b
Update app_depth.py
Browse files- app_depth.py +120 -120
app_depth.py
CHANGED
@@ -1,120 +1,120 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import random
|
3 |
-
|
4 |
-
|
5 |
-
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
6 |
-
if randomize_seed:
|
7 |
-
seed = random.randint(0, 100000000)
|
8 |
-
return seed
|
9 |
-
|
10 |
-
|
11 |
-
examples = [[
|
12 |
-
"condition/example/t2i/multigen/sofa.png",
|
13 |
-
"The red sofa in the living room has several pillows on it", "(512, 512)"
|
14 |
-
],
|
15 |
-
[
|
16 |
-
"condition/example/t2i/multigen/house.jpg",
|
17 |
-
"A brick house with a chimney under a starry sky.",
|
18 |
-
"(512, 512)"
|
19 |
-
],
|
20 |
-
[
|
21 |
-
"condition/example/t2i/multi_resolution/car.jpg",
|
22 |
-
"a sport car", "(448, 768)"
|
23 |
-
]]
|
24 |
-
|
25 |
-
|
26 |
-
def create_demo(process):
|
27 |
-
with gr.Blocks() as demo:
|
28 |
-
with gr.Row():
|
29 |
-
with gr.Column():
|
30 |
-
image = gr.Image()
|
31 |
-
prompt = gr.Textbox(label="Prompt")
|
32 |
-
run_button = gr.Button("Run")
|
33 |
-
with gr.Accordion("Advanced options", open=False):
|
34 |
-
cfg_scale = gr.Slider(label="Guidance scale",
|
35 |
-
minimum=0.1,
|
36 |
-
maximum=30.0,
|
37 |
-
value=
|
38 |
-
step=0.1)
|
39 |
-
resolution = gr.Slider(label="(H, W)",
|
40 |
-
minimum=384,
|
41 |
-
maximum=768,
|
42 |
-
value=512,
|
43 |
-
step=16)
|
44 |
-
top_k = gr.Slider(minimum=1,
|
45 |
-
maximum=16384,
|
46 |
-
step=1,
|
47 |
-
value=2000,
|
48 |
-
label='Top-K')
|
49 |
-
top_p = gr.Slider(minimum=0.,
|
50 |
-
maximum=1.0,
|
51 |
-
step=0.1,
|
52 |
-
value=1.0,
|
53 |
-
label="Top-P")
|
54 |
-
temperature = gr.Slider(minimum=0.,
|
55 |
-
maximum=1.0,
|
56 |
-
step=0.1,
|
57 |
-
value=1.0,
|
58 |
-
label='Temperature')
|
59 |
-
seed = gr.Slider(label="Seed",
|
60 |
-
minimum=0,
|
61 |
-
maximum=100000000,
|
62 |
-
step=1,
|
63 |
-
value=0)
|
64 |
-
randomize_seed = gr.Checkbox(label="Randomize seed",
|
65 |
-
value=True)
|
66 |
-
with gr.Column():
|
67 |
-
result = gr.Gallery(label="Output",
|
68 |
-
show_label=False,
|
69 |
-
height='800px',
|
70 |
-
columns=2,
|
71 |
-
object_fit="scale-down")
|
72 |
-
gr.Examples(
|
73 |
-
examples=examples,
|
74 |
-
inputs=[
|
75 |
-
image,
|
76 |
-
prompt,
|
77 |
-
resolution,
|
78 |
-
]
|
79 |
-
)
|
80 |
-
inputs = [
|
81 |
-
image,
|
82 |
-
prompt,
|
83 |
-
cfg_scale,
|
84 |
-
temperature,
|
85 |
-
top_k,
|
86 |
-
top_p,
|
87 |
-
seed,
|
88 |
-
]
|
89 |
-
prompt.submit(
|
90 |
-
fn=randomize_seed_fn,
|
91 |
-
inputs=[seed, randomize_seed],
|
92 |
-
outputs=seed,
|
93 |
-
queue=False,
|
94 |
-
api_name=False,
|
95 |
-
).then(
|
96 |
-
fn=process,
|
97 |
-
inputs=inputs,
|
98 |
-
outputs=result,
|
99 |
-
api_name=False,
|
100 |
-
)
|
101 |
-
run_button.click(
|
102 |
-
fn=randomize_seed_fn,
|
103 |
-
inputs=[seed, randomize_seed],
|
104 |
-
outputs=seed,
|
105 |
-
queue=False,
|
106 |
-
api_name=False,
|
107 |
-
).then(
|
108 |
-
fn=process,
|
109 |
-
inputs=inputs,
|
110 |
-
outputs=result,
|
111 |
-
api_name="canny",
|
112 |
-
)
|
113 |
-
return demo
|
114 |
-
|
115 |
-
|
116 |
-
if __name__ == "__main__":
|
117 |
-
from model import Model
|
118 |
-
model = Model()
|
119 |
-
demo = create_demo(model.process_depth)
|
120 |
-
demo.queue().launch(share=False, server_name="0.0.0.0")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
|
5 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
6 |
+
if randomize_seed:
|
7 |
+
seed = random.randint(0, 100000000)
|
8 |
+
return seed
|
9 |
+
|
10 |
+
|
11 |
+
examples = [[
|
12 |
+
"condition/example/t2i/multigen/sofa.png",
|
13 |
+
"The red sofa in the living room has several pillows on it", "(512, 512)"
|
14 |
+
],
|
15 |
+
[
|
16 |
+
"condition/example/t2i/multigen/house.jpg",
|
17 |
+
"A brick house with a chimney under a starry sky.",
|
18 |
+
"(512, 512)"
|
19 |
+
],
|
20 |
+
[
|
21 |
+
"condition/example/t2i/multi_resolution/car.jpg",
|
22 |
+
"a sport car", "(448, 768)"
|
23 |
+
]]
|
24 |
+
|
25 |
+
|
26 |
+
def create_demo(process):
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
image = gr.Image()
|
31 |
+
prompt = gr.Textbox(label="Prompt")
|
32 |
+
run_button = gr.Button("Run")
|
33 |
+
with gr.Accordion("Advanced options", open=False):
|
34 |
+
cfg_scale = gr.Slider(label="Guidance scale",
|
35 |
+
minimum=0.1,
|
36 |
+
maximum=30.0,
|
37 |
+
value=2,
|
38 |
+
step=0.1)
|
39 |
+
resolution = gr.Slider(label="(H, W)",
|
40 |
+
minimum=384,
|
41 |
+
maximum=768,
|
42 |
+
value=512,
|
43 |
+
step=16)
|
44 |
+
top_k = gr.Slider(minimum=1,
|
45 |
+
maximum=16384,
|
46 |
+
step=1,
|
47 |
+
value=2000,
|
48 |
+
label='Top-K')
|
49 |
+
top_p = gr.Slider(minimum=0.,
|
50 |
+
maximum=1.0,
|
51 |
+
step=0.1,
|
52 |
+
value=1.0,
|
53 |
+
label="Top-P")
|
54 |
+
temperature = gr.Slider(minimum=0.,
|
55 |
+
maximum=1.0,
|
56 |
+
step=0.1,
|
57 |
+
value=1.0,
|
58 |
+
label='Temperature')
|
59 |
+
seed = gr.Slider(label="Seed",
|
60 |
+
minimum=0,
|
61 |
+
maximum=100000000,
|
62 |
+
step=1,
|
63 |
+
value=0)
|
64 |
+
randomize_seed = gr.Checkbox(label="Randomize seed",
|
65 |
+
value=True)
|
66 |
+
with gr.Column():
|
67 |
+
result = gr.Gallery(label="Output",
|
68 |
+
show_label=False,
|
69 |
+
height='800px',
|
70 |
+
columns=2,
|
71 |
+
object_fit="scale-down")
|
72 |
+
gr.Examples(
|
73 |
+
examples=examples,
|
74 |
+
inputs=[
|
75 |
+
image,
|
76 |
+
prompt,
|
77 |
+
resolution,
|
78 |
+
]
|
79 |
+
)
|
80 |
+
inputs = [
|
81 |
+
image,
|
82 |
+
prompt,
|
83 |
+
cfg_scale,
|
84 |
+
temperature,
|
85 |
+
top_k,
|
86 |
+
top_p,
|
87 |
+
seed,
|
88 |
+
]
|
89 |
+
prompt.submit(
|
90 |
+
fn=randomize_seed_fn,
|
91 |
+
inputs=[seed, randomize_seed],
|
92 |
+
outputs=seed,
|
93 |
+
queue=False,
|
94 |
+
api_name=False,
|
95 |
+
).then(
|
96 |
+
fn=process,
|
97 |
+
inputs=inputs,
|
98 |
+
outputs=result,
|
99 |
+
api_name=False,
|
100 |
+
)
|
101 |
+
run_button.click(
|
102 |
+
fn=randomize_seed_fn,
|
103 |
+
inputs=[seed, randomize_seed],
|
104 |
+
outputs=seed,
|
105 |
+
queue=False,
|
106 |
+
api_name=False,
|
107 |
+
).then(
|
108 |
+
fn=process,
|
109 |
+
inputs=inputs,
|
110 |
+
outputs=result,
|
111 |
+
api_name="canny",
|
112 |
+
)
|
113 |
+
return demo
|
114 |
+
|
115 |
+
|
116 |
+
if __name__ == "__main__":
|
117 |
+
from model import Model
|
118 |
+
model = Model()
|
119 |
+
demo = create_demo(model.process_depth)
|
120 |
+
demo.queue().launch(share=False, server_name="0.0.0.0")
|