Upload folder using huggingface_hub
Browse files- inference.py +2 -1
- internals/pipelines/replace_background.py +49 -16
- internals/util/slack.py +1 -0
inference.py
CHANGED
@@ -470,6 +470,7 @@ def replace_bg(task: Task):
|
|
470 |
steps=task.get_steps(),
|
471 |
resize_dimension=task.get_resize_dimension(),
|
472 |
product_scale_width=task.get_image_scale(),
|
|
|
473 |
conditioning_scale=task.rbg_controlnet_conditioning_scale(),
|
474 |
)
|
475 |
|
@@ -502,7 +503,7 @@ def load_model_by_task(task: Task):
|
|
502 |
safety_checker.apply(text2img_pipe)
|
503 |
safety_checker.apply(img2img_pipe)
|
504 |
elif task.get_type() == TaskType.REPLACE_BG:
|
505 |
-
replace_background.load(controlnet=controlnet)
|
506 |
else:
|
507 |
if task.get_type() == TaskType.TILE_UPSCALE:
|
508 |
controlnet.load_tile_upscaler()
|
|
|
470 |
steps=task.get_steps(),
|
471 |
resize_dimension=task.get_resize_dimension(),
|
472 |
product_scale_width=task.get_image_scale(),
|
473 |
+
apply_high_res=task.get_high_res_fix(),
|
474 |
conditioning_scale=task.rbg_controlnet_conditioning_scale(),
|
475 |
)
|
476 |
|
|
|
503 |
safety_checker.apply(text2img_pipe)
|
504 |
safety_checker.apply(img2img_pipe)
|
505 |
elif task.get_type() == TaskType.REPLACE_BG:
|
506 |
+
replace_background.load(controlnet=controlnet, high_res=high_res)
|
507 |
else:
|
508 |
if task.get_type() == TaskType.TILE_UPSCALE:
|
509 |
controlnet.load_tile_upscaler()
|
internals/pipelines/replace_background.py
CHANGED
@@ -14,6 +14,7 @@ import internals.util.image as ImageUtil
|
|
14 |
from internals.data.result import Result
|
15 |
from internals.pipelines.commons import AbstractPipeline
|
16 |
from internals.pipelines.controlnets import ControlNet
|
|
|
17 |
from internals.pipelines.remove_background import RemoveBackgroundV2
|
18 |
from internals.pipelines.upscaler import Upscaler
|
19 |
from internals.util.commons import download_image
|
@@ -28,6 +29,7 @@ class ReplaceBackground(AbstractPipeline):
|
|
28 |
upscaler: Optional[Upscaler] = None,
|
29 |
remove_background: Optional[RemoveBackgroundV2] = None,
|
30 |
controlnet: Optional[ControlNet] = None,
|
|
|
31 |
):
|
32 |
if self.__loaded:
|
33 |
return
|
@@ -53,9 +55,14 @@ class ReplaceBackground(AbstractPipeline):
|
|
53 |
pipe.to("cuda")
|
54 |
|
55 |
self.pipe = pipe
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
if not upscaler:
|
57 |
upscaler = Upscaler()
|
58 |
-
|
59 |
upscaler.load()
|
60 |
self.upscaler = upscaler
|
61 |
|
@@ -72,12 +79,13 @@ class ReplaceBackground(AbstractPipeline):
|
|
72 |
width: int,
|
73 |
height: int,
|
74 |
product_scale_width: float,
|
75 |
-
prompt:
|
76 |
-
negative_prompt:
|
77 |
resize_dimension: int,
|
78 |
conditioning_scale: float,
|
79 |
seed: int,
|
80 |
steps: int,
|
|
|
81 |
):
|
82 |
if type(image) is str:
|
83 |
image = download_image(image)
|
@@ -120,19 +128,44 @@ class ReplaceBackground(AbstractPipeline):
|
|
120 |
|
121 |
condition_image = ControlNet.linearart_condition_image(image)
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
images, has_nsfw = result
|
138 |
|
|
|
14 |
from internals.data.result import Result
|
15 |
from internals.pipelines.commons import AbstractPipeline
|
16 |
from internals.pipelines.controlnets import ControlNet
|
17 |
+
from internals.pipelines.high_res import HighRes
|
18 |
from internals.pipelines.remove_background import RemoveBackgroundV2
|
19 |
from internals.pipelines.upscaler import Upscaler
|
20 |
from internals.util.commons import download_image
|
|
|
29 |
upscaler: Optional[Upscaler] = None,
|
30 |
remove_background: Optional[RemoveBackgroundV2] = None,
|
31 |
controlnet: Optional[ControlNet] = None,
|
32 |
+
high_res: Optional[HighRes] = None,
|
33 |
):
|
34 |
if self.__loaded:
|
35 |
return
|
|
|
55 |
pipe.to("cuda")
|
56 |
|
57 |
self.pipe = pipe
|
58 |
+
|
59 |
+
if not high_res:
|
60 |
+
high_res = HighRes()
|
61 |
+
high_res.load()
|
62 |
+
self.high_res = high_res
|
63 |
+
|
64 |
if not upscaler:
|
65 |
upscaler = Upscaler()
|
|
|
66 |
upscaler.load()
|
67 |
self.upscaler = upscaler
|
68 |
|
|
|
79 |
width: int,
|
80 |
height: int,
|
81 |
product_scale_width: float,
|
82 |
+
prompt: List[str],
|
83 |
+
negative_prompt: List[str],
|
84 |
resize_dimension: int,
|
85 |
conditioning_scale: float,
|
86 |
seed: int,
|
87 |
steps: int,
|
88 |
+
apply_high_res: bool = False,
|
89 |
):
|
90 |
if type(image) is str:
|
91 |
image = download_image(image)
|
|
|
128 |
|
129 |
condition_image = ControlNet.linearart_condition_image(image)
|
130 |
|
131 |
+
if apply_high_res and hasattr(self, "high_res"):
|
132 |
+
(w, h) = self.high_res.get_intermediate_dimension(width, height)
|
133 |
+
images = self.pipe.__call__(
|
134 |
+
prompt=prompt,
|
135 |
+
negative_prompt=negative_prompt,
|
136 |
+
image=image,
|
137 |
+
mask_image=mask,
|
138 |
+
control_image=condition_image,
|
139 |
+
controlnet_conditioning_scale=conditioning_scale,
|
140 |
+
guidance_scale=9,
|
141 |
+
strength=1,
|
142 |
+
num_inference_steps=steps,
|
143 |
+
height=w,
|
144 |
+
width=h,
|
145 |
+
).images
|
146 |
+
result = self.high_res.apply(
|
147 |
+
prompt=prompt,
|
148 |
+
negative_prompt=negative_prompt,
|
149 |
+
images=images,
|
150 |
+
width=width,
|
151 |
+
height=width,
|
152 |
+
steps=steps,
|
153 |
+
)
|
154 |
+
else:
|
155 |
+
result = self.pipe.__call__(
|
156 |
+
prompt=prompt,
|
157 |
+
negative_prompt=negative_prompt,
|
158 |
+
image=image,
|
159 |
+
mask_image=mask,
|
160 |
+
control_image=condition_image,
|
161 |
+
controlnet_conditioning_scale=conditioning_scale,
|
162 |
+
guidance_scale=9,
|
163 |
+
strength=1,
|
164 |
+
height=height,
|
165 |
+
num_inference_steps=steps,
|
166 |
+
width=width,
|
167 |
+
)
|
168 |
+
result = Result.from_result(result)
|
169 |
|
170 |
images, has_nsfw = result
|
171 |
|
internals/util/slack.py
CHANGED
@@ -22,6 +22,7 @@ class Slack:
|
|
22 |
raw.pop("timestamp", None)
|
23 |
raw.pop("task_id", None)
|
24 |
raw.pop("maskImageUrl", None)
|
|
|
25 |
|
26 |
if args is not None:
|
27 |
raw.update(args.items())
|
|
|
22 |
raw.pop("timestamp", None)
|
23 |
raw.pop("task_id", None)
|
24 |
raw.pop("maskImageUrl", None)
|
25 |
+
raw.pop("aux_imageUrl", None)
|
26 |
|
27 |
if args is not None:
|
28 |
raw.update(args.items())
|