tori29umai commited on
Commit
6904b31
1 Parent(s): 967d328
Files changed (2) hide show
  1. app.py +5 -15
  2. utils/dl_utils.py +2 -2
app.py CHANGED
@@ -28,7 +28,6 @@ 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
33
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
34
  controlnet = ControlNetModel.from_pretrained(cn_dir, torch_dtype=dtype, use_safetensors=True)
@@ -37,22 +36,20 @@ def load_model(lora_dir, cn_dir):
37
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnet, vae=vae, torch_dtype=torch.float16
38
  )
39
  pipe.enable_model_cpu_offload()
40
- pipe.load_lora_weights(lora_dir, weight_name="normalmap.safetensors")
41
- # pipe = pipe.to(device)
42
  return pipe
43
 
44
-
45
  @spaces.GPU
46
  def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
47
  pipe = load_model(lora_dir, cn_dir)
48
  input_image = Image.open(input_image_path)
49
- base_image = base_generation(input_image.size, (150, 110, 255, 255)).convert("RGB")
50
  resize_image = resize_image_aspect_ratio(input_image)
51
  resize_base_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)
@@ -73,12 +70,9 @@ def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
73
  output_image = output_image.resize(input_image.size, Image.LANCZOS)
74
  return output_image
75
 
76
-
77
-
78
  class Img2Img:
79
  def __init__(self):
80
  self.demo = self.layout()
81
- self.post_filter = True
82
  self.tagger_model = None
83
  self.input_image_path = None
84
  self.canny_image = None
@@ -88,13 +82,10 @@ class Img2Img:
88
  if self.tagger_model is None:
89
  self.tagger_model = modelLoad(tagger_dir)
90
  tags = analysis(input_image_path, tagger_dir, self.tagger_model)
91
- tags_list = tags
92
- if self.post_filter:
93
- tags_list = remove_color(tags)
94
  return tags_list
95
 
96
 
97
-
98
  def layout(self):
99
  css = """
100
  #intro{
@@ -128,6 +119,5 @@ class Img2Img:
128
  )
129
  return demo
130
 
131
-
132
  img2img = Img2Img()
133
  img2img.demo.launch(share=True)
 
28
  dl_lora_model(lora_dir)
29
 
30
  def load_model(lora_dir, cn_dir):
 
31
  dtype = torch.float16
32
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
33
  controlnet = ControlNetModel.from_pretrained(cn_dir, torch_dtype=dtype, use_safetensors=True)
 
36
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnet, vae=vae, torch_dtype=torch.float16
37
  )
38
  pipe.enable_model_cpu_offload()
39
+ pipe.load_lora_weights(lora_dir, weight_name="lineart.safetensors")
 
40
  return pipe
41
 
 
42
  @spaces.GPU
43
  def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
44
  pipe = load_model(lora_dir, cn_dir)
45
  input_image = Image.open(input_image_path)
46
+ base_image = base_generation(input_image.size, (255, 255, 255, 255)).convert("RGB")
47
  resize_image = resize_image_aspect_ratio(input_image)
48
  resize_base_image = resize_image_aspect_ratio(base_image)
49
  generator = torch.manual_seed(0)
50
  last_time = time.time()
51
+ prompt = "masterpiece, best quality, monochrome, greyscale, lineart, white background, " + prompt
52
+ execute_tags = ["sketch", "transparent background"]
53
  prompt = execute_prompt(execute_tags, prompt)
54
  prompt = remove_duplicates(prompt)
55
  prompt = remove_color(prompt)
 
70
  output_image = output_image.resize(input_image.size, Image.LANCZOS)
71
  return output_image
72
 
 
 
73
  class Img2Img:
74
  def __init__(self):
75
  self.demo = self.layout()
 
76
  self.tagger_model = None
77
  self.input_image_path = None
78
  self.canny_image = None
 
82
  if self.tagger_model is None:
83
  self.tagger_model = modelLoad(tagger_dir)
84
  tags = analysis(input_image_path, tagger_dir, self.tagger_model)
85
+ tags_list = remove_color(tags)
 
 
86
  return tags_list
87
 
88
 
 
89
  def layout(self):
90
  css = """
91
  #intro{
 
119
  )
120
  return demo
121
 
 
122
  img2img = Img2Img()
123
  img2img.demo.launch(share=True)
utils/dl_utils.py CHANGED
@@ -57,10 +57,10 @@ def dl_tagger_model(model_dir):
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.safetensors"
64
  response = requests.get(url, allow_redirects=True)
65
  if response.status_code == 200:
66
  with open(file_path, 'wb') as f:
 
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: