albarji commited on
Commit
ad8e498
1 Parent(s): 0ff087c

Example caching and space duplication

Browse files
Files changed (1) hide show
  1. app.py +59 -14
app.py CHANGED
@@ -5,6 +5,12 @@ from diffusers import LMSDiscreteScheduler
5
  from mixdiff import StableDiffusionCanvasPipeline, Text2ImageRegion
6
 
7
  article = """
 
 
 
 
 
 
8
  ## Motivation
9
 
10
  Current image generation methods, such as Stable Diffusion, struggle to position objects at specific locations. While the content of the generated image (somewhat) reflects the objects present in the prompt, it is difficult to frame the prompt in a way that creates an specific composition. For instance, take a prompt expressing a complex composition such as
@@ -30,12 +36,6 @@ The method proposed here strives to provide a better tool for image composition
30
 
31
  Using several diffusion processes in parallel has also practical advantages when generating very large images, as the GPU memory requirements are similar to that of generating an image of the size of a single tile.
32
 
33
- ## Usage
34
-
35
- In this demo you can use Mixture of Diffusers to configure a canvas made up of 3 diffusion regions. Play around with the prompts and guidance values in each region! You can also change increment the overlap between regions if seams appear in the image.
36
-
37
- In the full version of Mixture of Diffusers you will find further freedom to configure the regions in the canvas. Check the [github repo](https://github.com/albarji/mixture-of-diffusers)!
38
-
39
  ## Responsible use
40
 
41
  The same recommendations as in Stable Diffusion apply, so please check the corresponding [model card](https://huggingface.co/CompVis/stable-diffusion-v1-4).
@@ -44,7 +44,7 @@ More broadly speaking, always bear this in mind: YOU are responsible for the con
44
 
45
  ## Gallery
46
 
47
- Here are some relevant illustrations I have created using this software (and putting quite a few hours into them!).
48
 
49
  ### Darkness Dawning
50
 
@@ -94,19 +94,46 @@ def generate(prompt1, prompt2, prompt3, gc1, gc2, gc3, overlap, steps, seed):
94
  )["sample"][0]
95
 
96
  with gr.Blocks(title="Mixture of Diffusers") as demo:
97
- gr.Markdown("# Mixture of Diffusers")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  with gr.Row():
99
  with gr.Column(scale=1):
100
  gr.Markdown("### Left region")
101
- left_prompt = gr.Textbox(lines=2, label="Prompt")
102
  left_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
103
  with gr.Column(scale=1):
104
  gr.Markdown("### Center region")
105
- center_prompt = gr.Textbox(lines=2, label="Prompt")
106
  center_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
107
  with gr.Column(scale=1):
108
  gr.Markdown("### Right region")
109
- right_prompt = gr.Textbox(lines=2, label="Prompt")
110
  right_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
111
  gr.Markdown("### General parameters")
112
  with gr.Row():
@@ -132,11 +159,29 @@ with gr.Blocks(title="Mixture of Diffusers") as demo:
132
  50,
133
  7178915308
134
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  ],
136
  inputs=[left_prompt, center_prompt, right_prompt, left_gs, center_gs, right_gs, overlap, steps, seed],
137
- # outputs=output,
138
- # fn=generate,
139
- # cache_examples=True
140
  )
141
 
142
  button.click(
 
5
  from mixdiff import StableDiffusionCanvasPipeline, Text2ImageRegion
6
 
7
  article = """
8
+ ## Usage
9
+
10
+ In this demo you can use Mixture of Diffusers to configure a canvas made up of 3 diffusion regions. Play around with the prompts and guidance values in each region! You can also change increment the overlap between regions if seams appear in the image.
11
+
12
+ In the full version of Mixture of Diffusers you will find further freedom to configure the regions in the canvas. Check the [github repo](https://github.com/albarji/mixture-of-diffusers)!
13
+
14
  ## Motivation
15
 
16
  Current image generation methods, such as Stable Diffusion, struggle to position objects at specific locations. While the content of the generated image (somewhat) reflects the objects present in the prompt, it is difficult to frame the prompt in a way that creates an specific composition. For instance, take a prompt expressing a complex composition such as
 
36
 
37
  Using several diffusion processes in parallel has also practical advantages when generating very large images, as the GPU memory requirements are similar to that of generating an image of the size of a single tile.
38
 
 
 
 
 
 
 
39
  ## Responsible use
40
 
41
  The same recommendations as in Stable Diffusion apply, so please check the corresponding [model card](https://huggingface.co/CompVis/stable-diffusion-v1-4).
 
44
 
45
  ## Gallery
46
 
47
+ Here are some relevant illustrations created using this software (and putting quite a few hours into them!).
48
 
49
  ### Darkness Dawning
50
 
 
94
  )["sample"][0]
95
 
96
  with gr.Blocks(title="Mixture of Diffusers") as demo:
97
+ gr.HTML(
98
+ """
99
+ <div style="text-align: center; max-width: 700px; margin: 0 auto;">
100
+ <div
101
+ style="
102
+ display: inline-flex;
103
+ align-items: center;
104
+ gap: 0.8rem;
105
+ font-size: 1.75rem;
106
+ "
107
+ >
108
+ <h1 style="font-weight: 1000; margin-bottom: 7px; line-height: normal;">
109
+ Mixture of Diffusers
110
+ </h1>
111
+ </div>
112
+ <p style="margin-bottom: 10px; font-size: 94%">
113
+ <a href="https://arxiv.org/abs/2302.02412">[Paper]</a> <a href="https://github.com/albarji/mixture-of-diffusers">[Code in Github]</a> <a href="https://huggingface.co/spaces/albarji/mixture-of-diffusers?duplicate=true">
114
+ </p>
115
+ </div>
116
+ """
117
+ )
118
+ gr.HTML("""
119
+ <p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.
120
+ <br/>
121
+ <a href="https://huggingface.co/spaces/albarji/mixture-of-diffusers?duplicate=true">
122
+ <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
123
+ <p/>
124
+ """)
125
  with gr.Row():
126
  with gr.Column(scale=1):
127
  gr.Markdown("### Left region")
128
+ left_prompt = gr.Textbox(lines=2, label="Prompt (what do you want to see in the left side of the image?)")
129
  left_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
130
  with gr.Column(scale=1):
131
  gr.Markdown("### Center region")
132
+ center_prompt = gr.Textbox(lines=2, label="Prompt (what do you want to see in the center of the image?)")
133
  center_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
134
  with gr.Column(scale=1):
135
  gr.Markdown("### Right region")
136
+ right_prompt = gr.Textbox(lines=2, label="Prompt (what do you want to see in the right side of the image?)")
137
  right_gs = gr.Slider(minimum=0, maximum=15, value=8, step=1, label="Guidance scale")
138
  gr.Markdown("### General parameters")
139
  with gr.Row():
 
159
  50,
160
  7178915308
161
  ],
162
+ [
163
+ "Abstract decorative illustration, by joan miro and gustav klimt and marlina vera and loish, elegant, intricate, highly detailed, smooth, sharp focus, vibrant colors, artstation, stunning masterpiece",
164
+ "Abstract decorative illustration, by joan miro and gustav klimt and marlina vera and loish, elegant, intricate, highly detailed, smooth, sharp focus, vibrant colors, artstation, stunning masterpiece",
165
+ "Abstract decorative illustration, by joan miro and gustav klimt and marlina vera and loish, elegant, intricate, highly detailed, smooth, sharp focus, vibrant colors, artstation, stunning masterpiece",
166
+ 8, 8, 8,
167
+ 256,
168
+ 35,
169
+ 21156517
170
+ ],
171
+ [
172
+ "Magical diagrams and runes written with chalk on a blackboard, elegant, intricate, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
173
+ "Magical diagrams and runes written with chalk on a blackboard, elegant, intricate, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
174
+ "Magical diagrams and runes written with chalk on a blackboard, elegant, intricate, highly detailed, smooth, sharp focus, artstation, stunning masterpiece",
175
+ 12, 12, 12,
176
+ 256,
177
+ 35,
178
+ 12591765619
179
+ ]
180
  ],
181
  inputs=[left_prompt, center_prompt, right_prompt, left_gs, center_gs, right_gs, overlap, steps, seed],
182
+ outputs=output,
183
+ fn=generate,
184
+ cache_examples=True
185
  )
186
 
187
  button.click(