Spaces:
Running
on
A10G
Running
on
A10G
major update:
Browse files1. set inputs once and edit on the same inversion.
2. RNRI hyperparams to user
- app.py +59 -28
- src/editor.py +2 -2
app.py
CHANGED
|
@@ -27,23 +27,13 @@ pipe_inversion.scheduler_inference = scheduler_class.from_config(pipe_inference.
|
|
| 27 |
# pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
| 28 |
# pipe = pipe.to(device)
|
| 29 |
|
| 30 |
-
@spaces.GPU
|
| 31 |
-
def set_pipe(input_image, description_prompt, edit_guidance_scale, num_inference_steps=4,
|
| 32 |
-
num_inversion_steps=4, inversion_max_step=0.6):
|
| 33 |
-
config = RunConfig(num_inference_steps=num_inference_steps,
|
| 34 |
-
num_inversion_steps=num_inversion_steps,
|
| 35 |
-
edit_guidance_scale=edit_guidance_scale,
|
| 36 |
-
inversion_max_step=inversion_max_step)
|
| 37 |
-
|
| 38 |
-
return ImageEditorDemo(pipe_inversion, pipe_inference, input_image, description_prompt, config, device)
|
| 39 |
-
|
| 40 |
# return editor
|
| 41 |
# image = editor.edit(target_prompt)
|
| 42 |
# return image
|
| 43 |
|
| 44 |
def edit(editor, target_prompt):
|
| 45 |
if editor is None:
|
| 46 |
-
|
| 47 |
return editor.edit(target_prompt)
|
| 48 |
|
| 49 |
examples = [
|
|
@@ -75,6 +65,20 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 75 |
Image editing using our RNRI for inversion demonstrates significant speed-up and improved quality compared to previous state-of-the-art methods.
|
| 76 |
Take a look at our [project page](https://barakmam.github.io/rnri.github.io/).
|
| 77 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
with gr.Row():
|
| 79 |
with gr.Column(elem_id="col-container-1"):
|
| 80 |
with gr.Row():
|
|
@@ -90,19 +94,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 90 |
container=False,
|
| 91 |
)
|
| 92 |
|
| 93 |
-
with gr.Row():
|
| 94 |
-
set_button = gr.Button("Set input image & description", scale=1)
|
| 95 |
-
|
| 96 |
-
editor_state = gr.State()
|
| 97 |
-
with gr.Row():
|
| 98 |
-
target_prompt = gr.Text(
|
| 99 |
-
label="Edit prompt",
|
| 100 |
-
info = "Enter your edit prompt",
|
| 101 |
-
show_label=False,
|
| 102 |
-
max_lines=1,
|
| 103 |
-
placeholder="an oreo cake on a table",
|
| 104 |
-
container=False,
|
| 105 |
-
)
|
| 106 |
|
| 107 |
with gr.Accordion("Advanced Settings", open=False):
|
| 108 |
with gr.Row():
|
|
@@ -115,7 +106,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 115 |
)
|
| 116 |
|
| 117 |
num_inference_steps = gr.Slider(
|
| 118 |
-
label="
|
| 119 |
minimum=1,
|
| 120 |
maximum=12,
|
| 121 |
step=1,
|
|
@@ -130,12 +121,52 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 130 |
value=0.6,
|
| 131 |
)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
with gr.Row():
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
with gr.Column(elem_id="col-container-2"):
|
| 137 |
result = gr.Image(label="Result")
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
# gr.Examples(
|
| 140 |
# examples = examples,
|
| 141 |
# inputs = [prompt]
|
|
@@ -144,8 +175,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 144 |
set_button.click(
|
| 145 |
fn=set_pipe,
|
| 146 |
inputs=[input_image, description_prompt, edit_guidance_scale, num_inference_steps,
|
| 147 |
-
num_inference_steps, inversion_max_step],
|
| 148 |
-
outputs=editor_state
|
| 149 |
)
|
| 150 |
|
| 151 |
run_button.click(
|
|
|
|
| 27 |
# pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
| 28 |
# pipe = pipe.to(device)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# return editor
|
| 31 |
# image = editor.edit(target_prompt)
|
| 32 |
# return image
|
| 33 |
|
| 34 |
def edit(editor, target_prompt):
|
| 35 |
if editor is None:
|
| 36 |
+
raise gr.Error("Set inputs before editing.")
|
| 37 |
return editor.edit(target_prompt)
|
| 38 |
|
| 39 |
examples = [
|
|
|
|
| 65 |
Image editing using our RNRI for inversion demonstrates significant speed-up and improved quality compared to previous state-of-the-art methods.
|
| 66 |
Take a look at our [project page](https://barakmam.github.io/rnri.github.io/).
|
| 67 |
""")
|
| 68 |
+
editor_state = gr.State()
|
| 69 |
+
|
| 70 |
+
@spaces.GPU
|
| 71 |
+
def set_pipe(input_image, description_prompt, edit_guidance_scale, num_inference_steps=4,
|
| 72 |
+
num_inversion_steps=4, inversion_max_step=0.6, rnri_iterations=2, rnri_alpha=0.1, rnri_lr=0.2):
|
| 73 |
+
config = RunConfig(num_inference_steps=num_inference_steps,
|
| 74 |
+
num_inversion_steps=num_inversion_steps,
|
| 75 |
+
edit_guidance_scale=edit_guidance_scale,
|
| 76 |
+
inversion_max_step=inversion_max_step)
|
| 77 |
+
return ImageEditorDemo(pipe_inversion, pipe_inference, input_image,
|
| 78 |
+
description_prompt, config, device,
|
| 79 |
+
[rnri_iterations, rnri_alpha, rnri_lr]), "Input has set!"
|
| 80 |
+
|
| 81 |
+
|
| 82 |
with gr.Row():
|
| 83 |
with gr.Column(elem_id="col-container-1"):
|
| 84 |
with gr.Row():
|
|
|
|
| 94 |
container=False,
|
| 95 |
)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
with gr.Accordion("Advanced Settings", open=False):
|
| 99 |
with gr.Row():
|
|
|
|
| 106 |
)
|
| 107 |
|
| 108 |
num_inference_steps = gr.Slider(
|
| 109 |
+
label="Inference steps",
|
| 110 |
minimum=1,
|
| 111 |
maximum=12,
|
| 112 |
step=1,
|
|
|
|
| 121 |
value=0.6,
|
| 122 |
)
|
| 123 |
|
| 124 |
+
rnri_iterations = gr.Slider(
|
| 125 |
+
label="RNRI iterations",
|
| 126 |
+
minimum=0,
|
| 127 |
+
maximum=5,
|
| 128 |
+
step=1,
|
| 129 |
+
value=2,
|
| 130 |
+
)
|
| 131 |
+
rnri_alpha = gr.Slider(
|
| 132 |
+
label="RNRI alpha",
|
| 133 |
+
minimum=0.0,
|
| 134 |
+
maximum=1.0,
|
| 135 |
+
step=0.05,
|
| 136 |
+
value=0.1,
|
| 137 |
+
)
|
| 138 |
+
rnri_lr = gr.Slider(
|
| 139 |
+
label="RNRI learning rate",
|
| 140 |
+
minimum=0.0,
|
| 141 |
+
maximum=1.0,
|
| 142 |
+
step=0.05,
|
| 143 |
+
value=0.2,
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
with gr.Row():
|
| 147 |
+
set_button = gr.Button("Set input image & description & settings", scale=1)
|
| 148 |
+
|
| 149 |
+
is_set_text = gr.Text("", show_label=False)
|
| 150 |
+
|
| 151 |
+
# Create a loading indicator
|
| 152 |
+
loading_indicator = gr.Markdown(value="⏳ Processing...", visible=False)
|
| 153 |
|
| 154 |
with gr.Column(elem_id="col-container-2"):
|
| 155 |
result = gr.Image(label="Result")
|
| 156 |
|
| 157 |
+
with gr.Row():
|
| 158 |
+
target_prompt = gr.Text(
|
| 159 |
+
label="Edit prompt",
|
| 160 |
+
info = "Enter your edit prompt",
|
| 161 |
+
show_label=False,
|
| 162 |
+
max_lines=1,
|
| 163 |
+
placeholder="an oreo cake on a table",
|
| 164 |
+
container=False,
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
with gr.Row():
|
| 168 |
+
run_button = gr.Button("Edit", scale=1)
|
| 169 |
+
|
| 170 |
# gr.Examples(
|
| 171 |
# examples = examples,
|
| 172 |
# inputs = [prompt]
|
|
|
|
| 175 |
set_button.click(
|
| 176 |
fn=set_pipe,
|
| 177 |
inputs=[input_image, description_prompt, edit_guidance_scale, num_inference_steps,
|
| 178 |
+
num_inference_steps, inversion_max_step, rnri_iterations, rnri_alpha, rnri_lr],
|
| 179 |
+
outputs=[editor_state, is_set_text],
|
| 180 |
)
|
| 181 |
|
| 182 |
run_button.click(
|
src/editor.py
CHANGED
|
@@ -35,7 +35,7 @@ def load_im_into_format_from_path(im_path):
|
|
| 35 |
|
| 36 |
|
| 37 |
class ImageEditorDemo:
|
| 38 |
-
def __init__(self, pipe_inversion, pipe_inference, input_image, description_prompt, cfg, device):
|
| 39 |
self.pipe_inversion = pipe_inversion
|
| 40 |
self.pipe_inference = pipe_inference
|
| 41 |
self.original_image = load_im_into_format_from_path(input_image).convert("RGB")
|
|
@@ -54,7 +54,7 @@ class ImageEditorDemo:
|
|
| 54 |
self.cfg = cfg
|
| 55 |
self.pipe_inversion.cfg = cfg
|
| 56 |
self.pipe_inference.cfg = cfg
|
| 57 |
-
self.inv_hp = [2, 0.1, 0.2]
|
| 58 |
self.edit_cfg = cfg.edit_guidance_scale
|
| 59 |
|
| 60 |
self.pipe_inference.to(device)
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
class ImageEditorDemo:
|
| 38 |
+
def __init__(self, pipe_inversion, pipe_inference, input_image, description_prompt, cfg, device, inv_hp):
|
| 39 |
self.pipe_inversion = pipe_inversion
|
| 40 |
self.pipe_inference = pipe_inference
|
| 41 |
self.original_image = load_im_into_format_from_path(input_image).convert("RGB")
|
|
|
|
| 54 |
self.cfg = cfg
|
| 55 |
self.pipe_inversion.cfg = cfg
|
| 56 |
self.pipe_inference.cfg = cfg
|
| 57 |
+
self.inv_hp = inv_hp # [2, 0.1, 0.2]
|
| 58 |
self.edit_cfg = cfg.edit_guidance_scale
|
| 59 |
|
| 60 |
self.pipe_inference.to(device)
|