mattyamonaca commited on
Commit
21f3a40
1 Parent(s): fe944ec
Files changed (2) hide show
  1. app.py +8 -6
  2. sd_model.py +13 -0
app.py CHANGED
@@ -5,7 +5,7 @@ from starline import process
5
  from utils import load_cn_model, load_cn_config, randomname
6
  from convertor import pil2cv, cv2pil
7
 
8
- from sd_model import get_cn_pipeline, get_cn_detector
9
  import cv2
10
  import os
11
  import numpy as np
@@ -20,8 +20,10 @@ cn_lineart_dir = f"{path}/controlnet/lineart"
20
 
21
  load_cn_model(cn_lineart_dir)
22
  load_cn_config(cn_lineart_dir)
23
- pipe = get_cn_pipeline()
24
- pipe.to("cuda")
 
 
25
 
26
 
27
 
@@ -33,8 +35,8 @@ def generate(detectors, prompt, negative_prompt, reference_flg=False, reference_
33
  negative_prompt = default_neg + negative_prompt
34
 
35
 
36
- if reference_flg==False:
37
- image = pipe(
38
  prompt=prompt,
39
  negative_prompt = negative_prompt,
40
  image=detectors,
@@ -44,7 +46,7 @@ def generate(detectors, prompt, negative_prompt, reference_flg=False, reference_
44
  ).images[0]
45
  else:
46
 
47
- image = pipe(
48
  prompt=prompt,
49
  negative_prompt = negative_prompt,
50
  image=detectors,
 
5
  from utils import load_cn_model, load_cn_config, randomname
6
  from convertor import pil2cv, cv2pil
7
 
8
+ from sd_model import get_cn_pipeline, get_cn_detector, get_ip_pipeline
9
  import cv2
10
  import os
11
  import numpy as np
 
20
 
21
  load_cn_model(cn_lineart_dir)
22
  load_cn_config(cn_lineart_dir)
23
+ pipe_cn = get_cn_pipeline()
24
+ pipe_ip = get_ip_pipeline()
25
+ pipe_cn.to("cuda")
26
+ pipe_ip.to("cuda")
27
 
28
 
29
 
 
35
  negative_prompt = default_neg + negative_prompt
36
 
37
 
38
+ if reference_flg==False and reference_img is not None:
39
+ image = pipe_ip(
40
  prompt=prompt,
41
  negative_prompt = negative_prompt,
42
  image=detectors,
 
46
  ).images[0]
47
  else:
48
 
49
+ image = pipe_cn(
50
  prompt=prompt,
51
  negative_prompt = negative_prompt,
52
  image=detectors,
sd_model.py CHANGED
@@ -12,6 +12,19 @@ def get_cn_pipeline():
12
  ControlNetModel.from_pretrained("mattyamonaca/controlnet_line2line_xl", torch_dtype=torch.float16)
13
  ]
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
16
  pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
17
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnets, vae=vae, torch_dtype=torch.float16
 
12
  ControlNetModel.from_pretrained("mattyamonaca/controlnet_line2line_xl", torch_dtype=torch.float16)
13
  ]
14
 
15
+ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
16
+ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
17
+ "cagliostrolab/animagine-xl-3.1", controlnet=controlnets, vae=vae, torch_dtype=torch.float16
18
+ )
19
+
20
+ return pipe
21
+
22
+ def get_ip_pipeline():
23
+ controlnets = [
24
+ ControlNetModel.from_pretrained("./controlnet/lineart", torch_dtype=torch.float16, use_safetensors=True),
25
+ ControlNetModel.from_pretrained("mattyamonaca/controlnet_line2line_xl", torch_dtype=torch.float16)
26
+ ]
27
+
28
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
29
  pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
30
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnets, vae=vae, torch_dtype=torch.float16