fffiloni commited on
Commit
6e5055d
·
verified ·
1 Parent(s): 4c29cb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -33
app.py CHANGED
@@ -8,33 +8,18 @@ from PIL import Image
8
  import cv2
9
 
10
  import torch
11
- from diffusers import StableDiffusion3Pipeline
12
- from diffusers.models.controlnet_sd3 import ControlNetSD3Model
13
- from diffusers.utils.torch_utils import randn_tensor
14
- from diffusers.utils import load_image
15
-
16
- # Clone the specific branch
17
- subprocess.run(["git", "clone", "-b", "sd3_control", "https://github.com/instantX-research/diffusers_sd3_control.git"])
18
-
19
- # Change directory to the cloned repository and install it
20
- os.chdir('diffusers_sd3_control')
21
- subprocess.run(["pip", "install", "-e", "."])
22
-
23
- # Add the path to the examples directory
24
- sys.path.append(os.path.abspath('./examples/community'))
25
-
26
- # Import the required pipeline
27
- from pipeline_stable_diffusion_3_controlnet import StableDiffusion3CommonPipeline
28
-
29
 
 
 
 
30
 
31
  # load pipeline
32
- base_model = 'stabilityai/stable-diffusion-3-medium-diffusers'
33
- pipe = StableDiffusion3CommonPipeline.from_pretrained(
34
- base_model,
35
- controlnet_list=['InstantX/SD3-Controlnet-Canny'],
36
  )
37
- pipe.to('cuda:0', torch.float16)
38
 
39
  def resize_image(input_path, output_path, target_height):
40
  # Open the input image
@@ -68,21 +53,13 @@ def infer(image_in, prompt, inference_steps, guidance_scale, control_weight, pro
68
  image_to_canny = np.concatenate([image_to_canny, image_to_canny, image_to_canny], axis=2)
69
  image_to_canny = Image.fromarray(image_to_canny)
70
 
71
- # controlnet config
72
- controlnet_conditioning = [
73
- dict(
74
- control_index=0,
75
- control_image=image_to_canny,
76
- control_weight=control_weight,
77
- control_pooled_projections='zeros'
78
- )
79
- ]
80
 
81
  # infer
82
  image = pipe(
83
  prompt=prompt,
84
  negative_prompt=n_prompt,
85
- controlnet_conditioning=controlnet_conditioning,
 
86
  num_inference_steps=inference_steps,
87
  guidance_scale=guidance_scale,
88
  ).images[0]
 
8
  import cv2
9
 
10
  import torch
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ from diffusers import StableDiffusion3ControlNetPipeline
13
+ from diffusers.models import SD3ControlNetModel, SD3MultiControlNetModel
14
+ from diffusers.utils import load_image
15
 
16
  # load pipeline
17
+ controlnet = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Canny")
18
+ pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
19
+ "stabilityai/stable-diffusion-3-medium-diffusers",
20
+ controlnet=controlnet
21
  )
22
+ pipe.to("cuda", torch.float16)
23
 
24
  def resize_image(input_path, output_path, target_height):
25
  # Open the input image
 
53
  image_to_canny = np.concatenate([image_to_canny, image_to_canny, image_to_canny], axis=2)
54
  image_to_canny = Image.fromarray(image_to_canny)
55
 
 
 
 
 
 
 
 
 
 
56
 
57
  # infer
58
  image = pipe(
59
  prompt=prompt,
60
  negative_prompt=n_prompt,
61
+ control_image=image_to_canny,
62
+ controlnet_conditioning_scale=control_weigth,
63
  num_inference_steps=inference_steps,
64
  guidance_scale=guidance_scale,
65
  ).images[0]