add deltaedit
Browse files
app.py
CHANGED
|
@@ -110,8 +110,13 @@ def edit_image(orig_image, edit_direction, edit_power, align, mask, progress=gr.
|
|
| 110 |
return gr.update(value=output_edited, visible=True), gr.update(value=output_inv, visible=True), gr.update(visible=False)
|
| 111 |
|
| 112 |
|
| 113 |
-
def edit_image_clip(orig_image, neutral_prompt, target_prompt, disentanglement, edit_power, align, mask, progress=gr.Progress(track_tqdm=True)):
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
return edit_image(orig_image, edit_direction, edit_power, align, mask, progress=None)
|
| 116 |
|
| 117 |
|
|
@@ -177,9 +182,10 @@ def get_demo():
|
|
| 177 |
predef_editing_power = gr.Slider(-20, 20, value=7, step=0.1, label="Editing power")
|
| 178 |
btn_predef = gr.Button("Edit image")
|
| 179 |
|
| 180 |
-
with gr.Accordion("Text Prompt
|
| 181 |
with gr.Accordion("Description", open=False):
|
| 182 |
-
gr.Markdown('''You can alse use editings from text prompts via **StyleClip Global Mapper** (https://arxiv.org/abs/2103.17249). You just need to choose:
|
|
|
|
| 183 |
|
| 184 |
**Editing power** -- the greater the absolute value of this parameter, the more the selected edit will appear.
|
| 185 |
|
|
@@ -189,7 +195,7 @@ def get_demo():
|
|
| 189 |
|
| 190 |
**Disentanglement** -- positive number, the less this attribute -- the more related attributes will also be changed (e.g. for grey hair editing, wrinkle, skin colour and glasses may also be edited)
|
| 191 |
''')
|
| 192 |
-
|
| 193 |
neutral_prompt = gr.Textbox(value="face with hair", label="Neutreal prompt (e.g. 'a face')")
|
| 194 |
target_prompt = gr.Textbox(value="face with fire hair", label="Target prompt (e.g. 'a smilling face')")
|
| 195 |
styleclip_editing_power = gr.Slider(-50, 50, value=10, step=1, label="Editing power")
|
|
@@ -262,7 +268,7 @@ def get_demo():
|
|
| 262 |
)
|
| 263 |
btn_clip.click(
|
| 264 |
fn=edit_image_clip,
|
| 265 |
-
inputs=[input_image, neutral_prompt, target_prompt, disentanglement, styleclip_editing_power, align, mask],
|
| 266 |
outputs=[output_edit, output_inv, error_message]
|
| 267 |
)
|
| 268 |
btn_mask.click(
|
|
@@ -288,4 +294,4 @@ def get_demo():
|
|
| 288 |
|
| 289 |
if __name__ == "__main__":
|
| 290 |
demo = get_demo()
|
| 291 |
-
demo.launch(server_name="
|
|
|
|
| 110 |
return gr.update(value=output_edited, visible=True), gr.update(value=output_inv, visible=True), gr.update(visible=False)
|
| 111 |
|
| 112 |
|
| 113 |
+
def edit_image_clip(orig_image, neutral_prompt, target_prompt, disentanglement, edit_power, align, mask, edit_method, progress=gr.Progress(track_tqdm=True)):
|
| 114 |
+
if edit_method == "StyleClip":
|
| 115 |
+
edit_direction = "_".join(["styleclip_global", neutral_prompt, target_prompt, str(disentanglement)])
|
| 116 |
+
else:
|
| 117 |
+
edit_power = edit_power / 10
|
| 118 |
+
disentanglement = disentanglement / 3
|
| 119 |
+
edit_direction = "_".join(["deltaedit", neutral_prompt, target_prompt, str(disentanglement)])
|
| 120 |
return edit_image(orig_image, edit_direction, edit_power, align, mask, progress=None)
|
| 121 |
|
| 122 |
|
|
|
|
| 182 |
predef_editing_power = gr.Slider(-20, 20, value=7, step=0.1, label="Editing power")
|
| 183 |
btn_predef = gr.Button("Edit image")
|
| 184 |
|
| 185 |
+
with gr.Accordion("Text Prompt Editings", open=False):
|
| 186 |
with gr.Accordion("Description", open=False):
|
| 187 |
+
gr.Markdown('''You can alse use editings from text prompts via **StyleClip Global Mapper** (https://arxiv.org/abs/2103.17249) or **DeltaEdit** (https://arxiv.org/abs/2303.06285). You just need to choose:
|
| 188 |
+
**Method** -- method to use, StyleClip or DeltaEdit
|
| 189 |
|
| 190 |
**Editing power** -- the greater the absolute value of this parameter, the more the selected edit will appear.
|
| 191 |
|
|
|
|
| 195 |
|
| 196 |
**Disentanglement** -- positive number, the less this attribute -- the more related attributes will also be changed (e.g. for grey hair editing, wrinkle, skin colour and glasses may also be edited)
|
| 197 |
''')
|
| 198 |
+
edit_method = gr.Dropdown(["StyleClip", "DeltaEdit"], label="Editing method", value="StyleClip")
|
| 199 |
neutral_prompt = gr.Textbox(value="face with hair", label="Neutreal prompt (e.g. 'a face')")
|
| 200 |
target_prompt = gr.Textbox(value="face with fire hair", label="Target prompt (e.g. 'a smilling face')")
|
| 201 |
styleclip_editing_power = gr.Slider(-50, 50, value=10, step=1, label="Editing power")
|
|
|
|
| 268 |
)
|
| 269 |
btn_clip.click(
|
| 270 |
fn=edit_image_clip,
|
| 271 |
+
inputs=[input_image, neutral_prompt, target_prompt, disentanglement, styleclip_editing_power, align, mask, edit_method],
|
| 272 |
outputs=[output_edit, output_inv, error_message]
|
| 273 |
)
|
| 274 |
btn_mask.click(
|
|
|
|
| 294 |
|
| 295 |
if __name__ == "__main__":
|
| 296 |
demo = get_demo()
|
| 297 |
+
demo.launch(server_name="127.0.0.1", server_port=7860)
|