jayparmr commited on
Commit
f256b62
·
1 Parent(s): 8aeb9e5

Upload folder using huggingface_hub

Browse files
inference.py CHANGED
@@ -14,11 +14,18 @@ from internals.pipelines.prompt_modifier import PromptModifier
14
  from internals.pipelines.safety_checker import SafetyChecker
15
  from internals.util.args import apply_style_args
16
  from internals.util.avatar import Avatar
17
- from internals.util.cache import (auto_clear_cuda_and_gc, clear_cuda,
18
- clear_cuda_and_gc)
19
- from internals.util.commons import pickPoses, upload_image, upload_images
20
- from internals.util.config import (num_return_sequences, set_configs_from_task,
21
- set_root_dir)
 
 
 
 
 
 
 
22
  from internals.util.failure_hander import FailureHandler
23
  from internals.util.lora_style import LoraStyle
24
  from internals.util.slack import Slack
@@ -293,7 +300,12 @@ def pose(task: Task, s3_outkey: str = "_pose", poses: Optional[list] = None):
293
  lora_patcher = lora_style.get_patcher(controlnet.pipe2, task.get_style())
294
  lora_patcher.patch()
295
 
296
- if task.get_pose_coordinates():
 
 
 
 
 
297
  infered_pose = pose_detector.transform(
298
  image=task.get_imageUrl(),
299
  client_coordinates=task.get_pose_coordinates(),
 
14
  from internals.pipelines.safety_checker import SafetyChecker
15
  from internals.util.args import apply_style_args
16
  from internals.util.avatar import Avatar
17
+ from internals.util.cache import auto_clear_cuda_and_gc, clear_cuda, clear_cuda_and_gc
18
+ from internals.util.commons import (
19
+ download_image,
20
+ pickPoses,
21
+ upload_image,
22
+ upload_images,
23
+ )
24
+ from internals.util.config import (
25
+ num_return_sequences,
26
+ set_configs_from_task,
27
+ set_root_dir,
28
+ )
29
  from internals.util.failure_hander import FailureHandler
30
  from internals.util.lora_style import LoraStyle
31
  from internals.util.slack import Slack
 
300
  lora_patcher = lora_style.get_patcher(controlnet.pipe2, task.get_style())
301
  lora_patcher.patch()
302
 
303
+ if not task.get_pose_estimation():
304
+ pose = download_image(task.get_imageUrl()).resize(
305
+ (task.get_width(), task.get_height())
306
+ )
307
+ poses = [pose] * num_return_sequences
308
+ elif task.get_pose_coordinates():
309
  infered_pose = pose_detector.transform(
310
  image=task.get_imageUrl(),
311
  client_coordinates=task.get_pose_coordinates(),
inference2.py CHANGED
@@ -7,17 +7,18 @@ from internals.data.task import ModelType, Task, TaskType
7
  from internals.pipelines.inpainter import InPainter
8
  from internals.pipelines.object_remove import ObjectRemoval
9
  from internals.pipelines.prompt_modifier import PromptModifier
10
- from internals.pipelines.remove_background import (RemoveBackground,
11
- RemoveBackgroundV2)
12
  from internals.pipelines.replace_background import ReplaceBackground
13
  from internals.pipelines.safety_checker import SafetyChecker
14
  from internals.pipelines.upscaler import Upscaler
15
  from internals.util.avatar import Avatar
16
  from internals.util.cache import auto_clear_cuda_and_gc, clear_cuda
17
- from internals.util.commons import (construct_default_s3_url, upload_image,
18
- upload_images)
19
- from internals.util.config import (num_return_sequences, set_configs_from_task,
20
- set_root_dir)
 
 
21
  from internals.util.failure_hander import FailureHandler
22
  from internals.util.slack import Slack
23
 
@@ -41,8 +42,8 @@ replace_background = ReplaceBackground()
41
  @update_db
42
  @slack.auto_send_alert
43
  def remove_bg(task: Task):
44
- remove_background = RemoveBackground()
45
- output_image = remove_background.remove(task.get_imageUrl())
46
 
47
  output_key = "crecoAI/{}_rmbg.png".format(task.get_taskId())
48
  upload_image(output_image, output_key)
 
7
  from internals.pipelines.inpainter import InPainter
8
  from internals.pipelines.object_remove import ObjectRemoval
9
  from internals.pipelines.prompt_modifier import PromptModifier
10
+ from internals.pipelines.remove_background import RemoveBackground, RemoveBackgroundV2
 
11
  from internals.pipelines.replace_background import ReplaceBackground
12
  from internals.pipelines.safety_checker import SafetyChecker
13
  from internals.pipelines.upscaler import Upscaler
14
  from internals.util.avatar import Avatar
15
  from internals.util.cache import auto_clear_cuda_and_gc, clear_cuda
16
+ from internals.util.commons import construct_default_s3_url, upload_image, upload_images
17
+ from internals.util.config import (
18
+ num_return_sequences,
19
+ set_configs_from_task,
20
+ set_root_dir,
21
+ )
22
  from internals.util.failure_hander import FailureHandler
23
  from internals.util.slack import Slack
24
 
 
42
  @update_db
43
  @slack.auto_send_alert
44
  def remove_bg(task: Task):
45
+ # remove_background = RemoveBackground()
46
+ output_image = remove_background_v2.remove(task.get_imageUrl())
47
 
48
  output_key = "crecoAI/{}_rmbg.png".format(task.get_taskId())
49
  upload_image(output_image, output_key)
internals/data/task.py CHANGED
@@ -97,6 +97,9 @@ class Task:
97
  def get_pose_coordinates(self) -> dict:
98
  return self.__data.get("pose_coordinates", None)
99
 
 
 
 
100
  def get_negative_prompt(self) -> str:
101
  return self.__data.get("negative_prompt", "")
102
 
 
97
  def get_pose_coordinates(self) -> dict:
98
  return self.__data.get("pose_coordinates", None)
99
 
100
+ def get_pose_estimation(self) -> bool:
101
+ return self.__data.get("pose_estimation", True)
102
+
103
  def get_negative_prompt(self) -> str:
104
  return self.__data.get("negative_prompt", "")
105
 
internals/pipelines/controlnets.py CHANGED
@@ -4,21 +4,17 @@ import cv2
4
  import numpy as np
5
  import torch
6
  from controlnet_aux import HEDdetector, LineartDetector, OpenposeDetector
7
- from diffusers import (
8
- ControlNetModel,
9
- DiffusionPipeline,
10
- StableDiffusionControlNetPipeline,
11
- UniPCMultistepScheduler,
12
- )
13
  from PIL import Image
14
  from torch.nn import Linear
15
  from tqdm import gui
16
 
17
  from internals.data.result import Result
18
  from internals.pipelines.commons import AbstractPipeline
19
- from internals.pipelines.tileUpscalePipeline import (
20
- StableDiffusionControlNetImg2ImgPipeline,
21
- )
22
  from internals.util.cache import clear_cuda_and_gc
23
  from internals.util.commons import download_image
24
 
@@ -291,7 +287,7 @@ class ControlNet(AbstractPipeline):
291
  def detect_pose(self, imageUrl: str) -> Image.Image:
292
  detector = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
293
  image = download_image(imageUrl)
294
- image = detector.__call__(image, hand_and_face=True)
295
  return image
296
 
297
  def __scribble_condition_image(self, image: Image.Image) -> Image.Image:
 
4
  import numpy as np
5
  import torch
6
  from controlnet_aux import HEDdetector, LineartDetector, OpenposeDetector
7
+ from diffusers import (ControlNetModel, DiffusionPipeline,
8
+ StableDiffusionControlNetPipeline,
9
+ UniPCMultistepScheduler)
 
 
 
10
  from PIL import Image
11
  from torch.nn import Linear
12
  from tqdm import gui
13
 
14
  from internals.data.result import Result
15
  from internals.pipelines.commons import AbstractPipeline
16
+ from internals.pipelines.tileUpscalePipeline import \
17
+ StableDiffusionControlNetImg2ImgPipeline
 
18
  from internals.util.cache import clear_cuda_and_gc
19
  from internals.util.commons import download_image
20
 
 
287
  def detect_pose(self, imageUrl: str) -> Image.Image:
288
  detector = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
289
  image = download_image(imageUrl)
290
+ image = detector.__call__(image)
291
  return image
292
 
293
  def __scribble_condition_image(self, image: Image.Image) -> Image.Image:
internals/pipelines/pose_detector.py CHANGED
@@ -79,7 +79,7 @@ class PoseDetector:
79
  return {"candidate": new_points, "subset": data["subset"]}
80
 
81
  def create_pose(self, data: dict, width: int, height: int) -> Image.Image:
82
- image = Image.new("RGB", (width, height), "black")
83
  draw = ImageDraw.Draw(image)
84
 
85
  points: list = data["candidate"]
@@ -164,24 +164,43 @@ class PoseDetector:
164
 
165
  __kim = [0, 17, 6, 8, 10, 5, 7, 9, 12, 14, 16, 11, 13, 15, 2, 1, 4, 3]
166
  __pose_logical_map = [
167
- [1, 2, "#000099"],
168
- [1, 16, "#330099"],
169
- [1, 15, "#660099"],
170
- [16, 18, "#990099"],
171
- [15, 17, "#990066"],
172
- [2, 3, "#990001"],
173
- [2, 6, "#993301"],
174
- [3, 4, "#996502"],
175
- [4, 5, "#999900"],
176
- [6, 7, "#669900"],
177
- [7, 8, "#349900"],
178
- [2, 9, "#009900"],
179
- [2, 12, "#009999"],
180
- [9, 10, "#009966"],
181
- [10, 11, "#009966"],
182
- [12, 13, "#006699"],
183
- [13, 14, "#013399"],
184
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  __points_color = [
186
  "#ff0000",
187
  "#ff5600",
 
79
  return {"candidate": new_points, "subset": data["subset"]}
80
 
81
  def create_pose(self, data: dict, width: int, height: int) -> Image.Image:
82
+ image = Image.new("RGBA", (width, height), "black")
83
  draw = ImageDraw.Draw(image)
84
 
85
  points: list = data["candidate"]
 
164
 
165
  __kim = [0, 17, 6, 8, 10, 5, 7, 9, 12, 14, 16, 11, 13, 15, 2, 1, 4, 3]
166
  __pose_logical_map = [
167
+ [2, 3, (255, 0, 0, 153)],
168
+ [3, 4, (255, 85, 0, 153)],
169
+ [4, 5, (255, 170, 0, 153)],
170
+ [2, 6, (255, 255, 0, 153)],
171
+ [6, 7, (170, 255, 0, 153)],
172
+ [7, 8, (85, 255, 0, 153)],
173
+ [2, 9, (0, 255, 0, 153)],
174
+ [9, 10, (0, 255, 85, 153)],
175
+ [10, 11, (0, 255, 170, 153)],
176
+ [2, 12, (0, 255, 255, 153)],
177
+ [12, 13, (0, 170, 255, 153)],
178
+ [13, 14, (0, 85, 255, 153)],
179
+ [2, 1, (0, 0, 255, 153)],
180
+ [1, 15, (85, 0, 255, 153)],
181
+ [15, 17, (170, 0, 255, 153)],
182
+ [1, 16, (255, 0, 255, 153)],
183
+ [16, 18, (255, 0, 170, 153)],
184
  ]
185
+ # __pose_logical_map = [
186
+ # [1, 2, "#000099"],
187
+ # [1, 16, "#330099"],
188
+ # [1, 15, "#660099"],
189
+ # [16, 18, "#990099"],
190
+ # [15, 17, "#990066"],
191
+ # [2, 3, "#990001"],
192
+ # [2, 6, "#993301"],
193
+ # [3, 4, "#996502"],
194
+ # [4, 5, "#999900"],
195
+ # [6, 7, "#669900"],
196
+ # [7, 8, "#349900"],
197
+ # [2, 9, "#009900"],
198
+ # [2, 12, "#009999"],
199
+ # [9, 10, "#009966"],
200
+ # [10, 11, "#009966"],
201
+ # [12, 13, "#006699"],
202
+ # [13, 14, "#013399"],
203
+ # ]
204
  __points_color = [
205
  "#ff0000",
206
  "#ff5600",