Spaces:
Running
on
Zero
Running
on
Zero
Add .detach() before all .cpu().numpy() calls to fix gradient error with torch.compile
Browse files
app.py
CHANGED
|
@@ -1112,7 +1112,7 @@ def add_noise_to_border_only(
|
|
| 1112 |
return image_tensor
|
| 1113 |
|
| 1114 |
# Convert to numpy for manipulation
|
| 1115 |
-
img_np = image_tensor.cpu().numpy()
|
| 1116 |
|
| 1117 |
# Set random seed for reproducibility (ensure it's within numpy's valid range)
|
| 1118 |
np.random.seed(seed % (2**32))
|
|
@@ -1249,7 +1249,7 @@ def _pipeline_standard(
|
|
| 1249 |
|
| 1250 |
# 1) Yield the base QR image as the first intermediate result
|
| 1251 |
base_qr_tensor = get_value_at_index(comfy_qr_by_module_size_15, 0)
|
| 1252 |
-
base_qr_np = (base_qr_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1253 |
base_qr_np = base_qr_np[0]
|
| 1254 |
base_qr_pil = Image.fromarray(base_qr_np)
|
| 1255 |
msg = "Generated base QR pattern… enhancing with AI (step 1/3)"
|
|
@@ -1325,7 +1325,7 @@ def _pipeline_standard(
|
|
| 1325 |
|
| 1326 |
# 2) Yield the first decoded image as a second intermediate result
|
| 1327 |
mid_tensor = get_value_at_index(vaedecode_8, 0)
|
| 1328 |
-
mid_np = (mid_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1329 |
mid_np = mid_np[0]
|
| 1330 |
mid_pil = Image.fromarray(mid_np)
|
| 1331 |
msg = "First enhancement pass complete (step 2/3)… refining details"
|
|
@@ -1387,7 +1387,7 @@ def _pipeline_standard(
|
|
| 1387 |
if enable_upscale:
|
| 1388 |
# Show pre-upscale result
|
| 1389 |
pre_upscale_tensor = get_value_at_index(vaedecode_21, 0)
|
| 1390 |
-
pre_upscale_np = (pre_upscale_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1391 |
pre_upscale_np = pre_upscale_np[0]
|
| 1392 |
pre_upscale_pil = Image.fromarray(pre_upscale_np)
|
| 1393 |
msg = "Enhancement complete (step 3/4)... upscaling image"
|
|
@@ -1402,7 +1402,7 @@ def _pipeline_standard(
|
|
| 1402 |
)
|
| 1403 |
|
| 1404 |
image_tensor = get_value_at_index(upscaled, 0)
|
| 1405 |
-
image_np = (image_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1406 |
image_np = image_np[0]
|
| 1407 |
pil_image = Image.fromarray(image_np)
|
| 1408 |
msg = "No errors, all good! Final QR art generated and upscaled. (step 4/4)"
|
|
@@ -1411,7 +1411,7 @@ def _pipeline_standard(
|
|
| 1411 |
else:
|
| 1412 |
# No upscaling
|
| 1413 |
image_tensor = get_value_at_index(vaedecode_21, 0)
|
| 1414 |
-
image_np = (image_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1415 |
image_np = image_np[0]
|
| 1416 |
pil_image = Image.fromarray(image_np)
|
| 1417 |
msg = "No errors, all good! Final QR art generated."
|
|
@@ -1466,7 +1466,7 @@ def _pipeline_artistic(
|
|
| 1466 |
|
| 1467 |
# Show the base QR code
|
| 1468 |
base_qr_tensor = get_value_at_index(comfy_qr, 0)
|
| 1469 |
-
base_qr_np = (base_qr_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1470 |
base_qr_np = base_qr_np[0]
|
| 1471 |
base_qr_pil = Image.fromarray(base_qr_np)
|
| 1472 |
|
|
@@ -1497,7 +1497,7 @@ def _pipeline_artistic(
|
|
| 1497 |
)
|
| 1498 |
|
| 1499 |
# Show the noisy QR so you can see the border cubic pattern effect
|
| 1500 |
-
noisy_qr_np = (qr_with_border_noise.cpu().numpy() * 255).astype(np.uint8)
|
| 1501 |
noisy_qr_np = noisy_qr_np[0]
|
| 1502 |
noisy_qr_pil = Image.fromarray(noisy_qr_np)
|
| 1503 |
msg = f"Added QR-like cubics to border... enhancing with AI (step {current_step}/{total_steps})"
|
|
@@ -1622,7 +1622,7 @@ def _pipeline_artistic(
|
|
| 1622 |
|
| 1623 |
# Show first pass result
|
| 1624 |
first_pass_tensor = get_value_at_index(decoded, 0)
|
| 1625 |
-
first_pass_np = (first_pass_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1626 |
first_pass_np = first_pass_np[0]
|
| 1627 |
first_pass_pil = Image.fromarray(first_pass_np)
|
| 1628 |
msg = f"First enhancement pass complete (step {current_step}/{total_steps})... final refinement pass"
|
|
@@ -1693,7 +1693,7 @@ def _pipeline_artistic(
|
|
| 1693 |
if enable_upscale:
|
| 1694 |
# Show result before upscaling
|
| 1695 |
pre_upscale_tensor = get_value_at_index(final_decoded, 0)
|
| 1696 |
-
pre_upscale_np = (pre_upscale_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1697 |
pre_upscale_np = pre_upscale_np[0]
|
| 1698 |
pre_upscale_pil = Image.fromarray(pre_upscale_np)
|
| 1699 |
msg = f"Final refinement complete (step {current_step}/{total_steps})... upscaling image"
|
|
@@ -1710,7 +1710,7 @@ def _pipeline_artistic(
|
|
| 1710 |
|
| 1711 |
# Convert upscaled image to PIL Image and return
|
| 1712 |
image_tensor = get_value_at_index(upscaled, 0)
|
| 1713 |
-
image_np = (image_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1714 |
image_np = image_np[0]
|
| 1715 |
final_image = Image.fromarray(image_np)
|
| 1716 |
msg = f"No errors, all good! Final artistic QR code generated and upscaled. (step {current_step}/{total_steps})"
|
|
@@ -1719,7 +1719,7 @@ def _pipeline_artistic(
|
|
| 1719 |
else:
|
| 1720 |
# No upscaling
|
| 1721 |
image_tensor = get_value_at_index(final_decoded, 0)
|
| 1722 |
-
image_np = (image_tensor.cpu().numpy() * 255).astype(np.uint8)
|
| 1723 |
image_np = image_np[0]
|
| 1724 |
final_image = Image.fromarray(image_np)
|
| 1725 |
msg = f"No errors, all good! Final artistic QR code generated. (step {current_step}/{total_steps})"
|
|
|
|
| 1112 |
return image_tensor
|
| 1113 |
|
| 1114 |
# Convert to numpy for manipulation
|
| 1115 |
+
img_np = image_tensor.detach().cpu().numpy()
|
| 1116 |
|
| 1117 |
# Set random seed for reproducibility (ensure it's within numpy's valid range)
|
| 1118 |
np.random.seed(seed % (2**32))
|
|
|
|
| 1249 |
|
| 1250 |
# 1) Yield the base QR image as the first intermediate result
|
| 1251 |
base_qr_tensor = get_value_at_index(comfy_qr_by_module_size_15, 0)
|
| 1252 |
+
base_qr_np = (base_qr_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1253 |
base_qr_np = base_qr_np[0]
|
| 1254 |
base_qr_pil = Image.fromarray(base_qr_np)
|
| 1255 |
msg = "Generated base QR pattern… enhancing with AI (step 1/3)"
|
|
|
|
| 1325 |
|
| 1326 |
# 2) Yield the first decoded image as a second intermediate result
|
| 1327 |
mid_tensor = get_value_at_index(vaedecode_8, 0)
|
| 1328 |
+
mid_np = (mid_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1329 |
mid_np = mid_np[0]
|
| 1330 |
mid_pil = Image.fromarray(mid_np)
|
| 1331 |
msg = "First enhancement pass complete (step 2/3)… refining details"
|
|
|
|
| 1387 |
if enable_upscale:
|
| 1388 |
# Show pre-upscale result
|
| 1389 |
pre_upscale_tensor = get_value_at_index(vaedecode_21, 0)
|
| 1390 |
+
pre_upscale_np = (pre_upscale_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1391 |
pre_upscale_np = pre_upscale_np[0]
|
| 1392 |
pre_upscale_pil = Image.fromarray(pre_upscale_np)
|
| 1393 |
msg = "Enhancement complete (step 3/4)... upscaling image"
|
|
|
|
| 1402 |
)
|
| 1403 |
|
| 1404 |
image_tensor = get_value_at_index(upscaled, 0)
|
| 1405 |
+
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1406 |
image_np = image_np[0]
|
| 1407 |
pil_image = Image.fromarray(image_np)
|
| 1408 |
msg = "No errors, all good! Final QR art generated and upscaled. (step 4/4)"
|
|
|
|
| 1411 |
else:
|
| 1412 |
# No upscaling
|
| 1413 |
image_tensor = get_value_at_index(vaedecode_21, 0)
|
| 1414 |
+
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1415 |
image_np = image_np[0]
|
| 1416 |
pil_image = Image.fromarray(image_np)
|
| 1417 |
msg = "No errors, all good! Final QR art generated."
|
|
|
|
| 1466 |
|
| 1467 |
# Show the base QR code
|
| 1468 |
base_qr_tensor = get_value_at_index(comfy_qr, 0)
|
| 1469 |
+
base_qr_np = (base_qr_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1470 |
base_qr_np = base_qr_np[0]
|
| 1471 |
base_qr_pil = Image.fromarray(base_qr_np)
|
| 1472 |
|
|
|
|
| 1497 |
)
|
| 1498 |
|
| 1499 |
# Show the noisy QR so you can see the border cubic pattern effect
|
| 1500 |
+
noisy_qr_np = (qr_with_border_noise.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1501 |
noisy_qr_np = noisy_qr_np[0]
|
| 1502 |
noisy_qr_pil = Image.fromarray(noisy_qr_np)
|
| 1503 |
msg = f"Added QR-like cubics to border... enhancing with AI (step {current_step}/{total_steps})"
|
|
|
|
| 1622 |
|
| 1623 |
# Show first pass result
|
| 1624 |
first_pass_tensor = get_value_at_index(decoded, 0)
|
| 1625 |
+
first_pass_np = (first_pass_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1626 |
first_pass_np = first_pass_np[0]
|
| 1627 |
first_pass_pil = Image.fromarray(first_pass_np)
|
| 1628 |
msg = f"First enhancement pass complete (step {current_step}/{total_steps})... final refinement pass"
|
|
|
|
| 1693 |
if enable_upscale:
|
| 1694 |
# Show result before upscaling
|
| 1695 |
pre_upscale_tensor = get_value_at_index(final_decoded, 0)
|
| 1696 |
+
pre_upscale_np = (pre_upscale_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1697 |
pre_upscale_np = pre_upscale_np[0]
|
| 1698 |
pre_upscale_pil = Image.fromarray(pre_upscale_np)
|
| 1699 |
msg = f"Final refinement complete (step {current_step}/{total_steps})... upscaling image"
|
|
|
|
| 1710 |
|
| 1711 |
# Convert upscaled image to PIL Image and return
|
| 1712 |
image_tensor = get_value_at_index(upscaled, 0)
|
| 1713 |
+
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1714 |
image_np = image_np[0]
|
| 1715 |
final_image = Image.fromarray(image_np)
|
| 1716 |
msg = f"No errors, all good! Final artistic QR code generated and upscaled. (step {current_step}/{total_steps})"
|
|
|
|
| 1719 |
else:
|
| 1720 |
# No upscaling
|
| 1721 |
image_tensor = get_value_at_index(final_decoded, 0)
|
| 1722 |
+
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1723 |
image_np = image_np[0]
|
| 1724 |
final_image = Image.fromarray(image_np)
|
| 1725 |
msg = f"No errors, all good! Final artistic QR code generated. (step {current_step}/{total_steps})"
|