Spaces:
Running on Zero
Running on Zero
File size: 39,707 Bytes
75dd181 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multimodal-Edge-Comparator</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0d0d0f;
--grid: #1a1a1f;
--node-bg: #13131a;
--node-header: #1c1c26;
--node-border: #2a2a3a;
--accent: #7c6af7;
--accent2: #4ecdc4;
--accent3: #ff6b6b;
--text: #e8e8f0;
--muted: #6b6b8a;
--port: #4ecdc4;
--wire: #2a2a4a;
--wire-active: #7c6af7;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
min-height: 100%; background: var(--bg);
color: var(--text); font-family: 'JetBrains Mono', monospace;
}
body {
background-image:
radial-gradient(circle at 20% 50%, rgba(124,106,247,0.04) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(78,205,196,0.04) 0%, transparent 50%),
linear-gradient(var(--grid) 1px, transparent 1px),
linear-gradient(90deg, var(--grid) 1px, transparent 1px);
background-size: 100% 100%, 100% 100%, 24px 24px, 24px 24px;
overflow-x: auto; overflow-y: auto;
}
/* ββ Top Bar ββ */
.top-bar {
position: sticky; top: 0; left: 0; right: 0; height: 42px;
background: rgba(13,13,15,0.95); border-bottom: 1px solid var(--node-border);
display: flex; align-items: center; padding: 0 20px;
gap: 12px; z-index: 1000; backdrop-filter: blur(12px);
}
.top-bar .logo { font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }
.top-bar .sep { color: var(--node-border); }
.top-bar .sub { font-size: 11px; color: var(--muted); }
.top-bar .badge {
margin-left: auto; background: rgba(124,106,247,0.15);
border: 1px solid rgba(124,106,247,0.3); padding: 3px 10px;
border-radius: 20px; font-size: 10px; color: var(--accent);
}
/* ββ Canvas ββ */
#canvas {
position: relative; width: 1360px;
min-height: calc(100vh - 42px); height: 900px; margin: 0 auto;
}
svg.wires {
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
pointer-events: none; z-index: 2; overflow: visible;
}
path.wire { fill: none; stroke: var(--wire); stroke-width: 2.5; stroke-linecap: round; }
path.wire.active {
stroke: var(--wire-active); stroke-width: 3;
stroke-dasharray: 8 4; animation: flow 0.6s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -24; } }
/* ββ Nodes ββ */
.node {
position: absolute; width: 295px;
background: var(--node-bg); border: 1px solid var(--node-border);
border-radius: 9px; box-shadow: 0 8px 28px rgba(0,0,0,0.5);
z-index: 10; display: flex; flex-direction: column; transition: box-shadow 0.2s;
}
.node:hover { box-shadow: 0 8px 28px rgba(0,0,0,0.5), 0 0 0 1px rgba(124,106,247,0.3); }
.node.fixed-height { height: 340px; }
.node-header {
background: var(--node-header); padding: 7px 12px;
border-bottom: 1px solid var(--node-border); border-radius: 9px 9px 0 0;
font-size: 11px; font-weight: 700; cursor: grab;
display: flex; justify-content: space-between; align-items: center;
flex-shrink: 0; user-select: none;
}
.node-header:active { cursor: grabbing; }
.node-header .id {
font-size: 10px; color: var(--muted);
background: rgba(255,255,255,0.04); padding: 2px 7px; border-radius: 4px;
}
.node-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; overflow: hidden; }
/* ββ Ports ββ */
.port {
position: absolute; width: 11px; height: 11px;
background: var(--node-bg); border: 2px solid var(--port);
border-radius: 50%; z-index: 30;
}
.port.out { right: -6px; }
.port.in { left: -6px; }
/* ββ Labels ββ */
label {
font-size: 10px; color: var(--muted); font-weight: 600;
display: block; margin-bottom: 3px; letter-spacing: 0.07em; text-transform: uppercase;
}
input[type="file"] { display: none; }
/* ββ Upload Zone ββ */
.file-upload {
border: 1.5px dashed var(--node-border); border-radius: 7px; padding: 12px 10px;
text-align: center; cursor: pointer; font-size: 11px; color: var(--muted);
transition: border-color 0.2s, background 0.2s; background: rgba(255,255,255,0.01);
display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.file-upload:hover { border-color: var(--accent); background: rgba(124,106,247,0.04); }
.file-upload svg { opacity: 0.5; transition: opacity 0.2s; }
.file-upload:hover svg { opacity: 0.9; }
/* ββ Preview wrapper ββ */
.preview-wrap {
display: none; position: relative; border-radius: 7px;
overflow: hidden; border: 1px solid var(--node-border); background: #000;
}
.preview-wrap.visible { display: block; }
.img-preview { width: 100%; height: 170px; object-fit: contain; display: block; }
/* ββ Clear button ββ */
.clear-btn {
position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
border-radius: 50%; background: rgba(13,13,15,0.80);
border: 1px solid var(--node-border); color: var(--accent3); cursor: pointer;
display: flex; align-items: center; justify-content: center;
transition: background 0.18s, border-color 0.18s, transform 0.12s;
z-index: 20; backdrop-filter: blur(6px);
}
.clear-btn:hover { background: rgba(255,107,107,0.18); border-color: var(--accent3); transform: scale(1.08); }
.clear-btn:active { transform: scale(0.95); }
.clear-btn svg { pointer-events: none; }
/* ββ Filename chip ββ */
.img-chip {
display: none; align-items: center; gap: 6px;
background: rgba(124,106,247,0.08); border: 1px solid rgba(124,106,247,0.22);
border-radius: 5px; padding: 4px 8px; font-size: 9px; color: var(--muted); overflow: hidden;
}
.img-chip.visible { display: flex; }
.img-chip .chip-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent2); flex-shrink: 0; box-shadow: 0 0 4px var(--accent2); }
.img-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; color: var(--text); font-size: 9px; }
.img-chip .chip-size { color: var(--muted); flex-shrink: 0; font-size: 9px; }
select, textarea {
width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--node-border);
color: var(--text); padding: 7px 9px; border-radius: 5px; outline: none;
font-size: 11px; font-family: 'JetBrains Mono', monospace;
resize: none; transition: border-color 0.2s;
}
select:focus, textarea:focus { border-color: var(--accent); }
select option { background: #1c1c26; }
button.run-btn {
background: linear-gradient(135deg, var(--accent), #9b59b6);
color: #fff; border: none; padding: 8px; border-radius: 6px;
font-weight: 700; font-size: 11px; font-family: 'JetBrains Mono', monospace;
cursor: pointer; transition: opacity 0.2s, transform 0.1s;
display: flex; justify-content: center; align-items: center; gap: 8px;
letter-spacing: 0.04em; flex-shrink: 0;
}
button.run-btn:hover { opacity: 0.9; }
button.run-btn:active { transform: scale(0.98); }
button.run-btn:disabled { background: var(--node-border); cursor: not-allowed; color: #555; }
/* ββ Output node ββ */
.output-node-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; overflow: hidden; }
.output-header-row { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
/* ββ Icon buttons ββ */
.icon-btn {
display: flex; align-items: center; gap: 5px;
background: rgba(124,106,247,0.10); border: 1px solid rgba(124,106,247,0.25);
border-radius: 5px; padding: 3px 8px; font-size: 9px; font-weight: 700;
font-family: 'JetBrains Mono', monospace; color: var(--accent); cursor: pointer;
letter-spacing: 0.05em; transition: background 0.18s, border-color 0.18s, transform 0.1s;
flex-shrink: 0; text-decoration: none;
}
.icon-btn:hover { background: rgba(124,106,247,0.22); border-color: var(--accent); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn.teal { background: rgba(78,205,196,0.10); border-color: rgba(78,205,196,0.25); color: var(--accent2); }
.icon-btn.teal:hover { background: rgba(78,205,196,0.22); border-color: var(--accent2); }
.icon-btn.copied { background: rgba(78,205,196,0.15); border-color: var(--accent2); color: var(--accent2); }
.icon-btn svg { pointer-events: none; flex-shrink: 0; }
.output-box {
background: rgba(0,0,0,0.4); border: 1px solid var(--node-border);
border-radius: 5px; padding: 10px; flex: 1; overflow-y: auto;
font-size: 11px; line-height: 1.6; color: #c8c8e0; white-space: pre-wrap;
user-select: text; font-family: 'JetBrains Mono', monospace; min-height: 0;
}
/* ββ Grounding node ββ */
.ground-node-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; overflow: hidden; }
.ground-header-row { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.ground-img-wrap {
position: relative; flex: 1; border: 1px solid var(--node-border);
border-radius: 5px; overflow: hidden; background: #111; min-height: 0;
display: flex; align-items: center; justify-content: center;
}
.ground-img-wrap img.overlay-img {
max-width: 100%; max-height: 100%;
object-fit: contain; display: block;
}
.ground-placeholder {
position: absolute; inset: 0; display: flex; align-items: center;
justify-content: center; font-size: 11px; color: var(--muted);
text-align: center; padding: 10px; pointer-events: none; z-index: 5;
}
.loader {
width: 11px; height: 11px; border: 2px solid rgba(255,255,255,0.3);
border-top-color: #fff; border-radius: 50%;
animation: spin 0.7s linear infinite; display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: inline-block; margin-right: 6px; }
.status-dot.active { background: var(--accent2); box-shadow: 0 0 5px var(--accent2); }
/* ββ Model badges ββ */
.model-badge {
display: inline-block; padding: 2px 7px; border-radius: 4px;
font-size: 9px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.model-badge.qvl2b { background: rgba(255,150,50,0.15); color: #ff9632; border: 1px solid rgba(255,150,50,0.35); }
.model-badge.qvl4b { background: rgba(255,100,80,0.15); color: #ff6450; border: 1px solid rgba(255,100,80,0.35); }
.model-badge.q4bunred { background: rgba(255,80,80,0.18); color: #ff5050; border: 1px solid rgba(255,80,80,0.40); }
.model-badge.q4b { background: rgba(255,200,80,0.15); color: #ffc850; border: 1px solid rgba(255,200,80,0.35); }
.model-badge.q2b { background: rgba(124,106,247,0.2); color: var(--accent); border: 1px solid rgba(124,106,247,0.3); }
.model-badge.lfm450 { background: rgba(78,205,196,0.15); color: var(--accent2); border: 1px solid rgba(78,205,196,0.3); }
.model-badge.g4e2b { background: rgba(66,197,107,0.15); color: #42c56b; border: 1px solid rgba(66,197,107,0.35); }
.model-badge.lfm16 { background: rgba(107,203,119,0.15); color: #6bcb77; border: 1px solid rgba(107,203,119,0.35); }
.model-badge.qunred { background: rgba(255,80,160,0.15); color: #ff50a0; border: 1px solid rgba(255,80,160,0.35); }
.model-badge.q25vl3b { background: rgba(80,180,255,0.15); color: #50b4ff; border: 1px solid rgba(80,180,255,0.35); }
.model-info-box { border-radius: 6px; padding: 9px; font-size: 10px; color: var(--muted); line-height: 1.55; flex-shrink: 0; }
.canvas-footer { height: 36px; }
</style>
</head>
<body>
<div class="top-bar">
<span class="logo">MULTIMODAL EDGE</span>
<span class="sep">|</span>
<span class="sub">Node-Based Inference Canvas</span>
<span class="badge">10x Vision Models</span>
</div>
<div id="canvas">
<svg class="wires">
<path id="wire-img-task" class="wire" />
<path id="wire-model-task" class="wire" />
<path id="wire-task-out" class="wire" />
<path id="wire-task-gnd" class="wire" />
</svg>
<!-- βββ ID 01 : Image Input βββ -->
<div class="node fixed-height" id="node-img" style="left:40px; top:52px;">
<div class="node-header">
<span><span class="status-dot" id="dot-img"></span>Input Image</span>
<span class="id">ID: 01</span>
</div>
<div class="node-body">
<div>
<label>Upload Image</label>
<div class="file-upload" id="dropZone">
<svg width="30" height="30" viewBox="0 0 24 24" fill="none"
stroke="#7c6af7" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
<span>Click or drop image here</span>
<input type="file" id="fileInput" accept="image/*">
</div>
<div class="preview-wrap" id="previewWrap">
<img id="imgPreview" class="img-preview" />
<button class="clear-btn" id="clearBtn" title="Remove image">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
</div>
<div class="img-chip" id="imgChip" style="margin-top:6px;">
<span class="chip-dot"></span>
<span class="chip-name" id="chipName">β</span>
<span class="chip-size" id="chipSize"></span>
</div>
</div>
</div>
<div class="port out" id="port-img-out" style="top:50%;transform:translateY(-50%);"></div>
</div>
<!-- βββ ID 02 : Model Selector βββ -->
<div class="node fixed-height" id="node-model" style="left:40px; top:412px;">
<div class="node-header">
<span><span class="status-dot" id="dot-model"></span>Model Selector</span>
<span class="id">ID: 02</span>
</div>
<div class="node-body">
<div>
<label>Active Model</label>
<select id="modelSelect">
<option value="qwen_vl_2b">Qwen3-VL-2B-Instruct</option>
<option value="qwen_vl_4b">Qwen3-VL-4B-Instruct</option>
<option value="qwen_4b_unredacted">Qwen3.5-4B-Unredacted-MAX</option>
<option value="qwen_4b">Qwen3.5-4B</option>
<option value="qwen_2b">Qwen3.5-2B</option>
<option value="lfm_450">LFM2.5-VL-450M (LiquidAI)</option>
<option value="gemma4_e2b">Gemma4-E2B-it (Google)</option>
<option value="lfm_16">LFM2.5-VL-1.6B (LiquidAI)</option>
<option value="qwen_unredacted">Qwen3.5-2B-Unredacted-MAX</option>
<option value="qwen25_vl_3b">Qwen2.5-VL-3B-Instruct</option>
</select>
</div>
<div id="modelInfoBox" class="model-info-box"
style="background:rgba(255,150,50,0.07);border:1px solid rgba(255,150,50,0.3);">
<span class="model-badge qvl2b">QWEN3-VL Β· 2B</span><br><br>
Qwen3-VL-2B-Instruct β dedicated vision-language model by Alibaba Cloud.
Strong spatial grounding, OCR & instruction-following.
</div>
<div style="flex:1;"></div>
</div>
<div class="port out" id="port-model-out" style="top:50%;transform:translateY(-50%);"></div>
</div>
<!-- βββ ID 03 : Task Config βββ -->
<div class="node fixed-height" id="node-task" style="left:425px; top:52px;">
<div class="port in" id="port-task-in" style="top:50%;transform:translateY(-50%);"></div>
<div class="node-header">
<span><span class="status-dot" id="dot-task"></span>Task Config</span>
<span class="id">ID: 03</span>
</div>
<div class="node-body">
<div>
<label>Task Category</label>
<select id="categorySelect">
<option value="Query">Query</option>
<option value="Caption">Caption</option>
<option value="Point">Point</option>
<option value="Detect">Detect</option>
</select>
</div>
<div>
<label>Prompt Directive</label>
<textarea id="promptInput" rows="4"
placeholder="e.g., Count the total number of boats and describe the environment."></textarea>
</div>
<button class="run-btn" id="runBtn">
<span>Execute</span>
<span class="loader" id="btnLoader"></span>
</button>
</div>
<div class="port out" id="port-task-out" style="top:50%;transform:translateY(-50%);"></div>
</div>
<!-- βββ ID 04 : Output Stream βββ -->
<div class="node fixed-height" id="node-out" style="left:810px; top:52px;">
<div class="port in" id="port-out-in" style="top:50%;transform:translateY(-50%);"></div>
<div class="node-header">
<span><span class="status-dot" id="dot-out"></span>Output Stream</span>
<span class="id">ID: 04</span>
</div>
<div class="output-node-body">
<div class="output-header-row">
<label style="margin-bottom:0;">Streamed Result</label>
<button class="icon-btn" id="copyBtn" title="Copy result to clipboard">
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
COPY
</button>
</div>
<div class="output-box" id="outputBox">Results will stream here...</div>
</div>
</div>
<!-- βββ ID 05 : Grounding Visualiser βββ -->
<div class="node fixed-height" id="node-gnd" style="left:810px; top:412px;">
<div class="port in" id="port-gnd-in" style="top:50%;transform:translateY(-50%);"></div>
<div class="node-header">
<span><span class="status-dot" id="dot-gnd"></span>View Grounding</span>
<span class="id">ID: 05</span>
</div>
<div class="ground-node-body">
<div class="ground-header-row">
<label style="margin-bottom:0;">Point / Detect Overlay</label>
<a class="icon-btn teal" id="downloadBtn" title="Download overlay image" style="display:none;">
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
SAVE
</a>
</div>
<div class="ground-img-wrap" id="groundWrap">
<img class="overlay-img" id="overlayImg" src="" style="display:none;" />
<div class="ground-placeholder" id="groundPlaceholder">
Active for Point / Detect tasks.<br>Run inference to visualise.
</div>
</div>
</div>
</div>
<div class="canvas-footer"></div>
</div>
<script>
// ββββββββββββββββββββββββββββββββββββββββββββββ
// WIRE DRAWING
// ββββββββββββββββββββββββββββββββββββββββββββββ
const canvasEl = document.getElementById('canvas');
function portCenter(id) {
const el = document.getElementById(id);
if (!el) return {x:0,y:0};
const er = el.getBoundingClientRect(), cr = canvasEl.getBoundingClientRect();
return { x: er.left + er.width/2 - cr.left, y: er.top + er.height/2 - cr.top };
}
function bezier(p1, p2) {
const dx = Math.abs(p2.x - p1.x) * 0.55;
return `M ${p1.x} ${p1.y} C ${p1.x+dx} ${p1.y}, ${p2.x-dx} ${p2.y}, ${p2.x} ${p2.y}`;
}
function updateWires() {
const wires = [
['wire-img-task', 'port-img-out', 'port-task-in'],
['wire-model-task', 'port-model-out','port-task-in'],
['wire-task-out', 'port-task-out', 'port-out-in'],
['wire-task-gnd', 'port-task-out', 'port-gnd-in'],
];
for (const [id, from, to] of wires) {
const el = document.getElementById(id);
if (el) el.setAttribute('d', bezier(portCenter(from), portCenter(to)));
}
}
// ββββββββββββββββββββββββββββββββββββββββββββββ
// DRAGGING
// ββββββββββββββββββββββββββββββββββββββββββββββ
document.querySelectorAll('.node').forEach(node => {
const header = node.querySelector('.node-header');
let drag = false, sx, sy, il, it;
header.addEventListener('mousedown', e => {
drag=true; sx=e.clientX; sy=e.clientY;
il=parseInt(node.style.left)||0; it=parseInt(node.style.top)||0;
node.style.zIndex=100; e.preventDefault();
});
document.addEventListener('mousemove', e => {
if (!drag) return;
node.style.left=`${il+e.clientX-sx}px`; node.style.top=`${it+e.clientY-sy}px`;
updateWires();
});
document.addEventListener('mouseup', () => { if(drag){drag=false;node.style.zIndex=10;} });
});
window.addEventListener('resize', updateWires);
window.addEventListener('scroll', updateWires);
document.addEventListener('scroll', updateWires, true);
requestAnimationFrame(updateWires);
// ββββββββββββββββββββββββββββββββββββββββββββββ
// FILE UPLOAD + CLEAR
// ββββββββββββββββββββββββββββββββββββββββββββββ
let currentFile = null;
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const previewWrap = document.getElementById('previewWrap');
const imgPreview = document.getElementById('imgPreview');
const clearBtn = document.getElementById('clearBtn');
const imgChip = document.getElementById('imgChip');
const chipName = document.getElementById('chipName');
const chipSize = document.getElementById('chipSize');
const dotImg = document.getElementById('dot-img');
function formatBytes(b) {
if (b<1024) return b+' B';
if (b<1048576) return (b/1024).toFixed(1)+' KB';
return (b/1048576).toFixed(1)+' MB';
}
function handleFile(file) {
if (!file||!file.type.startsWith('image/')) return;
currentFile=file;
imgPreview.src=URL.createObjectURL(file);
previewWrap.classList.add('visible');
dropZone.style.display='none';
chipName.textContent=file.name;
chipSize.textContent=formatBytes(file.size);
imgChip.classList.add('visible');
dotImg.classList.add('active');
requestAnimationFrame(updateWires);
}
function clearImage() {
currentFile=null; imgPreview.src='';
previewWrap.classList.remove('visible');
dropZone.style.display='';
imgChip.classList.remove('visible');
chipName.textContent='β'; chipSize.textContent='';
fileInput.value=''; dotImg.classList.remove('active');
requestAnimationFrame(updateWires);
}
dropZone.onclick = () => fileInput.click();
fileInput.onchange = e => handleFile(e.target.files[0]);
clearBtn.onclick = e => { e.stopPropagation(); clearImage(); };
dropZone.ondragover = e => { e.preventDefault(); dropZone.style.borderColor='var(--accent)'; };
dropZone.ondragleave = () => { dropZone.style.borderColor=''; };
dropZone.ondrop = e => {
e.preventDefault(); dropZone.style.borderColor='';
if (e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
};
// ββββββββββββββββββββββββββββββββββββββββββββββ
// MODEL SELECTOR
// ββββββββββββββββββββββββββββββββββββββββββββββ
const modelSelect = document.getElementById('modelSelect');
const modelInfoBox = document.getElementById('modelInfoBox');
const dotModel = document.getElementById('dot-model');
dotModel.classList.add('active');
const MODEL_INFO = {
qwen_vl_2b: {
html: `<span class="model-badge qvl2b">QWEN3-VL Β· 2B</span><br><br>
Qwen3-VL-2B-Instruct β dedicated vision-language model by Alibaba Cloud.
Strong spatial grounding, OCR & instruction-following.`,
bg: 'rgba(255,150,50,0.07)', border: 'rgba(255,150,50,0.30)',
},
qwen_vl_4b: {
html: `<span class="model-badge qvl4b">QWEN3-VL Β· 4B</span><br><br>
Qwen3-VL-4B-Instruct β enhanced vision-language model by Alibaba Cloud.
Superior spatial grounding, richer OCR & stronger multi-step reasoning.`,
bg: 'rgba(255,100,80,0.07)', border: 'rgba(255,100,80,0.25)',
},
qwen_4b_unredacted: {
html: `<span class="model-badge q4bunred">QWEN 3.5 Β· 4B UNREDACTED MAX</span><br><br>
Qwen3.5-4B-Unredacted-MAX by prithivMLmods. Uncensored fine-tune of Qwen3.5-4B
with extended instruction-following & unrestricted reasoning.`,
bg: 'rgba(255,80,80,0.07)', border: 'rgba(255,80,80,0.30)',
},
qwen_4b: {
html: `<span class="model-badge q4b">QWEN 3.5 Β· 4B</span><br><br>
Qwen3.5 4B multimodal model by Alibaba Cloud.
Enhanced capacity β richer reasoning & better instruction following.`,
bg: 'rgba(255,200,80,0.07)', border: 'rgba(255,200,80,0.30)',
},
qwen_2b: {
html: `<span class="model-badge q2b">QWEN 3.5 Β· 2B</span><br><br>
Qwen3.5 2B multimodal model by Alibaba Cloud.
Lightweight & fast β ideal for quick Query, Caption, Point & Detect tasks.`,
bg: 'rgba(124,106,247,0.07)', border: 'rgba(124,106,247,0.25)',
},
lfm_450: {
html: `<span class="model-badge lfm450">LFM Β· 450M</span><br><br>
LFM2.5-VL 450M by LiquidAI. Ultra-lightweight edge model
with solid grounding capabilities.`,
bg: 'rgba(78,205,196,0.07)', border: 'rgba(78,205,196,0.25)',
},
gemma4_e2b: {
html: `<span class="model-badge g4e2b">GEMMA 4 Β· E2B</span><br><br>
Gemma4-E2B-it by Google DeepMind. Efficient 2B multimodal model
with strong vision-language understanding & instruction-following.`,
bg: 'rgba(66,197,107,0.07)', border: 'rgba(66,197,107,0.25)',
},
lfm_16: {
html: `<span class="model-badge lfm16">LFM Β· 1.6B</span><br><br>
LFM2.5-VL 1.6B by LiquidAI. Larger liquid-state model offering
enhanced reasoning & richer visual understanding.`,
bg: 'rgba(107,203,119,0.07)', border: 'rgba(107,203,119,0.25)',
},
qwen_unredacted: {
html: `<span class="model-badge qunred">QWEN 3.5 Β· 2B UNREDACTED MAX</span><br><br>
Qwen3.5-2B-Unredacted-MAX by prithivMLmods. Fine-tuned variant of Qwen3.5-2B
with uncensored & extended instruction-following capabilities.`,
bg: 'rgba(255,80,160,0.07)', border: 'rgba(255,80,160,0.25)',
},
qwen25_vl_3b: {
html: `<span class="model-badge q25vl3b">QWEN 2.5-VL Β· 3B</span><br><br>
Qwen2.5-VL-3B-Instruct by Alibaba Cloud. Powerful 3B vision-language model
with strong grounding, OCR & multi-task visual reasoning.`,
bg: 'rgba(80,180,255,0.07)', border: 'rgba(80,180,255,0.25)',
},
};
modelSelect.onchange = () => {
const info = MODEL_INFO[modelSelect.value];
if (!info) return;
modelInfoBox.innerHTML = info.html;
modelInfoBox.style.background = info.bg;
modelInfoBox.style.border = `1px solid ${info.border}`;
};
// ββββββββββββββββββββββββββββββββββββββββββββββ
// CATEGORY PLACEHOLDER
// ββββββββββββββββββββββββββββββββββββββββββββββ
const categorySelect = document.getElementById('categorySelect');
const promptInput = document.getElementById('promptInput');
const PLACEHOLDERS = {
Query: 'e.g., Count the total number of boats and describe the environment.',
Caption: 'e.g., short | normal | detailed',
Point: 'e.g., The gun held by the person.',
Detect: 'e.g., The headlight of the car.',
};
categorySelect.onchange = e => { promptInput.placeholder = PLACEHOLDERS[e.target.value] || ''; };
// ββββββββββββββββββββββββββββββββββββββββββββββ
// COPY BUTTON
// ββββββββββββββββββββββββββββββββββββββββββββββ
const copyBtn = document.getElementById('copyBtn');
const outputBox = document.getElementById('outputBox');
let copyTimer = null;
function resetCopyBtn() {
copyBtn.classList.remove('copied');
copyBtn.innerHTML = `
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg> COPY`;
}
copyBtn.onclick = () => {
const txt = outputBox.innerText || '';
if (!txt || txt === 'Results will stream here...') return;
navigator.clipboard.writeText(txt).then(() => {
copyBtn.classList.add('copied');
copyBtn.innerHTML = `
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="20 6 9 17 4 12"/>
</svg> COPIED`;
clearTimeout(copyTimer);
copyTimer = setTimeout(resetCopyBtn, 2000);
}).catch(() => {
const ta = document.createElement('textarea');
ta.value = txt; ta.style.position = 'fixed'; ta.style.opacity = '0';
document.body.appendChild(ta); ta.select(); document.execCommand('copy');
document.body.removeChild(ta);
});
};
// ββββββββββββββββββββββββββββββββββββββββββββββ
// GROUNDING DISPLAY (server-side annotated image)
// ββββββββββββββββββββββββββββββββββββββββββββββ
const overlayImg = document.getElementById('overlayImg');
const groundPlaceholder = document.getElementById('groundPlaceholder');
const downloadBtn = document.getElementById('downloadBtn');
const dotGnd = document.getElementById('dot-gnd');
function showOverlay(b64png) {
const src = 'data:image/png;base64,' + b64png;
overlayImg.src = src;
overlayImg.style.display = 'block';
groundPlaceholder.style.display = 'none';
dotGnd.classList.add('active');
const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
downloadBtn.href = src;
downloadBtn.download = `grounding_${ts}.png`;
downloadBtn.style.display = 'flex';
}
function resetOverlay(msg) {
overlayImg.src = '';
overlayImg.style.display = 'none';
groundPlaceholder.textContent = msg || 'Active for Point / Detect tasks.\nRun inference to visualise.';
groundPlaceholder.style.display = 'flex';
downloadBtn.style.display = 'none';
dotGnd.classList.remove('active');
}
// ββββββββββββββββββββββββββββββββββββββββββββββ
// RUN INFERENCE
// ββββββββββββββββββββββββββββββββββββββββββββββ
const runBtn = document.getElementById('runBtn');
const btnLoader = document.getElementById('btnLoader');
const allWires = ['wire-img-task','wire-model-task','wire-task-out','wire-task-gnd'];
const dotTask = document.getElementById('dot-task');
const dotOut = document.getElementById('dot-out');
runBtn.onclick = async () => {
if (!currentFile) { alert('Please upload an image into the Input Node.'); return; }
const promptStr = promptInput.value.trim();
if (!promptStr) { alert('Please enter a prompt directive.'); return; }
// ββ Reset UI ββββββββββββββββββββββββββββββ
runBtn.disabled = true;
btnLoader.style.display = 'inline-block';
outputBox.innerText = '';
outputBox.style.color = '';
dotTask.classList.add('active');
dotOut.classList.remove('active');
allWires.forEach(id => document.getElementById(id)?.classList.add('active'));
resetCopyBtn();
resetOverlay('Running inferenceβ¦');
const category = categorySelect.value;
const modelId = modelSelect.value;
// ββ Step 1: stream text from /api/run βββββ
const formData = new FormData();
formData.append('image', currentFile);
formData.append('category', category);
formData.append('prompt', promptStr);
formData.append('model_id', modelId);
let fullText = '';
try {
const response = await fetch('/api/run', { method: 'POST', body: formData });
if (!response.ok) {
const err = await response.json();
throw new Error(err.error || 'Execution failed.');
}
const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
let buffer = '';
while (true) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n\n');
buffer = lines.pop();
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const payload = line.slice(6);
if (payload === '[DONE]') break;
try {
const data = JSON.parse(payload);
if (data.chunk) {
fullText += data.chunk;
outputBox.innerText = fullText;
outputBox.scrollTop = outputBox.scrollHeight;
}
} catch (_) {}
}
}
dotOut.classList.add('active');
// ββ Step 2: if Point or Detect β call /api/annotate ββ
if ((category === 'Point' || category === 'Detect') && fullText.trim()) {
groundPlaceholder.textContent = 'Annotating imageβ¦';
groundPlaceholder.style.display = 'flex';
try {
const annotForm = new FormData();
annotForm.append('image', currentFile);
annotForm.append('text', fullText);
annotForm.append('category', category);
const annotResp = await fetch('/api/annotate', {
method: 'POST', body: annotForm,
});
if (!annotResp.ok) throw new Error('Annotation request failed');
const annotData = await annotResp.json();
if (annotData.error) {
resetOverlay('Annotation error: ' + annotData.error);
} else if (annotData.image_b64) {
showOverlay(annotData.image_b64);
} else {
resetOverlay('No coordinates found in model output.');
}
} catch (annotErr) {
resetOverlay('Annotation failed: ' + annotErr.message);
console.error('Annotation error:', annotErr);
}
} else if (category !== 'Point' && category !== 'Detect') {
resetOverlay('Active for Point / Detect tasks.\nRun inference to visualise.');
}
} catch (err) {
outputBox.innerText = `[Error] ${err.message}`;
outputBox.style.color = '#ff6b6b';
resetOverlay('Inference error β see Output Stream node.');
} finally {
runBtn.disabled = false;
btnLoader.style.display = 'none';
dotTask.classList.remove('active');
allWires.forEach(id => document.getElementById(id)?.classList.remove('active'));
}
};
</script>
</body>
</html> |