Spaces:
Running
Running
Allow number of images to be specified with environment variable
Browse files- app.py +32 -11
- gradio_canny2image.py +2 -2
- gradio_depth2image.py +2 -2
- gradio_fake_scribble2image.py +2 -2
- gradio_hed2image.py +2 -2
- gradio_hough2image.py +2 -2
- gradio_normal2image.py +2 -2
- gradio_pose2image.py +2 -2
- gradio_scribble2image.py +2 -2
- gradio_scribble2image_interactive.py +2 -2
- gradio_seg2image.py +2 -2
app.py
CHANGED
|
@@ -43,7 +43,6 @@ from gradio_scribble2image_interactive import \
|
|
| 43 |
from gradio_seg2image import create_demo as create_demo_seg
|
| 44 |
from model import Model
|
| 45 |
|
| 46 |
-
MAX_IMAGES = 1
|
| 47 |
DESCRIPTION = '''# ControlNet
|
| 48 |
|
| 49 |
This is an unofficial demo for [https://github.com/lllyasviel/ControlNet](https://github.com/lllyasviel/ControlNet).
|
|
@@ -57,32 +56,54 @@ if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
|
| 57 |
<p/>
|
| 58 |
'''
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
model = Model()
|
| 61 |
|
| 62 |
with gr.Blocks(css='style.css') as demo:
|
| 63 |
gr.Markdown(DESCRIPTION)
|
| 64 |
with gr.Tabs():
|
| 65 |
with gr.TabItem('Canny'):
|
| 66 |
-
create_demo_canny(model.process_canny,
|
|
|
|
|
|
|
| 67 |
with gr.TabItem('Hough'):
|
| 68 |
-
create_demo_hough(model.process_hough,
|
|
|
|
|
|
|
| 69 |
with gr.TabItem('HED'):
|
| 70 |
-
create_demo_hed(model.process_hed,
|
|
|
|
|
|
|
| 71 |
with gr.TabItem('Scribble'):
|
| 72 |
-
create_demo_scribble(model.process_scribble,
|
|
|
|
|
|
|
| 73 |
with gr.TabItem('Scribble Interactive'):
|
| 74 |
create_demo_scribble_interactive(
|
| 75 |
-
model.process_scribble_interactive,
|
|
|
|
|
|
|
| 76 |
with gr.TabItem('Fake Scribble'):
|
| 77 |
create_demo_fake_scribble(model.process_fake_scribble,
|
| 78 |
-
max_images=MAX_IMAGES
|
|
|
|
| 79 |
with gr.TabItem('Pose'):
|
| 80 |
-
create_demo_pose(model.process_pose,
|
|
|
|
|
|
|
| 81 |
with gr.TabItem('Segmentation'):
|
| 82 |
-
create_demo_seg(model.process_seg,
|
|
|
|
|
|
|
| 83 |
with gr.TabItem('Depth'):
|
| 84 |
-
create_demo_depth(model.process_depth,
|
|
|
|
|
|
|
| 85 |
with gr.TabItem('Normal map'):
|
| 86 |
-
create_demo_normal(model.process_normal,
|
|
|
|
|
|
|
| 87 |
|
| 88 |
demo.queue(api_open=False).launch()
|
|
|
|
| 43 |
from gradio_seg2image import create_demo as create_demo_seg
|
| 44 |
from model import Model
|
| 45 |
|
|
|
|
| 46 |
DESCRIPTION = '''# ControlNet
|
| 47 |
|
| 48 |
This is an unofficial demo for [https://github.com/lllyasviel/ControlNet](https://github.com/lllyasviel/ControlNet).
|
|
|
|
| 56 |
<p/>
|
| 57 |
'''
|
| 58 |
|
| 59 |
+
MAX_IMAGES = int(os.getenv('MAX_IMAGES', '3'))
|
| 60 |
+
DEFAULT_NUM_IMAGES = min(MAX_IMAGES, int(os.getenv('DEFAULT_NUM_IMAGES', '1')))
|
| 61 |
+
|
| 62 |
model = Model()
|
| 63 |
|
| 64 |
with gr.Blocks(css='style.css') as demo:
|
| 65 |
gr.Markdown(DESCRIPTION)
|
| 66 |
with gr.Tabs():
|
| 67 |
with gr.TabItem('Canny'):
|
| 68 |
+
create_demo_canny(model.process_canny,
|
| 69 |
+
max_images=MAX_IMAGES,
|
| 70 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 71 |
with gr.TabItem('Hough'):
|
| 72 |
+
create_demo_hough(model.process_hough,
|
| 73 |
+
max_images=MAX_IMAGES,
|
| 74 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 75 |
with gr.TabItem('HED'):
|
| 76 |
+
create_demo_hed(model.process_hed,
|
| 77 |
+
max_images=MAX_IMAGES,
|
| 78 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 79 |
with gr.TabItem('Scribble'):
|
| 80 |
+
create_demo_scribble(model.process_scribble,
|
| 81 |
+
max_images=MAX_IMAGES,
|
| 82 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 83 |
with gr.TabItem('Scribble Interactive'):
|
| 84 |
create_demo_scribble_interactive(
|
| 85 |
+
model.process_scribble_interactive,
|
| 86 |
+
max_images=MAX_IMAGES,
|
| 87 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 88 |
with gr.TabItem('Fake Scribble'):
|
| 89 |
create_demo_fake_scribble(model.process_fake_scribble,
|
| 90 |
+
max_images=MAX_IMAGES,
|
| 91 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 92 |
with gr.TabItem('Pose'):
|
| 93 |
+
create_demo_pose(model.process_pose,
|
| 94 |
+
max_images=MAX_IMAGES,
|
| 95 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 96 |
with gr.TabItem('Segmentation'):
|
| 97 |
+
create_demo_seg(model.process_seg,
|
| 98 |
+
max_images=MAX_IMAGES,
|
| 99 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 100 |
with gr.TabItem('Depth'):
|
| 101 |
+
create_demo_depth(model.process_depth,
|
| 102 |
+
max_images=MAX_IMAGES,
|
| 103 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 104 |
with gr.TabItem('Normal map'):
|
| 105 |
+
create_demo_normal(model.process_normal,
|
| 106 |
+
max_images=MAX_IMAGES,
|
| 107 |
+
default_num_images=DEFAULT_NUM_IMAGES)
|
| 108 |
|
| 109 |
demo.queue(api_open=False).launch()
|
gradio_canny2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Canny Edge Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Canny Edge Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_depth2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Depth Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Depth Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_fake_scribble2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Fake Scribble Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Fake Scribble Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_hed2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with HED Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with HED Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_hough2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Hough Line Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Hough Line Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_normal2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Normal Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Normal Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_pose2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Human Pose')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Human Pose')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_scribble2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Scribble Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Scribble Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
gradio_scribble2image_interactive.py
CHANGED
|
@@ -8,7 +8,7 @@ def create_canvas(w, h):
|
|
| 8 |
return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
|
| 9 |
|
| 10 |
|
| 11 |
-
def create_demo(process, max_images=12):
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
with gr.Row():
|
| 14 |
gr.Markdown(
|
|
@@ -45,7 +45,7 @@ def create_demo(process, max_images=12):
|
|
| 45 |
num_samples = gr.Slider(label='Images',
|
| 46 |
minimum=1,
|
| 47 |
maximum=max_images,
|
| 48 |
-
value=
|
| 49 |
step=1)
|
| 50 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 51 |
minimum=256,
|
|
|
|
| 8 |
return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
|
| 9 |
|
| 10 |
|
| 11 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
with gr.Row():
|
| 14 |
gr.Markdown(
|
|
|
|
| 45 |
num_samples = gr.Slider(label='Images',
|
| 46 |
minimum=1,
|
| 47 |
maximum=max_images,
|
| 48 |
+
value=default_num_images,
|
| 49 |
step=1)
|
| 50 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 51 |
minimum=256,
|
gradio_seg2image.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
-
def create_demo(process, max_images=12):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Segmentation Maps')
|
|
@@ -16,7 +16,7 @@ def create_demo(process, max_images=12):
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
-
value=
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
| 6 |
+
def create_demo(process, max_images=12, default_num_images=3):
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
with gr.Row():
|
| 9 |
gr.Markdown('## Control Stable Diffusion with Segmentation Maps')
|
|
|
|
| 16 |
num_samples = gr.Slider(label='Images',
|
| 17 |
minimum=1,
|
| 18 |
maximum=max_images,
|
| 19 |
+
value=default_num_images,
|
| 20 |
step=1)
|
| 21 |
image_resolution = gr.Slider(label='Image Resolution',
|
| 22 |
minimum=256,
|