-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSd3ControlNet.py
More file actions
36 lines (31 loc) · 1.1 KB
/
Sd3ControlNet.py
File metadata and controls
36 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import torch
import sys
from diffusers import StableDiffusion3ControlNetPipeline
from diffusers.models import SD3ControlNetModel
from diffusers.utils import load_image
def main(prompt, filename, controlImage):
# load pipeline
controlnet = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Canny")
pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-3-medium-diffusers",
controlnet=controlnet
)
pipe.to("mps", torch.float16)
control_image = load_image(controlImage)
prompt = prompt
n_prompt = 'NSFW, nude, naked, porn, ugly'
image = pipe(
prompt,
negative_prompt=n_prompt,
control_image=control_image,
controlnet_conditioning_scale=0.75,
).images[0]
image.save(filename)
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: python script.py [prompt] [filename path] [controlImage path]")
sys.exit(1)
prompt = sys.argv[1]
filename = sys.argv[2] + ".png"
controlImage = sys.argv[3]
main(prompt, filename, controlImage)