leonardo_iania commited on
Commit
5447ca9
·
1 Parent(s): d717f07

first comm

Browse files
control_net_canny.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import torch
3
+ import os
4
+ from huggingface_hub import HfApi
5
+ from pathlib import Path
6
+ from diffusers.utils import load_image
7
+ from controlnet_aux import CannyDetector
8
+
9
+ from diffusers import (
10
+ ControlNetModel,
11
+ StableDiffusionControlNetPipeline,
12
+ UniPCMultistepScheduler,
13
+ )
14
+ import sys
15
+
16
+ checkpoint = sys.argv[1]
17
+
18
+ image = load_image(
19
+ "https://huggingface.co/lllyasviel/sd-controlnet-canny/resolve/main/images/bird.png"
20
+ )
21
+
22
+ canny_detector = CannyDetector()
23
+ canny_image = canny_detector(image, low_threshold=100, high_threshold=200)
24
+
25
+ controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
26
+ pipe = StableDiffusionControlNetPipeline.from_pretrained(
27
+ "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
28
+ )
29
+
30
+ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
31
+ pipe.enable_model_cpu_offload()
32
+
33
+ generator = torch.manual_seed(33)
34
+ out_image = pipe("a blue paradise bird in the jungle", num_inference_steps=20, generator=generator, image=canny_image).images[0]
35
+
36
+ path = os.path.join(Path.home(), "images", "aa.png")
37
+ out_image.save(path)
38
+
39
+ api = HfApi()
40
+
41
+ api.upload_file(
42
+ path_or_fileobj=path,
43
+ path_in_repo=path.split("/")[-1],
44
+ repo_id="patrickvonplaten/images",
45
+ repo_type="dataset",
46
+ )
47
+ print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
diffusion_pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62364453cb4230f0e94669b4d36d723c292622268c3d5e30ed4aff128c7509f1
3
+ size 1445254969
diffusion_pytorch_model.fp16.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b80be83ccaf52d8d0c136323e88befe73994d7d416e534f410e46e3ed2cab9b
3
+ size 722698343
diffusion_pytorch_model.fp16.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ed3a7f834aca0d2b26f9c7f186b3ee29465de1d13e152459e8c9cbb25a0c0bc
3
+ size 722598642
diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be713fb941fc7c625f0c7d816b6a19115783a665f3049a8974f127e0c075d9a9
3
+ size 1445157124