Dark mode, debug decoder key matching
Browse files
app.py
CHANGED
|
@@ -185,11 +185,27 @@ def get_model():
|
|
| 185 |
decoder_state = {k.replace("gcode_decoder.", ""): v for k, v in state_dict.items()
|
| 186 |
if k.startswith("gcode_decoder.")}
|
| 187 |
if decoder_state:
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
else:
|
| 191 |
print("WARNING: No gcode_decoder weights found!")
|
| 192 |
-
print(f"Looking for keys starting with 'gcode_decoder.', but found: {[k for k in state_dict.keys() if 'decoder' in k.lower()][:10]}")
|
| 193 |
|
| 194 |
gcode_decoder.eval()
|
| 195 |
|
|
@@ -291,23 +307,37 @@ def gcode_to_svg(gcode: str) -> str:
|
|
| 291 |
h = BOUNDS["top"] - BOUNDS["bottom"]
|
| 292 |
padding = 20
|
| 293 |
|
| 294 |
-
#
|
| 295 |
svg = f'''<svg xmlns="http://www.w3.org/2000/svg"
|
| 296 |
viewBox="{BOUNDS["left"] - padding} {-BOUNDS["top"] - padding} {w + 2*padding} {h + 2*padding}"
|
| 297 |
-
style="
|
| 298 |
-
<
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
'''
|
| 301 |
|
| 302 |
for path in paths:
|
| 303 |
if len(path) < 2:
|
| 304 |
continue
|
| 305 |
d = " ".join(f"{'M' if i == 0 else 'L'}{p[0]:.1f},{-p[1]:.1f}" for i, p in enumerate(path))
|
| 306 |
-
svg += f'<path d="{d}" fill="none" stroke
|
| 307 |
|
| 308 |
total_points = sum(len(p) for p in paths)
|
| 309 |
svg += f'''
|
| 310 |
-
<text x="{BOUNDS["left"] + 8}" y="{-BOUNDS["top"] + 20}"
|
| 311 |
{len(paths)} paths / {total_points} points
|
| 312 |
</text>
|
| 313 |
'''
|
|
@@ -394,56 +424,93 @@ def generate(prompt: str, temperature: float, max_tokens: int, num_steps: int, g
|
|
| 394 |
return f"; Error: {e}", gcode_to_svg("")
|
| 395 |
|
| 396 |
|
| 397 |
-
# Minimal monochrome CSS
|
| 398 |
css = """
|
| 399 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&display=swap');
|
| 400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
* {
|
| 402 |
font-family: 'IBM Plex Mono', monospace !important;
|
| 403 |
}
|
| 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
.gradio-container {
|
| 406 |
max-width: 900px !important;
|
| 407 |
margin: auto;
|
| 408 |
-
background: #fff !important;
|
| 409 |
}
|
| 410 |
|
| 411 |
-
.gr-button
|
| 412 |
-
background:
|
| 413 |
-
border: 1px solid
|
| 414 |
-
color:
|
| 415 |
font-weight: 500 !important;
|
| 416 |
}
|
| 417 |
|
| 418 |
-
.gr-button
|
| 419 |
-
background:
|
| 420 |
}
|
| 421 |
|
| 422 |
.gr-examples {
|
| 423 |
margin-top: 8px !important;
|
| 424 |
}
|
| 425 |
|
| 426 |
-
.gr-examples .gr-sample-textbox {
|
| 427 |
-
display: inline-block !important;
|
| 428 |
-
margin-right: 8px !important;
|
| 429 |
-
}
|
| 430 |
-
|
| 431 |
footer {
|
| 432 |
display: none !important;
|
| 433 |
}
|
| 434 |
|
| 435 |
-
h1 {
|
| 436 |
-
|
| 437 |
-
letter-spacing: -0.02em !important;
|
| 438 |
}
|
| 439 |
|
| 440 |
-
.gr-box {
|
| 441 |
-
|
| 442 |
-
border: 1px solid
|
|
|
|
| 443 |
}
|
| 444 |
|
| 445 |
input, textarea {
|
| 446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
}
|
| 448 |
"""
|
| 449 |
|
|
|
|
| 185 |
decoder_state = {k.replace("gcode_decoder.", ""): v for k, v in state_dict.items()
|
| 186 |
if k.startswith("gcode_decoder.")}
|
| 187 |
if decoder_state:
|
| 188 |
+
# Check what keys the model expects vs what we have
|
| 189 |
+
model_keys = set(gcode_decoder.state_dict().keys())
|
| 190 |
+
ckpt_keys = set(decoder_state.keys())
|
| 191 |
+
missing = model_keys - ckpt_keys
|
| 192 |
+
extra = ckpt_keys - model_keys
|
| 193 |
+
print(f"Decoder: model expects {len(model_keys)} keys, checkpoint has {len(ckpt_keys)}")
|
| 194 |
+
if missing:
|
| 195 |
+
print(f"Missing keys: {list(missing)[:5]}")
|
| 196 |
+
if extra:
|
| 197 |
+
print(f"Extra keys: {list(extra)[:5]}")
|
| 198 |
+
|
| 199 |
+
# Try loading with strict=True to see errors
|
| 200 |
+
try:
|
| 201 |
+
gcode_decoder.load_state_dict(decoder_state, strict=True)
|
| 202 |
+
print(f"Loaded {len(decoder_state)} decoder weights (strict)")
|
| 203 |
+
except Exception as e:
|
| 204 |
+
print(f"Strict load failed: {e}")
|
| 205 |
+
gcode_decoder.load_state_dict(decoder_state, strict=False)
|
| 206 |
+
print(f"Loaded {len(decoder_state)} decoder weights (non-strict)")
|
| 207 |
else:
|
| 208 |
print("WARNING: No gcode_decoder weights found!")
|
|
|
|
| 209 |
|
| 210 |
gcode_decoder.eval()
|
| 211 |
|
|
|
|
| 307 |
h = BOUNDS["top"] - BOUNDS["bottom"]
|
| 308 |
padding = 20
|
| 309 |
|
| 310 |
+
# Dark mode compatible SVG
|
| 311 |
svg = f'''<svg xmlns="http://www.w3.org/2000/svg"
|
| 312 |
viewBox="{BOUNDS["left"] - padding} {-BOUNDS["top"] - padding} {w + 2*padding} {h + 2*padding}"
|
| 313 |
+
style="width: 100%; height: 480px; border: 1px solid var(--border, #e0e0e0); border-radius: 4px;">
|
| 314 |
+
<style>
|
| 315 |
+
@media (prefers-color-scheme: dark) {{
|
| 316 |
+
.bg {{ fill: #2a2b30; }}
|
| 317 |
+
.work {{ fill: #212226; stroke: #3a3b40; }}
|
| 318 |
+
.stroke {{ stroke: #e8e8e8; }}
|
| 319 |
+
.label {{ fill: #666; }}
|
| 320 |
+
}}
|
| 321 |
+
@media (prefers-color-scheme: light) {{
|
| 322 |
+
.bg {{ fill: #fff; }}
|
| 323 |
+
.work {{ fill: #fafafa; stroke: #ccc; }}
|
| 324 |
+
.stroke {{ stroke: #1a1a1a; }}
|
| 325 |
+
.label {{ fill: #999; }}
|
| 326 |
+
}}
|
| 327 |
+
</style>
|
| 328 |
+
<rect class="bg" x="{BOUNDS["left"] - padding}" y="{-BOUNDS["top"] - padding}" width="{w + 2*padding}" height="{h + 2*padding}"/>
|
| 329 |
+
<rect class="work" x="{BOUNDS["left"]}" y="{-BOUNDS["top"]}" width="{w}" height="{h}" stroke-width="1"/>
|
| 330 |
'''
|
| 331 |
|
| 332 |
for path in paths:
|
| 333 |
if len(path) < 2:
|
| 334 |
continue
|
| 335 |
d = " ".join(f"{'M' if i == 0 else 'L'}{p[0]:.1f},{-p[1]:.1f}" for i, p in enumerate(path))
|
| 336 |
+
svg += f'<path class="stroke" d="{d}" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>'
|
| 337 |
|
| 338 |
total_points = sum(len(p) for p in paths)
|
| 339 |
svg += f'''
|
| 340 |
+
<text class="label" x="{BOUNDS["left"] + 8}" y="{-BOUNDS["top"] + 20}" font-family="monospace" font-size="12">
|
| 341 |
{len(paths)} paths / {total_points} points
|
| 342 |
</text>
|
| 343 |
'''
|
|
|
|
| 424 |
return f"; Error: {e}", gcode_to_svg("")
|
| 425 |
|
| 426 |
|
| 427 |
+
# Minimal monochrome CSS with dark mode
|
| 428 |
css = """
|
| 429 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&display=swap');
|
| 430 |
|
| 431 |
+
:root {
|
| 432 |
+
--bg: #ffffff;
|
| 433 |
+
--bg-secondary: #fafafa;
|
| 434 |
+
--text: #1a1a1a;
|
| 435 |
+
--text-secondary: #666;
|
| 436 |
+
--border: #e0e0e0;
|
| 437 |
+
--btn-bg: #f0f0f0;
|
| 438 |
+
--btn-hover: #e0e0e0;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
@media (prefers-color-scheme: dark) {
|
| 442 |
+
:root {
|
| 443 |
+
--bg: #212226;
|
| 444 |
+
--bg-secondary: #2a2b30;
|
| 445 |
+
--text: #e8e8e8;
|
| 446 |
+
--text-secondary: #999;
|
| 447 |
+
--border: #3a3b40;
|
| 448 |
+
--btn-bg: #3a3b40;
|
| 449 |
+
--btn-hover: #4a4b50;
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
* {
|
| 454 |
font-family: 'IBM Plex Mono', monospace !important;
|
| 455 |
}
|
| 456 |
|
| 457 |
+
body, .gradio-container {
|
| 458 |
+
background: var(--bg) !important;
|
| 459 |
+
color: var(--text) !important;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
.gradio-container {
|
| 463 |
max-width: 900px !important;
|
| 464 |
margin: auto;
|
|
|
|
| 465 |
}
|
| 466 |
|
| 467 |
+
.gr-button {
|
| 468 |
+
background: var(--btn-bg) !important;
|
| 469 |
+
border: 1px solid var(--border) !important;
|
| 470 |
+
color: var(--text) !important;
|
| 471 |
font-weight: 500 !important;
|
| 472 |
}
|
| 473 |
|
| 474 |
+
.gr-button:hover {
|
| 475 |
+
background: var(--btn-hover) !important;
|
| 476 |
}
|
| 477 |
|
| 478 |
.gr-examples {
|
| 479 |
margin-top: 8px !important;
|
| 480 |
}
|
| 481 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
footer {
|
| 483 |
display: none !important;
|
| 484 |
}
|
| 485 |
|
| 486 |
+
h1, h2, h3, p, span, label {
|
| 487 |
+
color: var(--text) !important;
|
|
|
|
| 488 |
}
|
| 489 |
|
| 490 |
+
.gr-box, .gr-panel, .gr-form {
|
| 491 |
+
background: var(--bg-secondary) !important;
|
| 492 |
+
border: 1px solid var(--border) !important;
|
| 493 |
+
border-radius: 4px !important;
|
| 494 |
}
|
| 495 |
|
| 496 |
input, textarea {
|
| 497 |
+
background: var(--bg) !important;
|
| 498 |
+
color: var(--text) !important;
|
| 499 |
+
border: 1px solid var(--border) !important;
|
| 500 |
+
border-radius: 4px !important;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
.gr-accordion {
|
| 504 |
+
background: var(--bg-secondary) !important;
|
| 505 |
+
border: 1px solid var(--border) !important;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
a {
|
| 509 |
+
color: var(--text-secondary) !important;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
a:hover {
|
| 513 |
+
color: var(--text) !important;
|
| 514 |
}
|
| 515 |
"""
|
| 516 |
|