patrickvonplaten
commited on
Commit
•
de1053e
1
Parent(s):
8d64486
add all scripts
Browse files- control_net_lineart.py +50 -0
control_net_lineart.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 LineartDetector
|
8 |
+
|
9 |
+
from diffusers import (
|
10 |
+
ControlNetModel,
|
11 |
+
StableDiffusionControlNetPipeline,
|
12 |
+
UniPCMultistepScheduler,
|
13 |
+
)
|
14 |
+
import sys
|
15 |
+
|
16 |
+
checkpoint = sys.argv[1]
|
17 |
+
|
18 |
+
url = "https://github.com/lllyasviel/ControlNet-v1-1-nightly/raw/main/test_imgs/bag.png"
|
19 |
+
url = "https://github.com/lllyasviel/ControlNet-v1-1-nightly/raw/main/test_imgs/person_1.jpeg"
|
20 |
+
image = load_image(url)
|
21 |
+
|
22 |
+
prompt = "michael jackson concert"
|
23 |
+
|
24 |
+
processor = LineartDetector.from_pretrained("lllyasviel/Annotators")
|
25 |
+
image = processor(image)
|
26 |
+
image.save("/home/patrick/images/check.png")
|
27 |
+
|
28 |
+
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
|
29 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
30 |
+
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
|
31 |
+
)
|
32 |
+
|
33 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
34 |
+
pipe.enable_model_cpu_offload()
|
35 |
+
|
36 |
+
generator = torch.manual_seed(0)
|
37 |
+
out_image = pipe(prompt, num_inference_steps=30, generator=generator, image=image).images[0]
|
38 |
+
|
39 |
+
path = os.path.join(Path.home(), "images", "aa.png")
|
40 |
+
out_image.save(path)
|
41 |
+
|
42 |
+
api = HfApi()
|
43 |
+
|
44 |
+
api.upload_file(
|
45 |
+
path_or_fileobj=path,
|
46 |
+
path_in_repo=path.split("/")[-1],
|
47 |
+
repo_id="patrickvonplaten/images",
|
48 |
+
repo_type="dataset",
|
49 |
+
)
|
50 |
+
print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
|