CoolFace
Modelpublic

diffusers/tools

sourceHugging Facecreativeml-openrail-mupdated 3y agoView on Hugging Face
11likes28downloads
control_net_mlsd.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 PIL import Image8import numpy as np9from controlnet_aux import MLSDdetector10 11from diffusers import (12    ControlNetModel,13    StableDiffusionControlNetPipeline,14    UniPCMultistepScheduler,15)16import sys17 18checkpoint = sys.argv[1]19 20image = load_image("https://huggingface.co/lllyasviel/sd-controlnet-mlsd/resolve/main/images/room.png")21 22prompt = "royal chamber with fancy bed"23 24mlsd = MLSDdetector.from_pretrained('lllyasviel/ControlNet')25image = mlsd(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(0)36out_image = pipe(prompt, num_inference_steps=30, 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