Delete StableCascade.py
Browse files- StableCascade.py +0 -61
StableCascade.py
DELETED
|
@@ -1,61 +0,0 @@
|
|
| 1 |
-
# https://hf-mirror.com/stabilityai/stable-cascade
|
| 2 |
-
# https://hf-mirror.com/stabilityai/stable-cascade-prior
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
-
from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline, StableCascadeCombinedPipeline
|
| 6 |
-
|
| 7 |
-
cas = "stabilityai/stable-cascade"
|
| 8 |
-
cas_prior = "stabilityai/stable-cascade-prior"
|
| 9 |
-
|
| 10 |
-
def t2i_(prompt):
|
| 11 |
-
|
| 12 |
-
prior = StableCascadePriorPipeline.from_pretrained(cas_prior, variant="bf16", torch_dtype=torch.bfloat16)
|
| 13 |
-
decoder = StableCascadeDecoderPipeline.from_pretrained(cas, variant="bf16", torch_dtype=torch.float16)
|
| 14 |
-
|
| 15 |
-
prior.to("cuda")
|
| 16 |
-
decoder.to("cuda")
|
| 17 |
-
# prior.enable_model_cpu_offload()
|
| 18 |
-
# decoder.enable_model_cpu_offload()
|
| 19 |
-
|
| 20 |
-
prior_output = prior(
|
| 21 |
-
prompt=prompt,
|
| 22 |
-
height=1024,
|
| 23 |
-
width=1024,
|
| 24 |
-
negative_prompt="",
|
| 25 |
-
guidance_scale=4.0,
|
| 26 |
-
num_images_per_prompt=1,
|
| 27 |
-
num_inference_steps=20
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
image = decoder(
|
| 31 |
-
image_embeddings=prior_output.image_embeddings.to(torch.float16),
|
| 32 |
-
prompt=prompt,
|
| 33 |
-
negative_prompt="",
|
| 34 |
-
guidance_scale=0.0,
|
| 35 |
-
output_type="pil",
|
| 36 |
-
num_inference_steps=10
|
| 37 |
-
).images[0]
|
| 38 |
-
|
| 39 |
-
return image
|
| 40 |
-
|
| 41 |
-
def t2i(prompt):
|
| 42 |
-
pipe = StableCascadeCombinedPipeline.from_pretrained(cas, variant="bf16", torch_dtype=torch.bfloat16)
|
| 43 |
-
pipe.to("cuda")
|
| 44 |
-
|
| 45 |
-
image = pipe(
|
| 46 |
-
prompt=prompt,
|
| 47 |
-
negative_prompt="",
|
| 48 |
-
num_inference_steps=10,
|
| 49 |
-
prior_num_inference_steps=20,
|
| 50 |
-
prior_guidance_scale=3.0,
|
| 51 |
-
width=1024,
|
| 52 |
-
height=1024,
|
| 53 |
-
).images[0]
|
| 54 |
-
|
| 55 |
-
return image
|
| 56 |
-
|
| 57 |
-
if __name__ == "__main__":
|
| 58 |
-
prompt = "a girl in beijing"
|
| 59 |
-
image = t2i(prompt)
|
| 60 |
-
# image = t2i_(prompt)
|
| 61 |
-
image.save("stablecascade_output.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|