CoolFace
Modelpublic

diffusers/tools

sourceHugging Facecreativeml-openrail-mupdated 3y agoView on Hugging Face
11likes27downloads
control_net_pix2pix.py46 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 np9 10from diffusers import (11    ControlNetModel,12    StableDiffusionControlNetPipeline,13    UniPCMultistepScheduler,14)15import sys16 17checkpoint = sys.argv[1]18 19image = load_image("https://huggingface.co/lllyasviel/sd-controlnet-seg/resolve/main/images/house.png").convert('RGB')20 21prompt = "make it on fire"22 23controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)24pipe = StableDiffusionControlNetPipeline.from_pretrained(25    "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float1626)27 28pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)29pipe.enable_model_cpu_offload()30 31generator = torch.manual_seed(0)32out_image = pipe(prompt, num_inference_steps=30, generator=generator, image=image).images[0]33 34path = os.path.join(Path.home(), "images", "aa.png")35out_image.save(path)36 37api = HfApi()38 39api.upload_file(40    path_or_fileobj=path,41    path_in_repo=path.split("/")[-1],42    repo_id="patrickvonplaten/images",43    repo_type="dataset",44)45print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")46