Spaces:
Running
on
Zero
Running
on
Zero
add pro-tips and fix image size
Browse files
app.py
CHANGED
@@ -154,12 +154,23 @@ with gr.Blocks() as app:
|
|
154 |
|
155 |
with gr.Accordion(label="Image"):
|
156 |
num_inference_steps = gr.Slider(minimum=1, maximum=100, value=20, step=1, interactive=True, label="Inference steps")
|
157 |
-
height = gr.Slider(minimum=
|
158 |
-
width = gr.Slider(minimum=
|
159 |
with gr.Column():
|
160 |
use_fixed_seed = gr.Checkbox(value=True, interactive=False, label="Use fixed seed")
|
161 |
seed = gr.Number(minimum=0, maximum=10**9, value=0, interactive=True, label="Random seed", show_label=False)
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
@gr.on(
|
164 |
inputs=[model_type, model_path, prompt, negative_prompt, cfg_scale, embedded_guidance, num_inference_steps, height, width],
|
165 |
outputs=[prompt, negative_prompt, cfg_scale, embedded_guidance, num_inference_steps, height, width],
|
@@ -183,10 +194,17 @@ with gr.Blocks() as app:
|
|
183 |
canvas_list = []
|
184 |
for painter_layer_id in range(config["max_num_painter_layers"]):
|
185 |
with gr.Tab(label=f"Layer {painter_layer_id}"):
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
local_prompt = gr.Textbox(label="Local prompt", key=f"local_prompt_{painter_layer_id}")
|
188 |
-
mask_scale = gr.Slider(minimum=0.0, maximum=5.0, value=
|
189 |
-
|
|
|
190 |
brush=gr.Brush(default_size=100, default_color="#000000", colors=["#000000"]),
|
191 |
label="Painter", key=f"canvas_{painter_layer_id}")
|
192 |
@gr.on(inputs=[height, width, canvas], outputs=canvas, triggers=[height.change, width.change, canvas.clear, enable_local_prompt.change], show_progress="hidden")
|
@@ -255,7 +273,7 @@ with gr.Blocks() as app:
|
|
255 |
h, w = canvas["background"].shape[:2]
|
256 |
canvas["background"] = output_image.resize((w, h))
|
257 |
return tuple(canvas_list)
|
258 |
-
|
259 |
canvas1 = {
|
260 |
"background": Image.open("images/image1.png"),
|
261 |
"layers": [np.array(Image.open("images/image1_layer.png"))],
|
@@ -283,5 +301,4 @@ with gr.Blocks() as app:
|
|
283 |
inputs=[prompt, seed, output_image, enable_local_prompt_list[0], local_prompt_list[0], mask_scale_list[0], canvas_list[0]],
|
284 |
label=None
|
285 |
)
|
286 |
-
|
287 |
app.launch()
|
|
|
154 |
|
155 |
with gr.Accordion(label="Image"):
|
156 |
num_inference_steps = gr.Slider(minimum=1, maximum=100, value=20, step=1, interactive=True, label="Inference steps")
|
157 |
+
height = gr.Slider(minimum=1024, maximum=1024, value=1024, step=64, interactive=False, label="Height", visible=False)
|
158 |
+
width = gr.Slider(minimum=1024, maximum=1024, value=1024, step=64, interactive=False, label="Width", visible=False)
|
159 |
with gr.Column():
|
160 |
use_fixed_seed = gr.Checkbox(value=True, interactive=False, label="Use fixed seed")
|
161 |
seed = gr.Number(minimum=0, maximum=10**9, value=0, interactive=True, label="Random seed", show_label=False)
|
162 |
|
163 |
+
with gr.Row(elem_id="pro-tips"):
|
164 |
+
gr.Markdown("""
|
165 |
+
# Usage:
|
166 |
+
|
167 |
+
1. Enter a prompt and click "Generate" to create an image.
|
168 |
+
2. Click "Set as painter's background" to use the generated image as the canvas.
|
169 |
+
3. In the painter, draw the area you want to repaint and set a local prompt. For multiple areas with different prompts, use layer1 and layer2, and click "Enable this layer" to activate the canvas.
|
170 |
+
4. Click "Generate" again to obtain the repainted image.
|
171 |
+
5. If you want to regenerate a new image as the background, uncheck "Enable this layer," update the prompt, and click "Generate."
|
172 |
+
""")
|
173 |
+
|
174 |
@gr.on(
|
175 |
inputs=[model_type, model_path, prompt, negative_prompt, cfg_scale, embedded_guidance, num_inference_steps, height, width],
|
176 |
outputs=[prompt, negative_prompt, cfg_scale, embedded_guidance, num_inference_steps, height, width],
|
|
|
194 |
canvas_list = []
|
195 |
for painter_layer_id in range(config["max_num_painter_layers"]):
|
196 |
with gr.Tab(label=f"Layer {painter_layer_id}"):
|
197 |
+
enable_local_prompt_value = painter_layer_id == 0
|
198 |
+
enable_local_prompt = gr.Checkbox(
|
199 |
+
label="Enable this layer",
|
200 |
+
value=enable_local_prompt_value,
|
201 |
+
key=f"enable_local_prompt_{painter_layer_id}"
|
202 |
+
)
|
203 |
+
|
204 |
local_prompt = gr.Textbox(label="Local prompt", key=f"local_prompt_{painter_layer_id}")
|
205 |
+
mask_scale = gr.Slider(minimum=0.0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Mask scale", key=f"mask_scale_{painter_layer_id}")
|
206 |
+
canvas_size = (1024, 1024) if painter_layer_id == 0 else (1024, 1)
|
207 |
+
canvas = gr.ImageEditor(canvas_size=canvas_size, sources=None, layers=False, interactive=True, image_mode="RGBA",
|
208 |
brush=gr.Brush(default_size=100, default_color="#000000", colors=["#000000"]),
|
209 |
label="Painter", key=f"canvas_{painter_layer_id}")
|
210 |
@gr.on(inputs=[height, width, canvas], outputs=canvas, triggers=[height.change, width.change, canvas.clear, enable_local_prompt.change], show_progress="hidden")
|
|
|
273 |
h, w = canvas["background"].shape[:2]
|
274 |
canvas["background"] = output_image.resize((w, h))
|
275 |
return tuple(canvas_list)
|
276 |
+
|
277 |
canvas1 = {
|
278 |
"background": Image.open("images/image1.png"),
|
279 |
"layers": [np.array(Image.open("images/image1_layer.png"))],
|
|
|
301 |
inputs=[prompt, seed, output_image, enable_local_prompt_list[0], local_prompt_list[0], mask_scale_list[0], canvas_list[0]],
|
302 |
label=None
|
303 |
)
|
|
|
304 |
app.launch()
|