File size: 2,808 Bytes
69f6fc2 6d8ff37 78ed83d 2f0087d 78ed83d 6d8ff37 69f6fc2 b6badad b88c59f 69f6fc2 6d8ff37 269cbe7 6d8ff37 69f6fc2 78ed83d 6d8ff37 69f6fc2 a032108 6d8ff37 a032108 269cbe7 6d8ff37 a032108 ae23482 6d8ff37 ae23482 a032108 ae23482 6d8ff37 ae23482 6d8ff37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#!/usr/bin/env python3
from diffusers import StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
import time
import os
from huggingface_hub import HfApi
# from compel import Compel
import torch
import sys
from pathlib import Path
import requests
from PIL import Image
from io import BytesIO
# path = sys.argv[1]
path = "runwayml/stable-diffusion-v1-5"
path = "ptx0/pseudo-journey-v2"
# path = "stabilityai/stable-diffusion-2-1"
api = HfApi()
start_time = time.time()
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
# pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None)
# pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config)
# compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
pipe = pipe.to("cuda")
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
# rompts = ["a cat playing with a ball++ in the forest", "a cat playing with a ball++ in the forest", "a cat playing with a ball-- in the forest"]
# prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])
# generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]
#
# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
#
# response = requests.get(url)
# image = Image.open(BytesIO(response.content)).convert("RGB")
# image.thumbnail((768, 768))
#
for TIMESTEP_TYPE in ["trailing", "leading"]:
for RESCALE_BETAS_ZEROS_SNR in [True, False]:
for GUIDANCE_RESCALE in [0,0, 0.7]:
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing=TIMESTEP_TYPE, rescale_betas_zero_snr=RESCALE_BETAS_ZEROS_SNR)
generator = torch.Generator(device="cpu").manual_seed(0)
images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=4, num_inference_steps=40, guidance_rescale=GUIDANCE_RESCALE).images
for i, image in enumerate(images):
file_name = f"bb_{i}_{TIMESTEP_TYPE}_{str(int(RESCALE_BETAS_ZEROS_SNR))}_{GUIDANCE_RESCALE}"
path = os.path.join(Path.home(), "images", f"{file_name}.png")
image.save(path)
api.upload_file(
path_or_fileobj=path,
path_in_repo=path.split("/")[-1],
repo_id="patrickvonplaten/images",
repo_type="dataset",
)
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|