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