debug canny
Browse files- app-controlnet.py +10 -2
- controlnet/index.html +15 -1
app-controlnet.py
CHANGED
|
@@ -126,6 +126,7 @@ class InputParams(BaseModel):
|
|
| 126 |
controlnet_end: float = 1.0
|
| 127 |
canny_low_threshold: float = 0.31
|
| 128 |
canny_high_threshold: float = 0.78
|
|
|
|
| 129 |
|
| 130 |
def predict(
|
| 131 |
input_image: Image.Image, params: InputParams, prompt_embeds: torch.Tensor = None
|
|
@@ -133,7 +134,6 @@ def predict(
|
|
| 133 |
generator = torch.manual_seed(params.seed)
|
| 134 |
|
| 135 |
control_image = canny_torch(input_image, params.canny_low_threshold, params.canny_high_threshold)
|
| 136 |
-
print(params.canny_low_threshold, params.canny_high_threshold)
|
| 137 |
results = pipe(
|
| 138 |
control_image=control_image,
|
| 139 |
prompt_embeds=prompt_embeds,
|
|
@@ -157,7 +157,15 @@ def predict(
|
|
| 157 |
)
|
| 158 |
if nsfw_content_detected:
|
| 159 |
return None
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
|
| 163 |
app = FastAPI()
|
|
|
|
| 126 |
controlnet_end: float = 1.0
|
| 127 |
canny_low_threshold: float = 0.31
|
| 128 |
canny_high_threshold: float = 0.78
|
| 129 |
+
debug_canny: bool = False
|
| 130 |
|
| 131 |
def predict(
|
| 132 |
input_image: Image.Image, params: InputParams, prompt_embeds: torch.Tensor = None
|
|
|
|
| 134 |
generator = torch.manual_seed(params.seed)
|
| 135 |
|
| 136 |
control_image = canny_torch(input_image, params.canny_low_threshold, params.canny_high_threshold)
|
|
|
|
| 137 |
results = pipe(
|
| 138 |
control_image=control_image,
|
| 139 |
prompt_embeds=prompt_embeds,
|
|
|
|
| 157 |
)
|
| 158 |
if nsfw_content_detected:
|
| 159 |
return None
|
| 160 |
+
result_image = results.images[0]
|
| 161 |
+
if params.debug_canny:
|
| 162 |
+
# paste control_image on top of result_image
|
| 163 |
+
w0, h0 = (128, 128)
|
| 164 |
+
control_image = control_image.resize((w0, h0))
|
| 165 |
+
w1, h1 = result_image.size
|
| 166 |
+
result_image.paste(control_image, (w1 - w0, h1 - h0))
|
| 167 |
+
|
| 168 |
+
return result_image
|
| 169 |
|
| 170 |
|
| 171 |
app = FastAPI()
|
controlnet/index.html
CHANGED
|
@@ -16,7 +16,12 @@
|
|
| 16 |
</style>
|
| 17 |
<script type="module">
|
| 18 |
// you can change the size of the input image to 768x768 if you have a powerful GPU
|
| 19 |
-
const getValue = (id) =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
const startBtn = document.querySelector("#start");
|
| 21 |
const stopBtn = document.querySelector("#stop");
|
| 22 |
const videoEl = document.querySelector("#webcam");
|
|
@@ -115,6 +120,7 @@
|
|
| 115 |
"controlnet_end": getValue("#controlnet_end"),
|
| 116 |
"canny_low_threshold": getValue("#canny_low_threshold"),
|
| 117 |
"canny_high_threshold": getValue("#canny_high_threshold"),
|
|
|
|
| 118 |
}));
|
| 119 |
}
|
| 120 |
let mediaDevices = [];
|
|
@@ -381,6 +387,14 @@
|
|
| 381 |
</div>
|
| 382 |
</div>
|
| 383 |
<!-- -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
</div>
|
| 385 |
</details>
|
| 386 |
</div>
|
|
|
|
| 16 |
</style>
|
| 17 |
<script type="module">
|
| 18 |
// you can change the size of the input image to 768x768 if you have a powerful GPU
|
| 19 |
+
const getValue = (id) => {
|
| 20 |
+
const el = document.querySelector(`${id}`)
|
| 21 |
+
if (el.type === "checkbox")
|
| 22 |
+
return el.checked;
|
| 23 |
+
return el.value;
|
| 24 |
+
}
|
| 25 |
const startBtn = document.querySelector("#start");
|
| 26 |
const stopBtn = document.querySelector("#stop");
|
| 27 |
const videoEl = document.querySelector("#webcam");
|
|
|
|
| 120 |
"controlnet_end": getValue("#controlnet_end"),
|
| 121 |
"canny_low_threshold": getValue("#canny_low_threshold"),
|
| 122 |
"canny_high_threshold": getValue("#canny_high_threshold"),
|
| 123 |
+
"debug_canny": getValue("#debug_canny")
|
| 124 |
}));
|
| 125 |
}
|
| 126 |
let mediaDevices = [];
|
|
|
|
| 387 |
</div>
|
| 388 |
</div>
|
| 389 |
<!-- -->
|
| 390 |
+
<!-- -->
|
| 391 |
+
<label class="text-sm font-medium" for="debug_canny">Debug Canny</label>
|
| 392 |
+
<div class="col-span-2 flex gap-2">
|
| 393 |
+
<input type="checkbox" id="debug_canny" name="debug_canny" class="cursor-pointer">
|
| 394 |
+
<label for="debug_canny" class="text-sm cursor-pointer"></label>
|
| 395 |
+
</div>
|
| 396 |
+
<div></div>
|
| 397 |
+
<!-- -->
|
| 398 |
</div>
|
| 399 |
</details>
|
| 400 |
</div>
|