CoolFace
Modelpublic

diffusers/tools

sourceHugging Facecreativeml-openrail-mupdated 3y agoView on Hugging Face
11likes28downloads
control_net_normalbae.py50 linesDownload Raw Back to root
1#!/usr/bin/env python32import torch3import os4from huggingface_hub import HfApi5from pathlib import Path6from diffusers.utils import load_image7from controlnet_aux import NormalBaeDetector8 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/person-leaves.png"19image = load_image(url)20 21prompt = "A head full of roses"22 23 24processor = NormalBaeDetector.from_pretrained("lllyasviel/Annotators")25image = processor(image)26 27controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)28pipe = StableDiffusionControlNetPipeline.from_pretrained(29    "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float1630)31 32pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)33pipe.enable_model_cpu_offload()34 35generator = torch.manual_seed(33)36out_image = pipe(prompt, num_inference_steps=20, generator=generator, image=image).images[0]37 38path = os.path.join(Path.home(), "images", "aa.png")39out_image.save(path)40 41api = HfApi()42 43api.upload_file(44    path_or_fileobj=path,45    path_in_repo=path.split("/")[-1],46    repo_id="patrickvonplaten/images",47    repo_type="dataset",48)49print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")50