Spaces:
Running
on
Zero
Running
on
Zero
added paste back as an option
Browse files
app.py
CHANGED
|
@@ -46,7 +46,7 @@ pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
|
| 46 |
|
| 47 |
|
| 48 |
@spaces.GPU(duration=16)
|
| 49 |
-
def fill_image(prompt, image, model_selection):
|
| 50 |
(
|
| 51 |
prompt_embeds,
|
| 52 |
negative_prompt_embeds,
|
|
@@ -71,8 +71,14 @@ def fill_image(prompt, image, model_selection):
|
|
| 71 |
):
|
| 72 |
yield image, cnet_image
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
yield source, cnet_image
|
| 78 |
|
|
@@ -101,14 +107,17 @@ with gr.Blocks() as demo:
|
|
| 101 |
value="RealVisXL V5.0 Lightning",
|
| 102 |
label="Model",
|
| 103 |
)
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
with gr.Row():
|
| 107 |
input_image = gr.ImageMask(
|
| 108 |
-
type="pil",
|
| 109 |
-
label="Input Image",
|
| 110 |
-
crop_size=(1024, 1024),
|
| 111 |
-
layers=False
|
| 112 |
)
|
| 113 |
|
| 114 |
result = ImageSlider(
|
|
@@ -116,15 +125,13 @@ with gr.Blocks() as demo:
|
|
| 116 |
label="Generated Image",
|
| 117 |
)
|
| 118 |
|
| 119 |
-
use_as_input_button = gr.Button("Use as Input Image", visible=False)
|
| 120 |
|
| 121 |
def use_output_as_input(output_image):
|
| 122 |
return gr.update(value=output_image[1])
|
| 123 |
|
| 124 |
use_as_input_button.click(
|
| 125 |
-
fn=use_output_as_input,
|
| 126 |
-
inputs=[result],
|
| 127 |
-
outputs=[input_image]
|
| 128 |
)
|
| 129 |
|
| 130 |
run_button.click(
|
|
@@ -137,7 +144,7 @@ with gr.Blocks() as demo:
|
|
| 137 |
outputs=use_as_input_button,
|
| 138 |
).then(
|
| 139 |
fn=fill_image,
|
| 140 |
-
inputs=[prompt, input_image, model_selection],
|
| 141 |
outputs=result,
|
| 142 |
).then(
|
| 143 |
fn=lambda: gr.update(visible=True),
|
|
@@ -155,7 +162,7 @@ with gr.Blocks() as demo:
|
|
| 155 |
outputs=use_as_input_button,
|
| 156 |
).then(
|
| 157 |
fn=fill_image,
|
| 158 |
-
inputs=[prompt, input_image, model_selection],
|
| 159 |
outputs=result,
|
| 160 |
).then(
|
| 161 |
fn=lambda: gr.update(visible=True),
|
|
@@ -164,4 +171,4 @@ with gr.Blocks() as demo:
|
|
| 164 |
)
|
| 165 |
|
| 166 |
|
| 167 |
-
demo.launch(share=False)
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
@spaces.GPU(duration=16)
|
| 49 |
+
def fill_image(prompt, image, model_selection, paste_back):
|
| 50 |
(
|
| 51 |
prompt_embeds,
|
| 52 |
negative_prompt_embeds,
|
|
|
|
| 71 |
):
|
| 72 |
yield image, cnet_image
|
| 73 |
|
| 74 |
+
print(f"{model_selection=}")
|
| 75 |
+
print(f"{paste_back=}")
|
| 76 |
+
|
| 77 |
+
if paste_back:
|
| 78 |
+
image = image.convert("RGBA")
|
| 79 |
+
cnet_image.paste(image, (0, 0), binary_mask)
|
| 80 |
+
else:
|
| 81 |
+
cnet_image = image
|
| 82 |
|
| 83 |
yield source, cnet_image
|
| 84 |
|
|
|
|
| 107 |
value="RealVisXL V5.0 Lightning",
|
| 108 |
label="Model",
|
| 109 |
)
|
| 110 |
+
|
| 111 |
+
with gr.Row():
|
| 112 |
+
with gr.Column():
|
| 113 |
+
run_button = gr.Button("Generate")
|
| 114 |
+
|
| 115 |
+
with gr.Column():
|
| 116 |
+
paste_back = gr.Checkbox(True, label="Paste back original")
|
| 117 |
|
| 118 |
with gr.Row():
|
| 119 |
input_image = gr.ImageMask(
|
| 120 |
+
type="pil", label="Input Image", crop_size=(1024, 1024), layers=False
|
|
|
|
|
|
|
|
|
|
| 121 |
)
|
| 122 |
|
| 123 |
result = ImageSlider(
|
|
|
|
| 125 |
label="Generated Image",
|
| 126 |
)
|
| 127 |
|
| 128 |
+
use_as_input_button = gr.Button("Use as Input Image", visible=False)
|
| 129 |
|
| 130 |
def use_output_as_input(output_image):
|
| 131 |
return gr.update(value=output_image[1])
|
| 132 |
|
| 133 |
use_as_input_button.click(
|
| 134 |
+
fn=use_output_as_input, inputs=[result], outputs=[input_image]
|
|
|
|
|
|
|
| 135 |
)
|
| 136 |
|
| 137 |
run_button.click(
|
|
|
|
| 144 |
outputs=use_as_input_button,
|
| 145 |
).then(
|
| 146 |
fn=fill_image,
|
| 147 |
+
inputs=[prompt, input_image, model_selection, paste_back],
|
| 148 |
outputs=result,
|
| 149 |
).then(
|
| 150 |
fn=lambda: gr.update(visible=True),
|
|
|
|
| 162 |
outputs=use_as_input_button,
|
| 163 |
).then(
|
| 164 |
fn=fill_image,
|
| 165 |
+
inputs=[prompt, input_image, model_selection, paste_back],
|
| 166 |
outputs=result,
|
| 167 |
).then(
|
| 168 |
fn=lambda: gr.update(visible=True),
|
|
|
|
| 171 |
)
|
| 172 |
|
| 173 |
|
| 174 |
+
demo.launch(share=False)
|