hysts HF staff commited on
Commit
84448a9
1 Parent(s): ea1552f
app.py CHANGED
@@ -21,6 +21,7 @@ from app_segmentation import create_demo as create_demo_segmentation
21
  from app_shuffle import create_demo as create_demo_shuffle
22
  from app_softedge import create_demo as create_demo_softedge
23
  from model import Model
 
24
 
25
  DESCRIPTION = '# ControlNet v1.1'
26
 
@@ -30,10 +31,6 @@ ALLOW_CHANGING_BASE_MODEL = SPACE_ID != 'hysts/ControlNet-v1-1'
30
  if not torch.cuda.is_available():
31
  DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
32
 
33
- MAX_NUM_IMAGES = int(os.getenv('MAX_NUM_IMAGES', '3'))
34
- DEFAULT_NUM_IMAGES = min(MAX_NUM_IMAGES,
35
- int(os.getenv('DEFAULT_NUM_IMAGES', '1')))
36
-
37
  DEFAULT_MODEL_ID = os.getenv('DEFAULT_MODEL_ID',
38
  'runwayml/stable-diffusion-v1-5')
39
  model = Model(base_model_id=DEFAULT_MODEL_ID, task_name='Canny')
@@ -42,58 +39,34 @@ with gr.Blocks(css='style.css') as demo:
42
  gr.Markdown(DESCRIPTION)
43
  gr.DuplicateButton(value='Duplicate Space for private use',
44
  elem_id='duplicate-button',
45
- visible=os.getenv('SHOW_DUPLICATE_BUTTON') == '1')
46
 
47
  with gr.Tabs():
48
  with gr.TabItem('Canny'):
49
- create_demo_canny(model.process_canny,
50
- max_images=MAX_NUM_IMAGES,
51
- default_num_images=DEFAULT_NUM_IMAGES)
52
  with gr.TabItem('MLSD'):
53
- create_demo_mlsd(model.process_mlsd,
54
- max_images=MAX_NUM_IMAGES,
55
- default_num_images=DEFAULT_NUM_IMAGES)
56
  with gr.TabItem('Scribble'):
57
- create_demo_scribble(model.process_scribble,
58
- max_images=MAX_NUM_IMAGES,
59
- default_num_images=DEFAULT_NUM_IMAGES)
60
  with gr.TabItem('Scribble Interactive'):
61
  create_demo_scribble_interactive(
62
- model.process_scribble_interactive,
63
- max_images=MAX_NUM_IMAGES,
64
- default_num_images=DEFAULT_NUM_IMAGES)
65
  with gr.TabItem('SoftEdge'):
66
- create_demo_softedge(model.process_softedge,
67
- max_images=MAX_NUM_IMAGES,
68
- default_num_images=DEFAULT_NUM_IMAGES)
69
  with gr.TabItem('OpenPose'):
70
- create_demo_openpose(model.process_openpose,
71
- max_images=MAX_NUM_IMAGES,
72
- default_num_images=DEFAULT_NUM_IMAGES)
73
  with gr.TabItem('Segmentation'):
74
- create_demo_segmentation(model.process_segmentation,
75
- max_images=MAX_NUM_IMAGES,
76
- default_num_images=DEFAULT_NUM_IMAGES)
77
  with gr.TabItem('Depth'):
78
- create_demo_depth(model.process_depth,
79
- max_images=MAX_NUM_IMAGES,
80
- default_num_images=DEFAULT_NUM_IMAGES)
81
  with gr.TabItem('Normal map'):
82
- create_demo_normal(model.process_normal,
83
- max_images=MAX_NUM_IMAGES,
84
- default_num_images=DEFAULT_NUM_IMAGES)
85
  with gr.TabItem('Lineart'):
86
- create_demo_lineart(model.process_lineart,
87
- max_images=MAX_NUM_IMAGES,
88
- default_num_images=DEFAULT_NUM_IMAGES)
89
  with gr.TabItem('Content Shuffle'):
90
- create_demo_shuffle(model.process_shuffle,
91
- max_images=MAX_NUM_IMAGES,
92
- default_num_images=DEFAULT_NUM_IMAGES)
93
  with gr.TabItem('Instruct Pix2Pix'):
94
- create_demo_ip2p(model.process_ip2p,
95
- max_images=MAX_NUM_IMAGES,
96
- default_num_images=DEFAULT_NUM_IMAGES)
97
 
98
  with gr.Accordion(label='Base model', open=False):
99
  with gr.Row():
 
21
  from app_shuffle import create_demo as create_demo_shuffle
22
  from app_softedge import create_demo as create_demo_softedge
23
  from model import Model
24
+ from settings import SHOW_DUPLICATE_BUTTON
25
 
26
  DESCRIPTION = '# ControlNet v1.1'
27
 
 
31
  if not torch.cuda.is_available():
32
  DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
33
 
 
 
 
 
34
  DEFAULT_MODEL_ID = os.getenv('DEFAULT_MODEL_ID',
35
  'runwayml/stable-diffusion-v1-5')
36
  model = Model(base_model_id=DEFAULT_MODEL_ID, task_name='Canny')
 
39
  gr.Markdown(DESCRIPTION)
40
  gr.DuplicateButton(value='Duplicate Space for private use',
41
  elem_id='duplicate-button',
42
+ visible=SHOW_DUPLICATE_BUTTON)
43
 
44
  with gr.Tabs():
45
  with gr.TabItem('Canny'):
46
+ create_demo_canny(model.process_canny)
 
 
47
  with gr.TabItem('MLSD'):
48
+ create_demo_mlsd(model.process_mlsd)
 
 
49
  with gr.TabItem('Scribble'):
50
+ create_demo_scribble(model.process_scribble)
 
 
51
  with gr.TabItem('Scribble Interactive'):
52
  create_demo_scribble_interactive(
53
+ model.process_scribble_interactive)
 
 
54
  with gr.TabItem('SoftEdge'):
55
+ create_demo_softedge(model.process_softedge)
 
 
56
  with gr.TabItem('OpenPose'):
57
+ create_demo_openpose(model.process_openpose)
 
 
58
  with gr.TabItem('Segmentation'):
59
+ create_demo_segmentation(model.process_segmentation)
 
 
60
  with gr.TabItem('Depth'):
61
+ create_demo_depth(model.process_depth)
 
 
62
  with gr.TabItem('Normal map'):
63
+ create_demo_normal(model.process_normal)
 
 
64
  with gr.TabItem('Lineart'):
65
+ create_demo_lineart(model.process_lineart)
 
 
66
  with gr.TabItem('Content Shuffle'):
67
+ create_demo_shuffle(model.process_shuffle)
 
 
68
  with gr.TabItem('Instruct Pix2Pix'):
69
+ create_demo_ip2p(model.process_ip2p)
 
 
70
 
71
  with gr.Accordion(label='Base model', open=False):
72
  with gr.Row():
app_canny.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -15,8 +16,8 @@ def create_demo(process, max_images=12, default_num_images=3):
15
  with gr.Accordion('Advanced options', open=False):
16
  num_samples = gr.Slider(label='Number of 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,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
16
  with gr.Accordion('Advanced options', open=False):
17
  num_samples = gr.Slider(label='Number of images',
18
  minimum=1,
19
+ maximum=MAX_NUM_IMAGES,
20
+ value=DEFAULT_NUM_IMAGES,
21
  step=1)
22
  image_resolution = gr.Slider(label='Image resolution',
23
  minimum=256,
app_depth.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -20,8 +21,8 @@ def create_demo(process, max_images=12, default_num_images=3):
20
  value='DPT')
21
  num_samples = gr.Slider(label='Number of images',
22
  minimum=1,
23
- maximum=max_images,
24
- value=default_num_images,
25
  step=1)
26
  image_resolution = gr.Slider(label='Image resolution',
27
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
21
  value='DPT')
22
  num_samples = gr.Slider(label='Number of images',
23
  minimum=1,
24
+ maximum=MAX_NUM_IMAGES,
25
+ value=DEFAULT_NUM_IMAGES,
26
  step=1)
27
  image_resolution = gr.Slider(label='Image resolution',
28
  minimum=256,
app_ip2p.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -15,8 +16,8 @@ def create_demo(process, max_images=12, default_num_images=3):
15
  with gr.Accordion('Advanced options', open=False):
16
  num_samples = gr.Slider(label='Number of 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,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
16
  with gr.Accordion('Advanced options', open=False):
17
  num_samples = gr.Slider(label='Number of images',
18
  minimum=1,
19
+ maximum=MAX_NUM_IMAGES,
20
+ value=DEFAULT_NUM_IMAGES,
21
  step=1)
22
  image_resolution = gr.Slider(label='Image resolution',
23
  minimum=256,
app_lineart.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -29,8 +30,8 @@ def create_demo(process, max_images=12, default_num_images=3):
29
  )
30
  num_samples = gr.Slider(label='Number of images',
31
  minimum=1,
32
- maximum=max_images,
33
- value=default_num_images,
34
  step=1)
35
  image_resolution = gr.Slider(label='Image resolution',
36
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
30
  )
31
  num_samples = gr.Slider(label='Number of images',
32
  minimum=1,
33
+ maximum=MAX_NUM_IMAGES,
34
+ value=DEFAULT_NUM_IMAGES,
35
  step=1)
36
  image_resolution = gr.Slider(label='Image resolution',
37
  minimum=256,
app_mlsd.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -15,8 +16,8 @@ def create_demo(process, max_images=12, default_num_images=3):
15
  with gr.Accordion('Advanced options', open=False):
16
  num_samples = gr.Slider(label='Number of 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,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
16
  with gr.Accordion('Advanced options', open=False):
17
  num_samples = gr.Slider(label='Number of images',
18
  minimum=1,
19
+ maximum=MAX_NUM_IMAGES,
20
+ value=DEFAULT_NUM_IMAGES,
21
  step=1)
22
  image_resolution = gr.Slider(label='Image resolution',
23
  minimum=256,
app_normal.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -19,8 +20,8 @@ def create_demo(process, max_images=12, default_num_images=3):
19
  value='NormalBae')
20
  num_samples = gr.Slider(label='Images',
21
  minimum=1,
22
- maximum=max_images,
23
- value=default_num_images,
24
  step=1)
25
  image_resolution = gr.Slider(label='Image resolution',
26
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
20
  value='NormalBae')
21
  num_samples = gr.Slider(label='Images',
22
  minimum=1,
23
+ maximum=MAX_NUM_IMAGES,
24
+ value=DEFAULT_NUM_IMAGES,
25
  step=1)
26
  image_resolution = gr.Slider(label='Image resolution',
27
  minimum=256,
app_openpose.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -19,8 +20,8 @@ def create_demo(process, max_images=12, default_num_images=3):
19
  value='Openpose')
20
  num_samples = gr.Slider(label='Number of images',
21
  minimum=1,
22
- maximum=max_images,
23
- value=default_num_images,
24
  step=1)
25
  image_resolution = gr.Slider(label='Image resolution',
26
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
20
  value='Openpose')
21
  num_samples = gr.Slider(label='Number of images',
22
  minimum=1,
23
+ maximum=MAX_NUM_IMAGES,
24
+ value=DEFAULT_NUM_IMAGES,
25
  step=1)
26
  image_resolution = gr.Slider(label='Image resolution',
27
  minimum=256,
app_scribble.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -20,8 +21,8 @@ def create_demo(process, max_images=12, default_num_images=3):
20
  value='HED')
21
  num_samples = gr.Slider(label='Number of images',
22
  minimum=1,
23
- maximum=max_images,
24
- value=default_num_images,
25
  step=1)
26
  image_resolution = gr.Slider(label='Image resolution',
27
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
21
  value='HED')
22
  num_samples = gr.Slider(label='Number of images',
23
  minimum=1,
24
+ maximum=MAX_NUM_IMAGES,
25
+ value=DEFAULT_NUM_IMAGES,
26
  step=1)
27
  image_resolution = gr.Slider(label='Image resolution',
28
  minimum=256,
app_scribble_interactive.py CHANGED
@@ -3,6 +3,7 @@
3
  import gradio as gr
4
  import numpy as np
5
 
 
6
  from utils import randomize_seed_fn
7
 
8
 
@@ -10,7 +11,7 @@ def create_canvas(w, h):
10
  return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
11
 
12
 
13
- def create_demo(process, max_images=12, default_num_images=3):
14
  with gr.Blocks() as demo:
15
  with gr.Row():
16
  with gr.Column():
@@ -31,8 +32,8 @@ def create_demo(process, max_images=12, default_num_images=3):
31
  with gr.Accordion('Advanced options', open=False):
32
  num_samples = gr.Slider(label='Number of images',
33
  minimum=1,
34
- maximum=max_images,
35
- value=default_num_images,
36
  step=1)
37
  image_resolution = gr.Slider(label='Image resolution',
38
  minimum=256,
 
3
  import gradio as gr
4
  import numpy as np
5
 
6
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
7
  from utils import randomize_seed_fn
8
 
9
 
 
11
  return np.zeros(shape=(h, w, 3), dtype=np.uint8) + 255
12
 
13
 
14
+ def create_demo(process):
15
  with gr.Blocks() as demo:
16
  with gr.Row():
17
  with gr.Column():
 
32
  with gr.Accordion('Advanced options', open=False):
33
  num_samples = gr.Slider(label='Number of images',
34
  minimum=1,
35
+ maximum=MAX_NUM_IMAGES,
36
+ value=DEFAULT_NUM_IMAGES,
37
  step=1)
38
  image_resolution = gr.Slider(label='Image resolution',
39
  minimum=256,
app_segmentation.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -19,8 +20,8 @@ def create_demo(process, max_images=12, default_num_images=3):
19
  value='UPerNet')
20
  num_samples = gr.Slider(label='Number of images',
21
  minimum=1,
22
- maximum=max_images,
23
- value=default_num_images,
24
  step=1)
25
  image_resolution = gr.Slider(label='Image resolution',
26
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
20
  value='UPerNet')
21
  num_samples = gr.Slider(label='Number of images',
22
  minimum=1,
23
+ maximum=MAX_NUM_IMAGES,
24
+ value=DEFAULT_NUM_IMAGES,
25
  step=1)
26
  image_resolution = gr.Slider(label='Image resolution',
27
  minimum=256,
app_shuffle.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -20,8 +21,8 @@ def create_demo(process, max_images=12, default_num_images=3):
20
  value='ContentShuffle')
21
  num_samples = gr.Slider(label='Number of images',
22
  minimum=1,
23
- maximum=max_images,
24
- value=default_num_images,
25
  step=1)
26
  image_resolution = gr.Slider(label='Image resolution',
27
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
21
  value='ContentShuffle')
22
  num_samples = gr.Slider(label='Number of images',
23
  minimum=1,
24
+ maximum=MAX_NUM_IMAGES,
25
+ value=DEFAULT_NUM_IMAGES,
26
  step=1)
27
  image_resolution = gr.Slider(label='Image resolution',
28
  minimum=256,
app_softedge.py CHANGED
@@ -2,10 +2,11 @@
2
 
3
  import gradio as gr
4
 
 
5
  from utils import randomize_seed_fn
6
 
7
 
8
- def create_demo(process, max_images=12, default_num_images=3):
9
  with gr.Blocks() as demo:
10
  with gr.Row():
11
  with gr.Column():
@@ -25,8 +26,8 @@ def create_demo(process, max_images=12, default_num_images=3):
25
  value='PidiNet')
26
  num_samples = gr.Slider(label='Number of images',
27
  minimum=1,
28
- maximum=max_images,
29
- value=default_num_images,
30
  step=1)
31
  image_resolution = gr.Slider(label='Image resolution',
32
  minimum=256,
 
2
 
3
  import gradio as gr
4
 
5
+ from settings import DEFAULT_NUM_IMAGES, MAX_NUM_IMAGES
6
  from utils import randomize_seed_fn
7
 
8
 
9
+ def create_demo(process):
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
26
  value='PidiNet')
27
  num_samples = gr.Slider(label='Number of images',
28
  minimum=1,
29
+ maximum=MAX_NUM_IMAGES,
30
+ value=DEFAULT_NUM_IMAGES,
31
  step=1)
32
  image_resolution = gr.Slider(label='Image resolution',
33
  minimum=256,
settings.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ SHOW_DUPLICATE_BUTTON = os.getenv('SHOW_DUPLICATE_BUTTON') == '1'
4
+
5
+ MAX_NUM_IMAGES = int(os.getenv('MAX_NUM_IMAGES', '3'))
6
+ DEFAULT_NUM_IMAGES = min(MAX_NUM_IMAGES,
7
+ int(os.getenv('DEFAULT_NUM_IMAGES', '1')))