BoredEmperor
commited on
Commit
•
b6cc863
1
Parent(s):
ce6ec3b
Upload control_net_lineart_anime.py
Browse files- control_net_lineart_anime.py +52 -0
control_net_lineart_anime.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 LineartAnimeDetector
|
8 |
+
from transformers import CLIPTextModel
|
9 |
+
|
10 |
+
from diffusers import (
|
11 |
+
ControlNetModel,
|
12 |
+
StableDiffusionControlNetPipeline,
|
13 |
+
UniPCMultistepScheduler,
|
14 |
+
)
|
15 |
+
import sys
|
16 |
+
|
17 |
+
checkpoint = sys.argv[1]
|
18 |
+
|
19 |
+
url = "https://static.wikia.nocookie.net/unanything/images/a/a0/Unnamed.png/revision/latest/scale-to-width-down/350?cb=20230326002111"
|
20 |
+
image = load_image(url)
|
21 |
+
|
22 |
+
prompt = "warrior girl"
|
23 |
+
|
24 |
+
processor = LineartAnimeDetector.from_pretrained("lllyasviel/Annotators")
|
25 |
+
image = processor(image)
|
26 |
+
image.save("/home/patrick/images/check.png")
|
27 |
+
|
28 |
+
text_encoder = CLIPTextModel.from_pretrained("Linaqruf/anything-v3.0", subfolder="text_encoder", num_hidden_layers=11, torch_dtype=torch.float16)
|
29 |
+
|
30 |
+
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
|
31 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
32 |
+
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, text_encoder=text_encoder, torch_dtype=torch.float16
|
33 |
+
)
|
34 |
+
|
35 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
36 |
+
pipe.enable_model_cpu_offload()
|
37 |
+
|
38 |
+
generator = torch.manual_seed(33)
|
39 |
+
out_image = pipe(prompt, num_inference_steps=25, generator=generator, image=image).images[0]
|
40 |
+
|
41 |
+
path = os.path.join(Path.home(), "images", "aa.png")
|
42 |
+
out_image.save(path)
|
43 |
+
|
44 |
+
api = HfApi()
|
45 |
+
|
46 |
+
api.upload_file(
|
47 |
+
path_or_fileobj=path,
|
48 |
+
path_in_repo=path.split("/")[-1],
|
49 |
+
repo_id="patrickvonplaten/images",
|
50 |
+
repo_type="dataset",
|
51 |
+
)
|
52 |
+
print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
|