Spaces:
Running
on
A10G
Running
on
A10G
enables multiple editing without initializing the image each time
Browse files
app.py
CHANGED
|
@@ -28,19 +28,23 @@ pipe_inversion.scheduler_inference = scheduler_class.from_config(pipe_inference.
|
|
| 28 |
# pipe = pipe.to(device)
|
| 29 |
|
| 30 |
|
| 31 |
-
def
|
| 32 |
-
num_inversion_steps=4,
|
| 33 |
-
inversion_max_step=0.6):
|
| 34 |
config = RunConfig(num_inference_steps=num_inference_steps,
|
| 35 |
num_inversion_steps=num_inversion_steps,
|
| 36 |
edit_guidance_scale=edit_guidance_scale,
|
| 37 |
inversion_max_step=inversion_max_step)
|
| 38 |
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
examples = [
|
| 46 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
@@ -85,6 +89,10 @@ with gr.Blocks() as demo:
|
|
| 85 |
container=False,
|
| 86 |
)
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
with gr.Row():
|
| 89 |
target_prompt = gr.Text(
|
| 90 |
label="Edit prompt",
|
|
@@ -131,13 +139,20 @@ with gr.Blocks() as demo:
|
|
| 131 |
# inputs = [prompt]
|
| 132 |
# )
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
run_button.click(
|
| 135 |
-
fn=
|
| 136 |
-
inputs=[
|
| 137 |
-
num_inference_steps],
|
| 138 |
outputs=[result]
|
| 139 |
)
|
| 140 |
|
|
|
|
| 141 |
demo.queue().launch()
|
| 142 |
|
| 143 |
# im = infer(input_image, description_prompt, target_prompt, edit_guidance_scale, num_inference_steps=4, num_inversion_steps=4,
|
|
|
|
| 28 |
# pipe = pipe.to(device)
|
| 29 |
|
| 30 |
|
| 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 |
+
return "Please set image & description before editing."
|
| 47 |
+
return editor.edit(target_prompt)
|
| 48 |
|
| 49 |
examples = [
|
| 50 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
|
|
| 89 |
container=False,
|
| 90 |
)
|
| 91 |
|
| 92 |
+
with gr.Row():
|
| 93 |
+
set_button = gr.Button("Set input image & description", scale=1)
|
| 94 |
+
|
| 95 |
+
editor_state = gr.State()
|
| 96 |
with gr.Row():
|
| 97 |
target_prompt = gr.Text(
|
| 98 |
label="Edit prompt",
|
|
|
|
| 139 |
# inputs = [prompt]
|
| 140 |
# )
|
| 141 |
|
| 142 |
+
set_button.click(
|
| 143 |
+
fn=set_pipe,
|
| 144 |
+
inputs=[input_image, description_prompt, edit_guidance_scale, num_inference_steps,
|
| 145 |
+
num_inference_steps, inversion_max_step],
|
| 146 |
+
outputs=editor_state
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
run_button.click(
|
| 150 |
+
fn=edit,
|
| 151 |
+
inputs=[editor_state, target_prompt],
|
|
|
|
| 152 |
outputs=[result]
|
| 153 |
)
|
| 154 |
|
| 155 |
+
|
| 156 |
demo.queue().launch()
|
| 157 |
|
| 158 |
# im = infer(input_image, description_prompt, target_prompt, edit_guidance_scale, num_inference_steps=4, num_inversion_steps=4,
|