Spaces:
Runtime error
Runtime error
Update step counters to account for color quantization feature
Browse files- Add dynamic total_steps calculation based on enabled features
- Update all progress messages to use dynamic step counters
- Add progress messages when applying color quantization
- Handle both upscaling and non-upscaling paths correctly
Step flows now vary from 3 to 5 steps depending on features enabled:
- Base: 3 steps (QR generation, first pass, second pass)
- +1 step if upscaling is enabled
- +1 step if color quantization is enabled
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -1659,12 +1659,15 @@ def _pipeline_standard(
|
|
| 1659 |
yield None, error_msg
|
| 1660 |
return
|
| 1661 |
|
|
|
|
|
|
|
|
|
|
| 1662 |
# 1) Yield the base QR image as the first intermediate result
|
| 1663 |
base_qr_tensor = get_value_at_index(comfy_qr_by_module_size_15, 0)
|
| 1664 |
base_qr_np = (base_qr_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1665 |
base_qr_np = base_qr_np[0]
|
| 1666 |
base_qr_pil = Image.fromarray(base_qr_np)
|
| 1667 |
-
msg = "Generated base QR pattern… enhancing with AI (step 1/
|
| 1668 |
log_progress(msg, gr_progress, 0.05)
|
| 1669 |
yield base_qr_pil, msg
|
| 1670 |
|
|
@@ -1740,7 +1743,7 @@ def _pipeline_standard(
|
|
| 1740 |
mid_np = (mid_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1741 |
mid_np = mid_np[0]
|
| 1742 |
mid_pil = Image.fromarray(mid_np)
|
| 1743 |
-
msg = "First enhancement pass complete (step 2/
|
| 1744 |
log_progress(msg, gr_progress, 0.5)
|
| 1745 |
yield mid_pil, msg
|
| 1746 |
|
|
@@ -1804,7 +1807,8 @@ def _pipeline_standard(
|
|
| 1804 |
)
|
| 1805 |
pre_upscale_np = pre_upscale_np[0]
|
| 1806 |
pre_upscale_pil = Image.fromarray(pre_upscale_np)
|
| 1807 |
-
|
|
|
|
| 1808 |
log_progress(msg, gr_progress, 0.9)
|
| 1809 |
yield pre_upscale_pil, msg
|
| 1810 |
|
|
@@ -1819,9 +1823,14 @@ def _pipeline_standard(
|
|
| 1819 |
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1820 |
image_np = image_np[0]
|
| 1821 |
pil_image = Image.fromarray(image_np)
|
|
|
|
| 1822 |
|
| 1823 |
# Apply color quantization if enabled
|
| 1824 |
if enable_color_quantization:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1825 |
pil_image = apply_color_quantization(
|
| 1826 |
pil_image,
|
| 1827 |
colors=[color_1, color_2, color_3, color_4],
|
|
@@ -1830,8 +1839,9 @@ def _pipeline_standard(
|
|
| 1830 |
gradient_strength=gradient_strength,
|
| 1831 |
variation_steps=variation_steps,
|
| 1832 |
)
|
|
|
|
| 1833 |
|
| 1834 |
-
msg = "No errors, all good! Final QR art generated and upscaled. (step
|
| 1835 |
log_progress(msg, gr_progress, 1.0)
|
| 1836 |
yield (pil_image, msg)
|
| 1837 |
else:
|
|
@@ -1840,9 +1850,14 @@ def _pipeline_standard(
|
|
| 1840 |
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1841 |
image_np = image_np[0]
|
| 1842 |
pil_image = Image.fromarray(image_np)
|
|
|
|
| 1843 |
|
| 1844 |
# Apply color quantization if enabled
|
| 1845 |
if enable_color_quantization:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1846 |
pil_image = apply_color_quantization(
|
| 1847 |
pil_image,
|
| 1848 |
colors=[color_1, color_2, color_3, color_4],
|
|
@@ -1851,8 +1866,9 @@ def _pipeline_standard(
|
|
| 1851 |
gradient_strength=gradient_strength,
|
| 1852 |
variation_steps=variation_steps,
|
| 1853 |
)
|
|
|
|
| 1854 |
|
| 1855 |
-
msg = "No errors, all good! Final QR art generated."
|
| 1856 |
log_progress(msg, gr_progress, 1.0)
|
| 1857 |
yield pil_image, msg
|
| 1858 |
|
|
|
|
| 1659 |
yield None, error_msg
|
| 1660 |
return
|
| 1661 |
|
| 1662 |
+
# Calculate total steps based on enabled features
|
| 1663 |
+
total_steps = 3 + (1 if enable_upscale else 0) + (1 if enable_color_quantization else 0)
|
| 1664 |
+
|
| 1665 |
# 1) Yield the base QR image as the first intermediate result
|
| 1666 |
base_qr_tensor = get_value_at_index(comfy_qr_by_module_size_15, 0)
|
| 1667 |
base_qr_np = (base_qr_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1668 |
base_qr_np = base_qr_np[0]
|
| 1669 |
base_qr_pil = Image.fromarray(base_qr_np)
|
| 1670 |
+
msg = f"Generated base QR pattern… enhancing with AI (step 1/{total_steps})"
|
| 1671 |
log_progress(msg, gr_progress, 0.05)
|
| 1672 |
yield base_qr_pil, msg
|
| 1673 |
|
|
|
|
| 1743 |
mid_np = (mid_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1744 |
mid_np = mid_np[0]
|
| 1745 |
mid_pil = Image.fromarray(mid_np)
|
| 1746 |
+
msg = f"First enhancement pass complete (step 2/{total_steps})… refining details"
|
| 1747 |
log_progress(msg, gr_progress, 0.5)
|
| 1748 |
yield mid_pil, msg
|
| 1749 |
|
|
|
|
| 1807 |
)
|
| 1808 |
pre_upscale_np = pre_upscale_np[0]
|
| 1809 |
pre_upscale_pil = Image.fromarray(pre_upscale_np)
|
| 1810 |
+
current_step = 3
|
| 1811 |
+
msg = f"Enhancement complete (step {current_step}/{total_steps})... upscaling image"
|
| 1812 |
log_progress(msg, gr_progress, 0.9)
|
| 1813 |
yield pre_upscale_pil, msg
|
| 1814 |
|
|
|
|
| 1823 |
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1824 |
image_np = image_np[0]
|
| 1825 |
pil_image = Image.fromarray(image_np)
|
| 1826 |
+
current_step += 1
|
| 1827 |
|
| 1828 |
# Apply color quantization if enabled
|
| 1829 |
if enable_color_quantization:
|
| 1830 |
+
msg = f"Upscaling complete (step {current_step}/{total_steps})... applying color quantization"
|
| 1831 |
+
log_progress(msg, gr_progress, 0.95)
|
| 1832 |
+
yield pil_image, msg
|
| 1833 |
+
|
| 1834 |
pil_image = apply_color_quantization(
|
| 1835 |
pil_image,
|
| 1836 |
colors=[color_1, color_2, color_3, color_4],
|
|
|
|
| 1839 |
gradient_strength=gradient_strength,
|
| 1840 |
variation_steps=variation_steps,
|
| 1841 |
)
|
| 1842 |
+
current_step += 1
|
| 1843 |
|
| 1844 |
+
msg = f"No errors, all good! Final QR art generated and upscaled. (step {current_step}/{total_steps})"
|
| 1845 |
log_progress(msg, gr_progress, 1.0)
|
| 1846 |
yield (pil_image, msg)
|
| 1847 |
else:
|
|
|
|
| 1850 |
image_np = (image_tensor.detach().cpu().numpy() * 255).astype(np.uint8)
|
| 1851 |
image_np = image_np[0]
|
| 1852 |
pil_image = Image.fromarray(image_np)
|
| 1853 |
+
current_step = 3
|
| 1854 |
|
| 1855 |
# Apply color quantization if enabled
|
| 1856 |
if enable_color_quantization:
|
| 1857 |
+
msg = f"Enhancement complete (step {current_step}/{total_steps})... applying color quantization"
|
| 1858 |
+
log_progress(msg, gr_progress, 0.95)
|
| 1859 |
+
yield pil_image, msg
|
| 1860 |
+
|
| 1861 |
pil_image = apply_color_quantization(
|
| 1862 |
pil_image,
|
| 1863 |
colors=[color_1, color_2, color_3, color_4],
|
|
|
|
| 1866 |
gradient_strength=gradient_strength,
|
| 1867 |
variation_steps=variation_steps,
|
| 1868 |
)
|
| 1869 |
+
current_step += 1
|
| 1870 |
|
| 1871 |
+
msg = f"No errors, all good! Final QR art generated. (step {current_step}/{total_steps})"
|
| 1872 |
log_progress(msg, gr_progress, 1.0)
|
| 1873 |
yield pil_image, msg
|
| 1874 |
|