Spaces:
Sleeping
Sleeping
Pedro Cuenca
commited on
Commit
·
f5fe7df
1
Parent(s):
060afc3
Use constants.
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ SELECT_LABEL = "Select as seed"
|
|
15 |
MODEL_ID = "CompVis/ldm-text2im-large-256"
|
16 |
STEPS = 50
|
17 |
ETA = 0.3
|
18 |
-
GUIDANCE_SCALE =
|
19 |
|
20 |
ldm = DiffusionPipeline.from_pretrained(MODEL_ID)
|
21 |
|
@@ -31,14 +31,19 @@ with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
|
|
31 |
return images[0]
|
32 |
|
33 |
def infer_grid(prompt, n=6, seeds=[]):
|
34 |
-
# Unfortunately we have to iterate instead requesting all images at once,
|
35 |
-
# because we have no way to get the generation seeds.
|
36 |
result = defaultdict(list)
|
37 |
for _, seed in zip_longest(range(n), seeds, fillvalue=None):
|
38 |
seed = random.randint(0, 2**32 - 1) if seed is None else seed
|
39 |
print(f"Setting seed {seed}")
|
40 |
_ = torch.manual_seed(seed)
|
41 |
-
images = ldm(
|
|
|
|
|
|
|
|
|
|
|
42 |
result["images"].append(images[0])
|
43 |
result["seeds"].append(seed)
|
44 |
return result["images"], result["seeds"]
|
|
|
15 |
MODEL_ID = "CompVis/ldm-text2im-large-256"
|
16 |
STEPS = 50
|
17 |
ETA = 0.3
|
18 |
+
GUIDANCE_SCALE = 6
|
19 |
|
20 |
ldm = DiffusionPipeline.from_pretrained(MODEL_ID)
|
21 |
|
|
|
31 |
return images[0]
|
32 |
|
33 |
def infer_grid(prompt, n=6, seeds=[]):
|
34 |
+
# Unfortunately we have to iterate instead of requesting all images at once,
|
35 |
+
# because we have no way to get the intermediate generation seeds.
|
36 |
result = defaultdict(list)
|
37 |
for _, seed in zip_longest(range(n), seeds, fillvalue=None):
|
38 |
seed = random.randint(0, 2**32 - 1) if seed is None else seed
|
39 |
print(f"Setting seed {seed}")
|
40 |
_ = torch.manual_seed(seed)
|
41 |
+
images = ldm(
|
42 |
+
[prompt],
|
43 |
+
num_inference_steps=STEPS,
|
44 |
+
eta=ETA,
|
45 |
+
guidance_scale=GUIDANCE_SCALE
|
46 |
+
)["sample"]
|
47 |
result["images"].append(images[0])
|
48 |
result["seeds"].append(seed)
|
49 |
return result["images"], result["seeds"]
|