Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -227,6 +227,18 @@ def run_rmbg(img, sigma=0.0):
|
|
227 |
result = 127 + (img.astype(np.float32) - 127 + sigma) * alpha
|
228 |
return result.clip(0, 255).astype(np.uint8), alpha
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
@torch.inference_mode()
|
232 |
def process(input_fg, prompt, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
@@ -337,6 +349,7 @@ def process(input_fg, prompt, image_width, image_height, num_samples, seed, step
|
|
337 |
@torch.inference_mode()
|
338 |
def process_relight(input_fg, prompt, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
339 |
#input_fg, matting = run_rmbg(input_fg)
|
|
|
340 |
results = process(input_fg, prompt, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source)
|
341 |
return input_fg, results
|
342 |
|
|
|
227 |
result = 127 + (img.astype(np.float32) - 127 + sigma) * alpha
|
228 |
return result.clip(0, 255).astype(np.uint8), alpha
|
229 |
|
230 |
+
@torch.inference_mode()
|
231 |
+
def merge_alpha(img):
|
232 |
+
H, W, C = img.shape
|
233 |
+
print(f"img.shape: {img.shape}")
|
234 |
+
if C == 3:
|
235 |
+
return img
|
236 |
+
else:
|
237 |
+
rgb = img[:, :, :3]
|
238 |
+
alpha = img[:, :, 3] / 255.0
|
239 |
+
result = 127 + (rgb.astype(np.float32) - 127 + sigma) * alpha[:, :, np.newaxis]
|
240 |
+
return np.clip(result, 0, 255).astype(np.uint8)
|
241 |
+
|
242 |
|
243 |
@torch.inference_mode()
|
244 |
def process(input_fg, prompt, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
|
|
349 |
@torch.inference_mode()
|
350 |
def process_relight(input_fg, prompt, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
351 |
#input_fg, matting = run_rmbg(input_fg)
|
352 |
+
input_fg = merge_alpha(input_fg)
|
353 |
results = process(input_fg, prompt, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source)
|
354 |
return input_fg, results
|
355 |
|