Spaces:
Running
on
Zero
Running
on
Zero
gokaygokay
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -22,23 +22,35 @@ pipe.fuse_lora()
|
|
22 |
MAX_SEED = 2**32-1
|
23 |
|
24 |
@spaces.GPU(duration=75)
|
25 |
-
def generate_image(prompt, steps=28, seed=None, cfg_scale=3.5, width=1024, height=1024, lora_scale=
|
|
|
|
|
26 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
27 |
|
28 |
image = pipe(
|
29 |
prompt=prompt,
|
30 |
-
num_inference_steps=steps,
|
31 |
guidance_scale=cfg_scale,
|
32 |
-
width=width,
|
33 |
-
height=height,
|
34 |
generator=generator,
|
35 |
joint_attention_kwargs={"scale": lora_scale},
|
36 |
).images[0]
|
37 |
return image
|
38 |
|
39 |
-
def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
if randomize_seed or seed is None:
|
41 |
-
|
42 |
|
43 |
image = generate_image(prompt, steps, seed, cfg_scale, width, height, lora_scale)
|
44 |
return image, seed
|
|
|
22 |
MAX_SEED = 2**32-1
|
23 |
|
24 |
@spaces.GPU(duration=75)
|
25 |
+
def generate_image(prompt, steps=28, seed=None, cfg_scale=3.5, width=1024, height=1024, lora_scale=0.95):
|
26 |
+
if seed is None:
|
27 |
+
seed = random.randint(0, MAX_SEED)
|
28 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
29 |
|
30 |
image = pipe(
|
31 |
prompt=prompt,
|
32 |
+
num_inference_steps=int(steps),
|
33 |
guidance_scale=cfg_scale,
|
34 |
+
width=int(width),
|
35 |
+
height=int(height),
|
36 |
generator=generator,
|
37 |
joint_attention_kwargs={"scale": lora_scale},
|
38 |
).images[0]
|
39 |
return image
|
40 |
|
41 |
+
def run_lora(prompt, cfg_scale=3.5, steps=28, randomize_seed=True, seed=None, width=1024, height=1024, lora_scale=0.95):
|
42 |
+
# Handle the case when only prompt is provided (for Examples)
|
43 |
+
if isinstance(prompt, str) and all(param is None for param in [cfg_scale, steps, randomize_seed, seed, width, height, lora_scale]):
|
44 |
+
cfg_scale = 3.5
|
45 |
+
steps = 28
|
46 |
+
randomize_seed = True
|
47 |
+
seed = None
|
48 |
+
width = 1024
|
49 |
+
height = 1024
|
50 |
+
lora_scale = 0.95
|
51 |
+
|
52 |
if randomize_seed or seed is None:
|
53 |
+
seed = random.randint(0, MAX_SEED)
|
54 |
|
55 |
image = generate_image(prompt, steps, seed, cfg_scale, width, height, lora_scale)
|
56 |
return image, seed
|