Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -236,21 +236,24 @@ def inference(source_prompt, target_prompt, source_guidance_scale=1, guidance_sc
|
|
236 |
img = img.resize((int(img.width * ratio), int(img.height * ratio)))
|
237 |
|
238 |
# create the CAC controller.
|
239 |
-
|
240 |
-
if cross_attention_control == "replace":
|
241 |
controller = AttentionReplace([source_prompt, target_prompt],
|
242 |
num_inference_steps,
|
243 |
cross_replace_steps=cross_replace_steps,
|
244 |
self_replace_steps=self_replace_steps,
|
245 |
)
|
246 |
ptp_utils.register_attention_control(pipe, controller)
|
247 |
-
elif cross_attention_control == "
|
248 |
controller = AttentionRefine([source_prompt, target_prompt],
|
249 |
num_inference_steps,
|
250 |
cross_replace_steps=cross_replace_steps,
|
251 |
self_replace_steps=self_replace_steps,
|
252 |
)
|
253 |
ptp_utils.register_attention_control(pipe, controller)
|
|
|
|
|
|
|
|
|
254 |
|
255 |
results = pipe(prompt=target_prompt,
|
256 |
source_prompt=source_prompt,
|
@@ -286,7 +289,24 @@ with gr.Blocks(css=css) as demo:
|
|
286 |
CycleDiffusion (<a href="https://arxiv.org/abs/2210.05559">π Paper link</a> | <a href="https://huggingface.co/docs/diffusers/main/en/api/pipelines/cycle_diffusion">𧨠Pipeline doc</a>) is an image-to-image translation method that supports stochastic samplers for diffusion models. <br>
|
287 |
It also supports Cross Attention Control (<a href="https://arxiv.org/abs/2208.01626">π Paper link</a>), which is a technique to transfer the attention map from the source prompt to the target prompt. <br>
|
288 |
</p>
|
289 |
-
<p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
Running on <b>{device_print}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
|
291 |
</p>
|
292 |
</div>
|
@@ -317,17 +337,6 @@ with gr.Blocks(css=css) as demo:
|
|
317 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0.5, maximum=1, step=0.01)
|
318 |
with gr.Row():
|
319 |
generate1 = gr.Button(value="Edit")
|
320 |
-
with gr.Tab("Basic options"):
|
321 |
-
with gr.Group():
|
322 |
-
with gr.Row():
|
323 |
-
num_inference_steps = gr.Slider(label="Number of inference steps", value=100, minimum=25, maximum=500, step=1)
|
324 |
-
width = gr.Slider(label="Width", value=512, minimum=64, maximum=1024, step=8)
|
325 |
-
height = gr.Slider(label="Height", value=512, minimum=64, maximum=1024, step=8)
|
326 |
-
|
327 |
-
with gr.Row():
|
328 |
-
seed = gr.Slider(0, 2147483647, label='Seed', value=0, step=1)
|
329 |
-
with gr.Row():
|
330 |
-
generate2 = gr.Button(value="Edit")
|
331 |
|
332 |
with gr.Tab("CAC options"):
|
333 |
with gr.Group():
|
@@ -337,6 +346,18 @@ with gr.Blocks(css=css) as demo:
|
|
337 |
# If not "None", the following two parameters will be used.
|
338 |
cross_replace_steps = gr.Slider(label="Cross replace steps", value=0.8, minimum=0.0, maximum=1, step=0.01)
|
339 |
self_replace_steps = gr.Slider(label="Self replace steps", value=0.4, minimum=0.0, maximum=1, step=0.01)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
with gr.Row():
|
341 |
generate3 = gr.Button(value="Edit")
|
342 |
|
|
|
236 |
img = img.resize((int(img.width * ratio), int(img.height * ratio)))
|
237 |
|
238 |
# create the CAC controller.
|
239 |
+
if cross_attention_control == "Replace":
|
|
|
240 |
controller = AttentionReplace([source_prompt, target_prompt],
|
241 |
num_inference_steps,
|
242 |
cross_replace_steps=cross_replace_steps,
|
243 |
self_replace_steps=self_replace_steps,
|
244 |
)
|
245 |
ptp_utils.register_attention_control(pipe, controller)
|
246 |
+
elif cross_attention_control == "Refine":
|
247 |
controller = AttentionRefine([source_prompt, target_prompt],
|
248 |
num_inference_steps,
|
249 |
cross_replace_steps=cross_replace_steps,
|
250 |
self_replace_steps=self_replace_steps,
|
251 |
)
|
252 |
ptp_utils.register_attention_control(pipe, controller)
|
253 |
+
elif cross_attention_control == "None":
|
254 |
+
pass
|
255 |
+
else:
|
256 |
+
raise ValueError("Unknown cross_attention_control: {}".format(cross_attention_control))
|
257 |
|
258 |
results = pipe(prompt=target_prompt,
|
259 |
source_prompt=source_prompt,
|
|
|
289 |
CycleDiffusion (<a href="https://arxiv.org/abs/2210.05559">π Paper link</a> | <a href="https://huggingface.co/docs/diffusers/main/en/api/pipelines/cycle_diffusion">𧨠Pipeline doc</a>) is an image-to-image translation method that supports stochastic samplers for diffusion models. <br>
|
290 |
It also supports Cross Attention Control (<a href="https://arxiv.org/abs/2208.01626">π Paper link</a>), which is a technique to transfer the attention map from the source prompt to the target prompt. <br>
|
291 |
</p>
|
292 |
+
<p>
|
293 |
+
<b>How to use:</b> <br>
|
294 |
+
1. Upload an image. <br>
|
295 |
+
2. Enter the source and target prompts. <br>
|
296 |
+
3. Select the source guidance scale (for "encoding") and the target guidance scale (for "decoding"). <br>
|
297 |
+
4. Select the strength (smaller strength means better content preservation). <br>
|
298 |
+
5 (optional). Configurate Cross Attention Control options (e.g., CAC type, cross replace steps, self replace steps). <br>
|
299 |
+
6 (optional). Configurate other options (e.g., image size, inference steps, random seed). <br>
|
300 |
+
7. Click the "Edit" button. <br>
|
301 |
+
</p>
|
302 |
+
<p>
|
303 |
+
<b>Notes:</b> <br>
|
304 |
+
1. CycleDiffusion is likely to fail when drastic changes are intended (e.g., changing a large black car to red). <br>
|
305 |
+
2. The value of strength can be set larger when CAC is used. <br>
|
306 |
+
3. If CAC type is "Replace", the source and target prompts should differ in only one token; otherwise, an error will be raised. <br>
|
307 |
+
4. If CAC type is "Refine", the source prompt be a subsequence of the target prompt; otherwise, an error will be raised. <br>
|
308 |
+
</p>
|
309 |
+
<p>You can skip the queue using Colab: <a href="https://colab.research.google.com/gist/ChenWu98/0aa4fe7be80f6b45d3d055df9f14353a/copy-of-fine-tuned-diffusion-gradio.ipynb"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://colab.research.google.com/assets/colab-badge.svg"></a></p>
|
310 |
Running on <b>{device_print}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
|
311 |
</p>
|
312 |
</div>
|
|
|
337 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0.5, maximum=1, step=0.01)
|
338 |
with gr.Row():
|
339 |
generate1 = gr.Button(value="Edit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
|
341 |
with gr.Tab("CAC options"):
|
342 |
with gr.Group():
|
|
|
346 |
# If not "None", the following two parameters will be used.
|
347 |
cross_replace_steps = gr.Slider(label="Cross replace steps", value=0.8, minimum=0.0, maximum=1, step=0.01)
|
348 |
self_replace_steps = gr.Slider(label="Self replace steps", value=0.4, minimum=0.0, maximum=1, step=0.01)
|
349 |
+
with gr.Row():
|
350 |
+
generate2 = gr.Button(value="Edit")
|
351 |
+
|
352 |
+
with gr.Tab("Other options"):
|
353 |
+
with gr.Group():
|
354 |
+
with gr.Row():
|
355 |
+
num_inference_steps = gr.Slider(label="Number of inference steps", value=100, minimum=25, maximum=500, step=1)
|
356 |
+
width = gr.Slider(label="Width", value=512, minimum=64, maximum=1024, step=8)
|
357 |
+
height = gr.Slider(label="Height", value=512, minimum=64, maximum=1024, step=8)
|
358 |
+
|
359 |
+
with gr.Row():
|
360 |
+
seed = gr.Slider(0, 2147483647, label='Seed', value=0, step=1)
|
361 |
with gr.Row():
|
362 |
generate3 = gr.Button(value="Edit")
|
363 |
|