tori29umai commited on
Commit
168fc85
1 Parent(s): 6787f63
Files changed (2) hide show
  1. app.py +9 -15
  2. utils/dl_utils.py +3 -3
app.py CHANGED
@@ -7,7 +7,7 @@ import os
7
  import time
8
 
9
  from utils.dl_utils import dl_cn_model, dl_cn_config, dl_tagger_model, dl_lora_model
10
- from utils.image_utils import resize_image_aspect_ratio, base_generation, line_process
11
 
12
  from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
13
  from utils.tagger import modelLoad, analysis
@@ -27,12 +27,6 @@ dl_cn_config(cn_dir)
27
  dl_tagger_model(tagger_dir)
28
  dl_lora_model(lora_dir)
29
 
30
- def make_line(img_path, sigma, gamma):
31
- sigma = float(sigma )
32
- gamma = float(gamma)
33
- return line_process(img_path, sigma, gamma)
34
-
35
-
36
  def load_model(lora_dir, cn_dir):
37
  device = "cuda" if torch.cuda.is_available() else "cpu"
38
  dtype = torch.float16
@@ -42,8 +36,8 @@ def load_model(lora_dir, cn_dir):
42
  pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
43
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnet, vae=vae, torch_dtype=torch.float16
44
  )
45
- pipe.load_lora_weights(lora_dir, weight_name="lineart.safetensors")
46
- pipe.set_adapters(["lineart"], adapter_weights=[1.4])
47
  pipe.fuse_lora()
48
  pipe = pipe.to(device)
49
  return pipe
@@ -52,13 +46,13 @@ def load_model(lora_dir, cn_dir):
52
  @spaces.GPU
53
  def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
54
  pipe = load_model(lora_dir, cn_dir)
55
- line_image =make_line(input_image_path, 1.4, 0.98)
56
- base_size = line_image.size
57
- resize_image = resize_image_aspect_ratio(line_image)
58
  generator = torch.manual_seed(0)
59
  last_time = time.time()
60
- prompt = "masterpiece, best quality, monochrome, lineart, white background, " + prompt
61
- execute_tags = ["sketch", "transparent background"]
62
  prompt = execute_prompt(execute_tags, prompt)
63
  prompt = remove_duplicates(prompt)
64
  prompt = remove_color(prompt)
@@ -76,7 +70,7 @@ def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
76
  eta=1.0,
77
  ).images[0]
78
  print(f"Time taken: {time.time() - last_time}")
79
- output_image = output_image.resize(base_size, Image.LANCZOS)
80
  return output_image
81
 
82
 
 
7
  import time
8
 
9
  from utils.dl_utils import dl_cn_model, dl_cn_config, dl_tagger_model, dl_lora_model
10
+ from utils.image_utils import resize_image_aspect_ratio, base_generation
11
 
12
  from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
13
  from utils.tagger import modelLoad, analysis
 
27
  dl_tagger_model(tagger_dir)
28
  dl_lora_model(lora_dir)
29
 
 
 
 
 
 
 
30
  def load_model(lora_dir, cn_dir):
31
  device = "cuda" if torch.cuda.is_available() else "cpu"
32
  dtype = torch.float16
 
36
  pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
37
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnet, vae=vae, torch_dtype=torch.float16
38
  )
39
+ pipe.load_lora_weights(lora_dir, weight_name="normalmap.safetensors")
40
+ pipe.set_adapters(["normalmap"], adapter_weights=[1.4])
41
  pipe.fuse_lora()
42
  pipe = pipe.to(device)
43
  return pipe
 
46
  @spaces.GPU
47
  def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
48
  pipe = load_model(lora_dir, cn_dir)
49
+ input_image = Image.open(input_image_path)
50
+ base_image = base_generation(input_image.size, (150, 110, 255, 255)).convert("RGB")
51
+ resize_image = resize_image_aspect_ratio(base_image)
52
  generator = torch.manual_seed(0)
53
  last_time = time.time()
54
+ prompt = "masterpiece, best quality, normal map, purple background, " + prompt
55
+ execute_tags = ["monochrome", "greyscale", "lineart", "white background", "sketch", "transparent background"]
56
  prompt = execute_prompt(execute_tags, prompt)
57
  prompt = remove_duplicates(prompt)
58
  prompt = remove_color(prompt)
 
70
  eta=1.0,
71
  ).images[0]
72
  print(f"Time taken: {time.time() - last_time}")
73
+ output_image = output_image.resize(input_image.size, Image.LANCZOS)
74
  return output_image
75
 
76
 
utils/dl_utils.py CHANGED
@@ -11,7 +11,7 @@ import cv2
11
  def dl_cn_model(model_dir):
12
  folder = model_dir
13
  file_name = 'diffusion_pytorch_model.safetensors'
14
- url = "https://huggingface.co/2vXpSwA7/iroiro-lora/resolve/main/test_controlnet2/CN-anytest_v4-marged.safetensors"
15
  file_path = os.path.join(folder, file_name)
16
  if not os.path.exists(file_path):
17
  response = requests.get(url, allow_redirects=True)
@@ -57,10 +57,10 @@ def dl_tagger_model(model_dir):
57
 
58
 
59
  def dl_lora_model(model_dir):
60
- file_name = 'lineart.safetensors'
61
  file_path = os.path.join(model_dir, file_name)
62
  if not os.path.exists(file_path):
63
- url = "https://huggingface.co/tori29umai/lineart/resolve/main/sdxl_BWLine.safetensors"
64
  response = requests.get(url, allow_redirects=True)
65
  if response.status_code == 200:
66
  with open(file_path, 'wb') as f:
 
11
  def dl_cn_model(model_dir):
12
  folder = model_dir
13
  file_name = 'diffusion_pytorch_model.safetensors'
14
+ url = "https://huggingface.co/2vXpSwA7/iroiro-lora/resolve/main/test_controlnet2/CN-anytest_v3-50000_fp16.safetensors"
15
  file_path = os.path.join(folder, file_name)
16
  if not os.path.exists(file_path):
17
  response = requests.get(url, allow_redirects=True)
 
57
 
58
 
59
  def dl_lora_model(model_dir):
60
+ file_name = 'normalmap.safetensors'
61
  file_path = os.path.join(model_dir, file_name)
62
  if not os.path.exists(file_path):
63
+ url = "https://huggingface.co/tori29umai/SDXL_shadow/resolve/main/sdxl-testlora-normalmap_04b_dim32.safetensorss"
64
  response = requests.get(url, allow_redirects=True)
65
  if response.status_code == 200:
66
  with open(file_path, 'wb') as f: