Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
3fc7537
1
Parent(s):
10fd071
update UI
Browse files
app.py
CHANGED
|
@@ -204,13 +204,13 @@ MAX_IMAGE_SIZE = 1024
|
|
| 204 |
|
| 205 |
accelerator = accelerate.Accelerator()
|
| 206 |
|
| 207 |
-
def generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps):
|
| 208 |
"""Helper function to generate image with specific number of steps"""
|
| 209 |
scheduler = CustomedUniPCMultistepScheduler.from_config(pipe.scheduler.config
|
| 210 |
, solver_order = 2 if num_inference_steps==8 else 1
|
| 211 |
,denoise_to_zero = False
|
| 212 |
, use_afs = True
|
| 213 |
-
, use_free_predictor =
|
| 214 |
start_free_at_step = 4
|
| 215 |
pipe.scheduler = scheduler
|
| 216 |
pipe.to('cuda')
|
|
@@ -242,7 +242,7 @@ def generate_image_with_steps(prompt, negative_prompt, seed, width, height, guid
|
|
| 242 |
negative_prompts = 'lowres, bad anatomy, bad hands, watermark'
|
| 243 |
negative_prompts = 1 * [negative_prompts]
|
| 244 |
use_afs = True
|
| 245 |
-
use_free_predictor =
|
| 246 |
prompt_embeds, cond_kwargs = prepare_sdxl_pipeline_step_parameter(pipe
|
| 247 |
, prompts
|
| 248 |
, need_cfg=True
|
|
@@ -286,6 +286,7 @@ def infer(
|
|
| 286 |
resolution,
|
| 287 |
guidance_scale,
|
| 288 |
num_inference_steps,
|
|
|
|
| 289 |
progress=gr.Progress(track_tqdm=True),
|
| 290 |
):
|
| 291 |
if randomize_seed:
|
|
@@ -295,7 +296,7 @@ def infer(
|
|
| 295 |
width, height = map(int, resolution.split('x'))
|
| 296 |
|
| 297 |
# Generate image with selected steps
|
| 298 |
-
image_quick = generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps)
|
| 299 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config
|
| 300 |
, final_sigmas_type="sigma_min"
|
| 301 |
, algorithm_type="sde-dpmsolver++"
|
|
@@ -396,21 +397,27 @@ with gr.Blocks() as demo:
|
|
| 396 |
label="Number of inference steps",
|
| 397 |
)
|
| 398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
|
|
|
| 414 |
|
| 415 |
if __name__ == "__main__":
|
| 416 |
demo.launch()
|
|
|
|
| 204 |
|
| 205 |
accelerator = accelerate.Accelerator()
|
| 206 |
|
| 207 |
+
def generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps, use_free_unip):
|
| 208 |
"""Helper function to generate image with specific number of steps"""
|
| 209 |
scheduler = CustomedUniPCMultistepScheduler.from_config(pipe.scheduler.config
|
| 210 |
, solver_order = 2 if num_inference_steps==8 else 1
|
| 211 |
,denoise_to_zero = False
|
| 212 |
, use_afs = True
|
| 213 |
+
, use_free_predictor = use_free_unip)
|
| 214 |
start_free_at_step = 4
|
| 215 |
pipe.scheduler = scheduler
|
| 216 |
pipe.to('cuda')
|
|
|
|
| 242 |
negative_prompts = 'lowres, bad anatomy, bad hands, watermark'
|
| 243 |
negative_prompts = 1 * [negative_prompts]
|
| 244 |
use_afs = True
|
| 245 |
+
use_free_predictor = use_free_unip
|
| 246 |
prompt_embeds, cond_kwargs = prepare_sdxl_pipeline_step_parameter(pipe
|
| 247 |
, prompts
|
| 248 |
, need_cfg=True
|
|
|
|
| 286 |
resolution,
|
| 287 |
guidance_scale,
|
| 288 |
num_inference_steps,
|
| 289 |
+
use_free_unip,
|
| 290 |
progress=gr.Progress(track_tqdm=True),
|
| 291 |
):
|
| 292 |
if randomize_seed:
|
|
|
|
| 296 |
width, height = map(int, resolution.split('x'))
|
| 297 |
|
| 298 |
# Generate image with selected steps
|
| 299 |
+
image_quick = generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps, use_free_unip)
|
| 300 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config
|
| 301 |
, final_sigmas_type="sigma_min"
|
| 302 |
, algorithm_type="sde-dpmsolver++"
|
|
|
|
| 397 |
label="Number of inference steps",
|
| 398 |
)
|
| 399 |
|
| 400 |
+
use_free_unip = gr.Checkbox(
|
| 401 |
+
label="Use free Uni-P predictor",
|
| 402 |
+
value=False,
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
gr.Examples(examples=examples, inputs=[prompt])
|
| 406 |
+
gr.on(
|
| 407 |
+
triggers=[run_button.click, prompt.submit],
|
| 408 |
+
fn=infer,
|
| 409 |
+
inputs=[
|
| 410 |
+
prompt,
|
| 411 |
+
negative_prompt,
|
| 412 |
+
seed,
|
| 413 |
+
randomize_seed,
|
| 414 |
+
resolution,
|
| 415 |
+
guidance_scale,
|
| 416 |
+
num_inference_steps,
|
| 417 |
+
use_free_unip,
|
| 418 |
+
],
|
| 419 |
+
outputs=[result, result_30_steps, seed],
|
| 420 |
+
)
|
| 421 |
|
| 422 |
if __name__ == "__main__":
|
| 423 |
demo.launch()
|