Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
1e9825f
1
Parent(s):
25eefee
add inference
Browse files
app.py
CHANGED
|
@@ -176,7 +176,11 @@ accelerator = accelerate.Accelerator()
|
|
| 176 |
def generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps):
|
| 177 |
"""Helper function to generate image with specific number of steps"""
|
| 178 |
prompts = [prompt]
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
c = prompts
|
| 181 |
uc = ['(worst quality:2), (low quality:2), (normal quality:2), bad anatomy, bad proportions, poorly drawn face, poorly drawn hands, missing fingers, extra limbs, blurry, pixelated, distorted, lowres, jpeg artifacts, watermark, signature, text, (deformed:1.5), (bad hands:1.3), overexposed, underexposed, censored, mutated, extra fingers, cloned face, bad eyes'] * len(c) if guidance_scale != 1.0 else None
|
| 182 |
shape = [4, width // 8, height // 8]
|
|
@@ -226,7 +230,7 @@ def infer(
|
|
| 226 |
image_quick = generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps)
|
| 227 |
|
| 228 |
# Generate image with 50 steps for high quality
|
| 229 |
-
image_50_steps = generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale,
|
| 230 |
|
| 231 |
return image_quick, image_50_steps, seed
|
| 232 |
|
|
@@ -262,11 +266,11 @@ with gr.Blocks() as demo:
|
|
| 262 |
|
| 263 |
with gr.Row():
|
| 264 |
with gr.Column():
|
| 265 |
-
gr.Markdown("### Our fast inference Result")
|
| 266 |
result = gr.Image(label="Quick Result", show_label=False)
|
| 267 |
with gr.Column():
|
| 268 |
-
gr.Markdown("### Original
|
| 269 |
-
|
| 270 |
|
| 271 |
with gr.Accordion("Advanced Settings", open=False):
|
| 272 |
negative_prompt = gr.Text(
|
|
|
|
| 176 |
def generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps):
|
| 177 |
"""Helper function to generate image with specific number of steps"""
|
| 178 |
prompts = [prompt]
|
| 179 |
+
if num_inference_steps > 8:
|
| 180 |
+
sampler = UniPCSampler(pipe,model_closure=model_closure, steps=num_inference_steps, guidance_scale=guidance_scale,skip_type='time_uniform')
|
| 181 |
+
else:
|
| 182 |
+
sampler = UniPCSampler(pipe,model_closure=model_closure, steps=num_inference_steps, guidance_scale=guidance_scale)
|
| 183 |
+
|
| 184 |
c = prompts
|
| 185 |
uc = ['(worst quality:2), (low quality:2), (normal quality:2), bad anatomy, bad proportions, poorly drawn face, poorly drawn hands, missing fingers, extra limbs, blurry, pixelated, distorted, lowres, jpeg artifacts, watermark, signature, text, (deformed:1.5), (bad hands:1.3), overexposed, underexposed, censored, mutated, extra fingers, cloned face, bad eyes'] * len(c) if guidance_scale != 1.0 else None
|
| 186 |
shape = [4, width // 8, height // 8]
|
|
|
|
| 230 |
image_quick = generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps)
|
| 231 |
|
| 232 |
# Generate image with 50 steps for high quality
|
| 233 |
+
image_50_steps = generate_image_with_steps(prompt, negative_prompt, seed, width, height, guidance_scale, 20)
|
| 234 |
|
| 235 |
return image_quick, image_50_steps, seed
|
| 236 |
|
|
|
|
| 266 |
|
| 267 |
with gr.Row():
|
| 268 |
with gr.Column():
|
| 269 |
+
gr.Markdown("### Our fast inference Result using afs and uni-predictor to get 2 free steps")
|
| 270 |
result = gr.Image(label="Quick Result", show_label=False)
|
| 271 |
with gr.Column():
|
| 272 |
+
gr.Markdown("### Original 20 steps Result")
|
| 273 |
+
result_20_steps = gr.Image(label="20 Steps Result", show_label=False)
|
| 274 |
|
| 275 |
with gr.Accordion("Advanced Settings", open=False):
|
| 276 |
negative_prompt = gr.Text(
|