diffusers/tools
1128
1#!/usr/bin/env python32import torch3import os4from huggingface_hub import HfApi5from pathlib import Path6from diffusers.utils import load_image7from controlnet_aux import ContentShuffleDetector8 9from diffusers import (10 ControlNetModel,11 EulerDiscreteScheduler,12 EulerDiscreteScheduler,13 StableDiffusionControlNetPipeline,14 UniPCMultistepScheduler,15)16import sys17 18checkpoint = sys.argv[1]19 20url = "https://github.com/lllyasviel/ControlNet-v1-1-nightly/raw/main/test_imgs/city.jpg"21image = load_image(url)22 23prompt = "New York"24 25 26processor = ContentShuffleDetector()27image = processor(image)28 29controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)30pipe = StableDiffusionControlNetPipeline.from_pretrained(31 "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float1632)33 34# pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)35pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)36pipe.enable_model_cpu_offload()37 38generator = torch.manual_seed(33)39out_image = pipe(prompt, num_inference_steps=20, generator=generator, image=image).images[0]40 41path = os.path.join(Path.home(), "images", "aa.png")42out_image.save(path)43 44api = HfApi()45 46api.upload_file(47 path_or_fileobj=path,48 path_in_repo=path.split("/")[-1],49 repo_id="patrickvonplaten/images",50 repo_type="dataset",51)52print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")53 