Spaces:
Running
on
Zero
Running
on
Zero
Update app_v4.py
Browse files
app_v4.py
CHANGED
|
@@ -150,6 +150,8 @@ def generate_focus(control_image, focus_list):
|
|
| 150 |
print(f"Error generating focus: {e}")
|
| 151 |
return "highly detailed photo, raw photography.", "Original Image Dimensions: N/A"
|
| 152 |
|
|
|
|
|
|
|
| 153 |
@spaces.GPU(duration=6, progress=gr.Progress(track_tqdm=True))
|
| 154 |
@torch.no_grad()
|
| 155 |
def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_scale, guidance_scale, seed, guidance_end):
|
|
@@ -162,21 +164,24 @@ def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_
|
|
| 162 |
# Crop to nearest multiple of 32
|
| 163 |
w = w - w % 32
|
| 164 |
h = h - h % 32
|
|
|
|
| 165 |
control_image = control_image.resize((w, h), resample=2)
|
| 166 |
print("Size to: " + str(control_image.size[0]) + ", " + str(control_image.size[1]))
|
| 167 |
print(f"PromptLog: {repr(prompt)}")
|
| 168 |
# Convert image to RGB for processing, but keep alpha channel for transparency
|
| 169 |
control_image_rgb = control_image.convert("RGB")
|
| 170 |
control_image_alpha = control_image.split()[-1]
|
| 171 |
-
# Convert alpha channel to a mask
|
| 172 |
alpha = np.array(control_image_alpha)
|
| 173 |
mask = (alpha > 128).astype(np.float32) # Create binary mask with 0 and 1
|
|
|
|
|
|
|
| 174 |
with torch.inference_mode():
|
| 175 |
image = pipe(
|
| 176 |
generator=generator,
|
| 177 |
prompt=prompt,
|
| 178 |
-
control_image=
|
| 179 |
-
mask_image=mask, # Pass
|
| 180 |
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 181 |
num_inference_steps=steps,
|
| 182 |
guidance_scale=guidance_scale,
|
|
|
|
| 150 |
print(f"Error generating focus: {e}")
|
| 151 |
return "highly detailed photo, raw photography.", "Original Image Dimensions: N/A"
|
| 152 |
|
| 153 |
+
|
| 154 |
+
|
| 155 |
@spaces.GPU(duration=6, progress=gr.Progress(track_tqdm=True))
|
| 156 |
@torch.no_grad()
|
| 157 |
def generate_image(prompt, scale, steps, control_image, controlnet_conditioning_scale, guidance_scale, seed, guidance_end):
|
|
|
|
| 164 |
# Crop to nearest multiple of 32
|
| 165 |
w = w - w % 32
|
| 166 |
h = h - h % 32
|
| 167 |
+
# Fix the resizing code (assuming scale is defined)
|
| 168 |
control_image = control_image.resize((w, h), resample=2)
|
| 169 |
print("Size to: " + str(control_image.size[0]) + ", " + str(control_image.size[1]))
|
| 170 |
print(f"PromptLog: {repr(prompt)}")
|
| 171 |
# Convert image to RGB for processing, but keep alpha channel for transparency
|
| 172 |
control_image_rgb = control_image.convert("RGB")
|
| 173 |
control_image_alpha = control_image.split()[-1]
|
| 174 |
+
# Convert alpha channel to a mask (0 for transparent, 1 for opaque)
|
| 175 |
alpha = np.array(control_image_alpha)
|
| 176 |
mask = (alpha > 128).astype(np.float32) # Create binary mask with 0 and 1
|
| 177 |
+
# Convert control_image_rgb to numpy array (if necessary)
|
| 178 |
+
control_image_rgb_np = np.array(control_image_rgb)
|
| 179 |
with torch.inference_mode():
|
| 180 |
image = pipe(
|
| 181 |
generator=generator,
|
| 182 |
prompt=prompt,
|
| 183 |
+
control_image=control_image_rgb_np, # Use numpy array
|
| 184 |
+
mask_image=mask, # Pass numpy mask
|
| 185 |
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 186 |
num_inference_steps=steps,
|
| 187 |
guidance_scale=guidance_scale,
|