Spaces:
Runtime error
Runtime error
Commit
•
b12e444
1
Parent(s):
44f95c7
Update app.py
Browse files
app.py
CHANGED
@@ -23,15 +23,16 @@ device="cuda"
|
|
23 |
pipe = pipe.to(device)
|
24 |
|
25 |
@spaces.GPU
|
26 |
-
def run(prompt, negative_prompt="", guidance_scale=7.0, pag_scale=3.0, randomize_seed=True, seed=42, progress=gr.Progress(track_tqdm=True)):
|
27 |
prompt = prompt.strip()
|
|
|
28 |
if(randomize_seed):
|
29 |
seed = random.randint(0, sys.maxsize)
|
30 |
-
if(prompt == ""):
|
31 |
guidance_scale = 0.0
|
32 |
|
33 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
34 |
-
image_pag = pipe(prompt, guidance_scale=guidance_scale, pag_scale=
|
35 |
|
36 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
37 |
image_normal = pipe(prompt, guidance_scale=guidance_scale, generator=generator, num_inference_steps=25).images[0]
|
@@ -57,6 +58,7 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
57 |
guidance_scale = gr.Number(label="Guidance Scale", value=7.0)
|
58 |
negative_prompt = gr.Textbox(label="Negative prompt", info="Is only applied for the CFG part, leave blank for unconditional generation")
|
59 |
pag_scale = gr.Number(label="Pag Scale", value=3.0)
|
|
|
60 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
61 |
seed = gr.Slider(minimum=1, maximum=18446744073709551615, step=1, randomize=True)
|
62 |
gr.Examples(fn=run, examples=[" ", "an insect robot preparing a delicious meal, anime style", "a photo of a group of friends at an amusement park"], inputs=prompt, outputs=[output, seed], cache_examples=True)
|
@@ -66,7 +68,7 @@ with gr.Blocks(css=css, theme=theme) as demo:
|
|
66 |
prompt.submit
|
67 |
],
|
68 |
fn=run,
|
69 |
-
inputs=[prompt, negative_prompt, guidance_scale, pag_scale, randomize_seed, seed],
|
70 |
outputs=[output, seed],
|
71 |
)
|
72 |
if __name__ == "__main__":
|
|
|
23 |
pipe = pipe.to(device)
|
24 |
|
25 |
@spaces.GPU
|
26 |
+
def run(prompt, negative_prompt="", guidance_scale=7.0, pag_scale=3.0, pag_layers=["mid"], randomize_seed=True, seed=42, progress=gr.Progress(track_tqdm=True)):
|
27 |
prompt = prompt.strip()
|
28 |
+
negative_prompt = negative_prompt.strip()
|
29 |
if(randomize_seed):
|
30 |
seed = random.randint(0, sys.maxsize)
|
31 |
+
if(prompt == "" and negative_prompt == ""):
|
32 |
guidance_scale = 0.0
|
33 |
|
34 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
35 |
+
image_pag = pipe(prompt, guidance_scale=guidance_scale, pag_scale=pag_scale, pag_applied_layers=pag_layers, generator=generator, num_inference_steps=25).images[0]
|
36 |
|
37 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
38 |
image_normal = pipe(prompt, guidance_scale=guidance_scale, generator=generator, num_inference_steps=25).images[0]
|
|
|
58 |
guidance_scale = gr.Number(label="Guidance Scale", value=7.0)
|
59 |
negative_prompt = gr.Textbox(label="Negative prompt", info="Is only applied for the CFG part, leave blank for unconditional generation")
|
60 |
pag_scale = gr.Number(label="Pag Scale", value=3.0)
|
61 |
+
pag_layers = gr.Dropdown(label="Model layers to apply Pag to", info="mid is the one used on the paper, up and down blocks seem unstable", choices=["up", "mid", "down"], multiselect=True, value="mid")
|
62 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
63 |
seed = gr.Slider(minimum=1, maximum=18446744073709551615, step=1, randomize=True)
|
64 |
gr.Examples(fn=run, examples=[" ", "an insect robot preparing a delicious meal, anime style", "a photo of a group of friends at an amusement park"], inputs=prompt, outputs=[output, seed], cache_examples=True)
|
|
|
68 |
prompt.submit
|
69 |
],
|
70 |
fn=run,
|
71 |
+
inputs=[prompt, negative_prompt, guidance_scale, pag_scale, pag_layers, randomize_seed, seed],
|
72 |
outputs=[output, seed],
|
73 |
)
|
74 |
if __name__ == "__main__":
|