update app
Browse files
app.py
CHANGED
|
@@ -400,7 +400,7 @@ def pil_to_png_bytes(image: Image.Image) -> bytes:
|
|
| 400 |
# ---------------------------------------------------------------------------
|
| 401 |
# Inference Generator (Streaming)
|
| 402 |
# ---------------------------------------------------------------------------
|
| 403 |
-
@spaces.GPU(duration=120)
|
| 404 |
def generate_inference_stream(
|
| 405 |
image: Image.Image, category: str, prompt: str, model_id: str = "qwen_vl_2b"
|
| 406 |
):
|
|
@@ -607,7 +607,7 @@ def generate_inference_stream(
|
|
| 607 |
|
| 608 |
|
| 609 |
# ---------------------------------------------------------------------------
|
| 610 |
-
#
|
| 611 |
# Returns annotated PNG + structured JSON
|
| 612 |
# ---------------------------------------------------------------------------
|
| 613 |
@app.post("/api/annotate")
|
|
@@ -652,792 +652,14 @@ async def run_inference(
|
|
| 652 |
|
| 653 |
|
| 654 |
# ---------------------------------------------------------------------------
|
| 655 |
-
# Frontend
|
| 656 |
# ---------------------------------------------------------------------------
|
| 657 |
@app.get("/", response_class=HTMLResponse)
|
| 658 |
-
async def homepage(
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
<meta charset="UTF-8">
|
| 664 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 665 |
-
<title>Multimodal-Edge-Comparator</title>
|
| 666 |
-
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&display=swap" rel="stylesheet">
|
| 667 |
-
<style>
|
| 668 |
-
:root {
|
| 669 |
-
--bg: #0d0d0f;
|
| 670 |
-
--grid: #1a1a1f;
|
| 671 |
-
--node-bg: #13131a;
|
| 672 |
-
--node-header: #1c1c26;
|
| 673 |
-
--node-border: #2a2a3a;
|
| 674 |
-
--accent: #7c6af7;
|
| 675 |
-
--accent2: #4ecdc4;
|
| 676 |
-
--accent3: #ff6b6b;
|
| 677 |
-
--text: #e8e8f0;
|
| 678 |
-
--muted: #6b6b8a;
|
| 679 |
-
--port: #4ecdc4;
|
| 680 |
-
--wire: #2a2a4a;
|
| 681 |
-
--wire-active: #7c6af7;
|
| 682 |
-
}
|
| 683 |
-
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 684 |
-
html, body {
|
| 685 |
-
min-height: 100%; background: var(--bg);
|
| 686 |
-
color: var(--text); font-family: 'JetBrains Mono', monospace;
|
| 687 |
-
}
|
| 688 |
-
body {
|
| 689 |
-
background-image:
|
| 690 |
-
radial-gradient(circle at 20% 50%, rgba(124,106,247,0.04) 0%, transparent 50%),
|
| 691 |
-
radial-gradient(circle at 80% 20%, rgba(78,205,196,0.04) 0%, transparent 50%),
|
| 692 |
-
linear-gradient(var(--grid) 1px, transparent 1px),
|
| 693 |
-
linear-gradient(90deg, var(--grid) 1px, transparent 1px);
|
| 694 |
-
background-size: 100% 100%, 100% 100%, 24px 24px, 24px 24px;
|
| 695 |
-
overflow-x: auto; overflow-y: auto;
|
| 696 |
-
}
|
| 697 |
-
/* ── Top Bar ── */
|
| 698 |
-
.top-bar {
|
| 699 |
-
position: sticky; top: 0; left: 0; right: 0; height: 42px;
|
| 700 |
-
background: rgba(13,13,15,0.95); border-bottom: 1px solid var(--node-border);
|
| 701 |
-
display: flex; align-items: center; padding: 0 20px;
|
| 702 |
-
gap: 12px; z-index: 1000; backdrop-filter: blur(12px);
|
| 703 |
-
}
|
| 704 |
-
.top-bar .logo { font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }
|
| 705 |
-
.top-bar .sep { color: var(--node-border); }
|
| 706 |
-
.top-bar .sub { font-size: 11px; color: var(--muted); }
|
| 707 |
-
.top-bar .badge {
|
| 708 |
-
margin-left: auto; background: rgba(124,106,247,0.15);
|
| 709 |
-
border: 1px solid rgba(124,106,247,0.3); padding: 3px 10px;
|
| 710 |
-
border-radius: 20px; font-size: 10px; color: var(--accent);
|
| 711 |
-
}
|
| 712 |
-
/* ── Canvas ── */
|
| 713 |
-
#canvas {
|
| 714 |
-
position: relative; width: 1360px;
|
| 715 |
-
min-height: calc(100vh - 42px); height: 900px; margin: 0 auto;
|
| 716 |
-
}
|
| 717 |
-
svg.wires {
|
| 718 |
-
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
|
| 719 |
-
pointer-events: none; z-index: 2; overflow: visible;
|
| 720 |
-
}
|
| 721 |
-
path.wire { fill: none; stroke: var(--wire); stroke-width: 2.5; stroke-linecap: round; }
|
| 722 |
-
path.wire.active {
|
| 723 |
-
stroke: var(--wire-active); stroke-width: 3;
|
| 724 |
-
stroke-dasharray: 8 4; animation: flow 0.6s linear infinite;
|
| 725 |
-
}
|
| 726 |
-
@keyframes flow { to { stroke-dashoffset: -24; } }
|
| 727 |
-
/* ── Nodes ── */
|
| 728 |
-
.node {
|
| 729 |
-
position: absolute; width: 295px;
|
| 730 |
-
background: var(--node-bg); border: 1px solid var(--node-border);
|
| 731 |
-
border-radius: 9px; box-shadow: 0 8px 28px rgba(0,0,0,0.5);
|
| 732 |
-
z-index: 10; display: flex; flex-direction: column; transition: box-shadow 0.2s;
|
| 733 |
-
}
|
| 734 |
-
.node:hover { box-shadow: 0 8px 28px rgba(0,0,0,0.5), 0 0 0 1px rgba(124,106,247,0.3); }
|
| 735 |
-
.node.fixed-height { height: 340px; }
|
| 736 |
-
.node-header {
|
| 737 |
-
background: var(--node-header); padding: 7px 12px;
|
| 738 |
-
border-bottom: 1px solid var(--node-border); border-radius: 9px 9px 0 0;
|
| 739 |
-
font-size: 11px; font-weight: 700; cursor: grab;
|
| 740 |
-
display: flex; justify-content: space-between; align-items: center;
|
| 741 |
-
flex-shrink: 0; user-select: none;
|
| 742 |
-
}
|
| 743 |
-
.node-header:active { cursor: grabbing; }
|
| 744 |
-
.node-header .id {
|
| 745 |
-
font-size: 10px; color: var(--muted);
|
| 746 |
-
background: rgba(255,255,255,0.04); padding: 2px 7px; border-radius: 4px;
|
| 747 |
-
}
|
| 748 |
-
.node-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; overflow: hidden; }
|
| 749 |
-
/* ── Ports ── */
|
| 750 |
-
.port {
|
| 751 |
-
position: absolute; width: 11px; height: 11px;
|
| 752 |
-
background: var(--node-bg); border: 2px solid var(--port);
|
| 753 |
-
border-radius: 50%; z-index: 30;
|
| 754 |
-
}
|
| 755 |
-
.port.out { right: -6px; }
|
| 756 |
-
.port.in { left: -6px; }
|
| 757 |
-
/* ── Labels ── */
|
| 758 |
-
label {
|
| 759 |
-
font-size: 10px; color: var(--muted); font-weight: 600;
|
| 760 |
-
display: block; margin-bottom: 3px; letter-spacing: 0.07em; text-transform: uppercase;
|
| 761 |
-
}
|
| 762 |
-
input[type="file"] { display: none; }
|
| 763 |
-
/* ── Upload Zone ── */
|
| 764 |
-
.file-upload {
|
| 765 |
-
border: 1.5px dashed var(--node-border); border-radius: 7px; padding: 12px 10px;
|
| 766 |
-
text-align: center; cursor: pointer; font-size: 11px; color: var(--muted);
|
| 767 |
-
transition: border-color 0.2s, background 0.2s; background: rgba(255,255,255,0.01);
|
| 768 |
-
display: flex; flex-direction: column; align-items: center; gap: 5px;
|
| 769 |
-
}
|
| 770 |
-
.file-upload:hover { border-color: var(--accent); background: rgba(124,106,247,0.04); }
|
| 771 |
-
.file-upload svg { opacity: 0.5; transition: opacity 0.2s; }
|
| 772 |
-
.file-upload:hover svg { opacity: 0.9; }
|
| 773 |
-
/* ── Preview wrapper ── */
|
| 774 |
-
.preview-wrap {
|
| 775 |
-
display: none; position: relative; border-radius: 7px;
|
| 776 |
-
overflow: hidden; border: 1px solid var(--node-border); background: #000;
|
| 777 |
-
}
|
| 778 |
-
.preview-wrap.visible { display: block; }
|
| 779 |
-
.img-preview { width: 100%; height: 170px; object-fit: contain; display: block; }
|
| 780 |
-
/* ── Clear button ── */
|
| 781 |
-
.clear-btn {
|
| 782 |
-
position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
|
| 783 |
-
border-radius: 50%; background: rgba(13,13,15,0.80);
|
| 784 |
-
border: 1px solid var(--node-border); color: var(--accent3); cursor: pointer;
|
| 785 |
-
display: flex; align-items: center; justify-content: center;
|
| 786 |
-
transition: background 0.18s, border-color 0.18s, transform 0.12s;
|
| 787 |
-
z-index: 20; backdrop-filter: blur(6px);
|
| 788 |
-
}
|
| 789 |
-
.clear-btn:hover { background: rgba(255,107,107,0.18); border-color: var(--accent3); transform: scale(1.08); }
|
| 790 |
-
.clear-btn:active { transform: scale(0.95); }
|
| 791 |
-
.clear-btn svg { pointer-events: none; }
|
| 792 |
-
/* ── Filename chip ── */
|
| 793 |
-
.img-chip {
|
| 794 |
-
display: none; align-items: center; gap: 6px;
|
| 795 |
-
background: rgba(124,106,247,0.08); border: 1px solid rgba(124,106,247,0.22);
|
| 796 |
-
border-radius: 5px; padding: 4px 8px; font-size: 9px; color: var(--muted); overflow: hidden;
|
| 797 |
-
}
|
| 798 |
-
.img-chip.visible { display: flex; }
|
| 799 |
-
.img-chip .chip-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent2); flex-shrink: 0; box-shadow: 0 0 4px var(--accent2); }
|
| 800 |
-
.img-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; color: var(--text); font-size: 9px; }
|
| 801 |
-
.img-chip .chip-size { color: var(--muted); flex-shrink: 0; font-size: 9px; }
|
| 802 |
-
select, textarea {
|
| 803 |
-
width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--node-border);
|
| 804 |
-
color: var(--text); padding: 7px 9px; border-radius: 5px; outline: none;
|
| 805 |
-
font-size: 11px; font-family: 'JetBrains Mono', monospace;
|
| 806 |
-
resize: none; transition: border-color 0.2s;
|
| 807 |
-
}
|
| 808 |
-
select:focus, textarea:focus { border-color: var(--accent); }
|
| 809 |
-
select option { background: #1c1c26; }
|
| 810 |
-
button.run-btn {
|
| 811 |
-
background: linear-gradient(135deg, var(--accent), #9b59b6);
|
| 812 |
-
color: #fff; border: none; padding: 8px; border-radius: 6px;
|
| 813 |
-
font-weight: 700; font-size: 11px; font-family: 'JetBrains Mono', monospace;
|
| 814 |
-
cursor: pointer; transition: opacity 0.2s, transform 0.1s;
|
| 815 |
-
display: flex; justify-content: center; align-items: center; gap: 8px;
|
| 816 |
-
letter-spacing: 0.04em; flex-shrink: 0;
|
| 817 |
-
}
|
| 818 |
-
button.run-btn:hover { opacity: 0.9; }
|
| 819 |
-
button.run-btn:active { transform: scale(0.98); }
|
| 820 |
-
button.run-btn:disabled { background: var(--node-border); cursor: not-allowed; color: #555; }
|
| 821 |
-
/* ── Output node ── */
|
| 822 |
-
.output-node-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; overflow: hidden; }
|
| 823 |
-
.output-header-row { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
|
| 824 |
-
/* ── Icon buttons ── */
|
| 825 |
-
.icon-btn {
|
| 826 |
-
display: flex; align-items: center; gap: 5px;
|
| 827 |
-
background: rgba(124,106,247,0.10); border: 1px solid rgba(124,106,247,0.25);
|
| 828 |
-
border-radius: 5px; padding: 3px 8px; font-size: 9px; font-weight: 700;
|
| 829 |
-
font-family: 'JetBrains Mono', monospace; color: var(--accent); cursor: pointer;
|
| 830 |
-
letter-spacing: 0.05em; transition: background 0.18s, border-color 0.18s, transform 0.1s;
|
| 831 |
-
flex-shrink: 0; text-decoration: none;
|
| 832 |
-
}
|
| 833 |
-
.icon-btn:hover { background: rgba(124,106,247,0.22); border-color: var(--accent); }
|
| 834 |
-
.icon-btn:active { transform: scale(0.95); }
|
| 835 |
-
.icon-btn.teal { background: rgba(78,205,196,0.10); border-color: rgba(78,205,196,0.25); color: var(--accent2); }
|
| 836 |
-
.icon-btn.teal:hover { background: rgba(78,205,196,0.22); border-color: var(--accent2); }
|
| 837 |
-
.icon-btn.copied { background: rgba(78,205,196,0.15); border-color: var(--accent2); color: var(--accent2); }
|
| 838 |
-
.icon-btn svg { pointer-events: none; flex-shrink: 0; }
|
| 839 |
-
.output-box {
|
| 840 |
-
background: rgba(0,0,0,0.4); border: 1px solid var(--node-border);
|
| 841 |
-
border-radius: 5px; padding: 10px; flex: 1; overflow-y: auto;
|
| 842 |
-
font-size: 11px; line-height: 1.6; color: #c8c8e0; white-space: pre-wrap;
|
| 843 |
-
user-select: text; font-family: 'JetBrains Mono', monospace; min-height: 0;
|
| 844 |
-
}
|
| 845 |
-
/* ── Grounding node ── */
|
| 846 |
-
.ground-node-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; overflow: hidden; }
|
| 847 |
-
.ground-header-row { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
|
| 848 |
-
.ground-img-wrap {
|
| 849 |
-
position: relative; flex: 1; border: 1px solid var(--node-border);
|
| 850 |
-
border-radius: 5px; overflow: hidden; background: #111; min-height: 0;
|
| 851 |
-
display: flex; align-items: center; justify-content: center;
|
| 852 |
-
}
|
| 853 |
-
/* annotated image displayed via <img> tag — no canvas needed */
|
| 854 |
-
.ground-img-wrap img.overlay-img {
|
| 855 |
-
max-width: 100%; max-height: 100%;
|
| 856 |
-
object-fit: contain; display: block;
|
| 857 |
-
}
|
| 858 |
-
.ground-placeholder {
|
| 859 |
-
position: absolute; inset: 0; display: flex; align-items: center;
|
| 860 |
-
justify-content: center; font-size: 11px; color: var(--muted);
|
| 861 |
-
text-align: center; padding: 10px; pointer-events: none; z-index: 5;
|
| 862 |
-
}
|
| 863 |
-
.loader {
|
| 864 |
-
width: 11px; height: 11px; border: 2px solid rgba(255,255,255,0.3);
|
| 865 |
-
border-top-color: #fff; border-radius: 50%;
|
| 866 |
-
animation: spin 0.7s linear infinite; display: none;
|
| 867 |
-
}
|
| 868 |
-
@keyframes spin { to { transform: rotate(360deg); } }
|
| 869 |
-
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: inline-block; margin-right: 6px; }
|
| 870 |
-
.status-dot.active { background: var(--accent2); box-shadow: 0 0 5px var(--accent2); }
|
| 871 |
-
/* ── Model badges ── */
|
| 872 |
-
.model-badge {
|
| 873 |
-
display: inline-block; padding: 2px 7px; border-radius: 4px;
|
| 874 |
-
font-size: 9px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
|
| 875 |
-
}
|
| 876 |
-
.model-badge.qvl2b { background: rgba(255,150,50,0.15); color: #ff9632; border: 1px solid rgba(255,150,50,0.35); }
|
| 877 |
-
.model-badge.qvl4b { background: rgba(255,100,80,0.15); color: #ff6450; border: 1px solid rgba(255,100,80,0.35); }
|
| 878 |
-
.model-badge.q4bunred { background: rgba(255,80,80,0.18); color: #ff5050; border: 1px solid rgba(255,80,80,0.40); }
|
| 879 |
-
.model-badge.q4b { background: rgba(255,200,80,0.15); color: #ffc850; border: 1px solid rgba(255,200,80,0.35); }
|
| 880 |
-
.model-badge.q2b { background: rgba(124,106,247,0.2); color: var(--accent); border: 1px solid rgba(124,106,247,0.3); }
|
| 881 |
-
.model-badge.lfm450 { background: rgba(78,205,196,0.15); color: var(--accent2); border: 1px solid rgba(78,205,196,0.3); }
|
| 882 |
-
.model-badge.g4e2b { background: rgba(66,197,107,0.15); color: #42c56b; border: 1px solid rgba(66,197,107,0.35); }
|
| 883 |
-
.model-badge.lfm16 { background: rgba(107,203,119,0.15); color: #6bcb77; border: 1px solid rgba(107,203,119,0.35); }
|
| 884 |
-
.model-badge.qunred { background: rgba(255,80,160,0.15); color: #ff50a0; border: 1px solid rgba(255,80,160,0.35); }
|
| 885 |
-
.model-badge.q25vl3b { background: rgba(80,180,255,0.15); color: #50b4ff; border: 1px solid rgba(80,180,255,0.35); }
|
| 886 |
-
.model-info-box { border-radius: 6px; padding: 9px; font-size: 10px; color: var(--muted); line-height: 1.55; flex-shrink: 0; }
|
| 887 |
-
.canvas-footer { height: 36px; }
|
| 888 |
-
</style>
|
| 889 |
-
</head>
|
| 890 |
-
<body>
|
| 891 |
-
|
| 892 |
-
<div class="top-bar">
|
| 893 |
-
<span class="logo">MULTIMODAL EDGE</span>
|
| 894 |
-
<span class="sep">|</span>
|
| 895 |
-
<span class="sub">Node-Based Inference Canvas</span>
|
| 896 |
-
<span class="badge">10x Vision Models</span>
|
| 897 |
-
</div>
|
| 898 |
-
|
| 899 |
-
<div id="canvas">
|
| 900 |
-
<svg class="wires">
|
| 901 |
-
<path id="wire-img-task" class="wire" />
|
| 902 |
-
<path id="wire-model-task" class="wire" />
|
| 903 |
-
<path id="wire-task-out" class="wire" />
|
| 904 |
-
<path id="wire-task-gnd" class="wire" />
|
| 905 |
-
</svg>
|
| 906 |
-
|
| 907 |
-
<!-- ─── ID 01 : Image Input ─── -->
|
| 908 |
-
<div class="node fixed-height" id="node-img" style="left:40px; top:52px;">
|
| 909 |
-
<div class="node-header">
|
| 910 |
-
<span><span class="status-dot" id="dot-img"></span>Input Image</span>
|
| 911 |
-
<span class="id">ID: 01</span>
|
| 912 |
-
</div>
|
| 913 |
-
<div class="node-body">
|
| 914 |
-
<div>
|
| 915 |
-
<label>Upload Image</label>
|
| 916 |
-
<div class="file-upload" id="dropZone">
|
| 917 |
-
<svg width="30" height="30" viewBox="0 0 24 24" fill="none"
|
| 918 |
-
stroke="#7c6af7" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
| 919 |
-
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
|
| 920 |
-
<circle cx="8.5" cy="8.5" r="1.5"/>
|
| 921 |
-
<polyline points="21 15 16 10 5 21"/>
|
| 922 |
-
</svg>
|
| 923 |
-
<span>Click or drop image here</span>
|
| 924 |
-
<input type="file" id="fileInput" accept="image/*">
|
| 925 |
-
</div>
|
| 926 |
-
<div class="preview-wrap" id="previewWrap">
|
| 927 |
-
<img id="imgPreview" class="img-preview" />
|
| 928 |
-
<button class="clear-btn" id="clearBtn" title="Remove image">
|
| 929 |
-
<svg width="12" height="12" viewBox="0 0 24 24" fill="none"
|
| 930 |
-
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
| 931 |
-
<line x1="18" y1="6" x2="6" y2="18"/>
|
| 932 |
-
<line x1="6" y1="6" x2="18" y2="18"/>
|
| 933 |
-
</svg>
|
| 934 |
-
</button>
|
| 935 |
-
</div>
|
| 936 |
-
<div class="img-chip" id="imgChip" style="margin-top:6px;">
|
| 937 |
-
<span class="chip-dot"></span>
|
| 938 |
-
<span class="chip-name" id="chipName">—</span>
|
| 939 |
-
<span class="chip-size" id="chipSize"></span>
|
| 940 |
-
</div>
|
| 941 |
-
</div>
|
| 942 |
-
</div>
|
| 943 |
-
<div class="port out" id="port-img-out" style="top:50%;transform:translateY(-50%);"></div>
|
| 944 |
-
</div>
|
| 945 |
-
|
| 946 |
-
<!-- ─── ID 02 : Model Selector ─── -->
|
| 947 |
-
<div class="node fixed-height" id="node-model" style="left:40px; top:412px;">
|
| 948 |
-
<div class="node-header">
|
| 949 |
-
<span><span class="status-dot" id="dot-model"></span>Model Selector</span>
|
| 950 |
-
<span class="id">ID: 02</span>
|
| 951 |
-
</div>
|
| 952 |
-
<div class="node-body">
|
| 953 |
-
<div>
|
| 954 |
-
<label>Active Model</label>
|
| 955 |
-
<select id="modelSelect">
|
| 956 |
-
<option value="qwen_vl_2b">Qwen3-VL-2B-Instruct</option>
|
| 957 |
-
<option value="qwen_vl_4b">Qwen3-VL-4B-Instruct</option>
|
| 958 |
-
<option value="qwen_4b_unredacted">Qwen3.5-4B-Unredacted-MAX</option>
|
| 959 |
-
<option value="qwen_4b">Qwen3.5-4B</option>
|
| 960 |
-
<option value="qwen_2b">Qwen3.5-2B</option>
|
| 961 |
-
<option value="lfm_450">LFM2.5-VL-450M (LiquidAI)</option>
|
| 962 |
-
<option value="gemma4_e2b">Gemma4-E2B-it (Google)</option>
|
| 963 |
-
<option value="lfm_16">LFM2.5-VL-1.6B (LiquidAI)</option>
|
| 964 |
-
<option value="qwen_unredacted">Qwen3.5-2B-Unredacted-MAX</option>
|
| 965 |
-
<option value="qwen25_vl_3b">Qwen2.5-VL-3B-Instruct</option>
|
| 966 |
-
</select>
|
| 967 |
-
</div>
|
| 968 |
-
<div id="modelInfoBox" class="model-info-box"
|
| 969 |
-
style="background:rgba(255,150,50,0.07);border:1px solid rgba(255,150,50,0.3);">
|
| 970 |
-
<span class="model-badge qvl2b">QWEN3-VL · 2B</span><br><br>
|
| 971 |
-
Qwen3-VL-2B-Instruct — dedicated vision-language model by Alibaba Cloud.
|
| 972 |
-
Strong spatial grounding, OCR & instruction-following.
|
| 973 |
-
</div>
|
| 974 |
-
<div style="flex:1;"></div>
|
| 975 |
-
</div>
|
| 976 |
-
<div class="port out" id="port-model-out" style="top:50%;transform:translateY(-50%);"></div>
|
| 977 |
-
</div>
|
| 978 |
-
|
| 979 |
-
<!-- ─── ID 03 : Task Config ─── -->
|
| 980 |
-
<div class="node fixed-height" id="node-task" style="left:425px; top:52px;">
|
| 981 |
-
<div class="port in" id="port-task-in" style="top:50%;transform:translateY(-50%);"></div>
|
| 982 |
-
<div class="node-header">
|
| 983 |
-
<span><span class="status-dot" id="dot-task"></span>Task Config</span>
|
| 984 |
-
<span class="id">ID: 03</span>
|
| 985 |
-
</div>
|
| 986 |
-
<div class="node-body">
|
| 987 |
-
<div>
|
| 988 |
-
<label>Task Category</label>
|
| 989 |
-
<select id="categorySelect">
|
| 990 |
-
<option value="Query">Query</option>
|
| 991 |
-
<option value="Caption">Caption</option>
|
| 992 |
-
<option value="Point">Point</option>
|
| 993 |
-
<option value="Detect">Detect</option>
|
| 994 |
-
</select>
|
| 995 |
-
</div>
|
| 996 |
-
<div>
|
| 997 |
-
<label>Prompt Directive</label>
|
| 998 |
-
<textarea id="promptInput" rows="4"
|
| 999 |
-
placeholder="e.g., Count the total number of boats and describe the environment."></textarea>
|
| 1000 |
-
</div>
|
| 1001 |
-
<button class="run-btn" id="runBtn">
|
| 1002 |
-
<span>Execute</span>
|
| 1003 |
-
<span class="loader" id="btnLoader"></span>
|
| 1004 |
-
</button>
|
| 1005 |
-
</div>
|
| 1006 |
-
<div class="port out" id="port-task-out" style="top:50%;transform:translateY(-50%);"></div>
|
| 1007 |
-
</div>
|
| 1008 |
-
|
| 1009 |
-
<!-- ─── ID 04 : Output Stream ─── -->
|
| 1010 |
-
<div class="node fixed-height" id="node-out" style="left:810px; top:52px;">
|
| 1011 |
-
<div class="port in" id="port-out-in" style="top:50%;transform:translateY(-50%);"></div>
|
| 1012 |
-
<div class="node-header">
|
| 1013 |
-
<span><span class="status-dot" id="dot-out"></span>Output Stream</span>
|
| 1014 |
-
<span class="id">ID: 04</span>
|
| 1015 |
-
</div>
|
| 1016 |
-
<div class="output-node-body">
|
| 1017 |
-
<div class="output-header-row">
|
| 1018 |
-
<label style="margin-bottom:0;">Streamed Result</label>
|
| 1019 |
-
<button class="icon-btn" id="copyBtn" title="Copy result to clipboard">
|
| 1020 |
-
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
|
| 1021 |
-
stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
|
| 1022 |
-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
| 1023 |
-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
| 1024 |
-
</svg>
|
| 1025 |
-
COPY
|
| 1026 |
-
</button>
|
| 1027 |
-
</div>
|
| 1028 |
-
<div class="output-box" id="outputBox">Results will stream here...</div>
|
| 1029 |
-
</div>
|
| 1030 |
-
</div>
|
| 1031 |
-
|
| 1032 |
-
<!-- ─── ID 05 : Grounding Visualiser ─── -->
|
| 1033 |
-
<div class="node fixed-height" id="node-gnd" style="left:810px; top:412px;">
|
| 1034 |
-
<div class="port in" id="port-gnd-in" style="top:50%;transform:translateY(-50%);"></div>
|
| 1035 |
-
<div class="node-header">
|
| 1036 |
-
<span><span class="status-dot" id="dot-gnd"></span>View Grounding</span>
|
| 1037 |
-
<span class="id">ID: 05</span>
|
| 1038 |
-
</div>
|
| 1039 |
-
<div class="ground-node-body">
|
| 1040 |
-
<div class="ground-header-row">
|
| 1041 |
-
<label style="margin-bottom:0;">Point / Detect Overlay</label>
|
| 1042 |
-
<a class="icon-btn teal" id="downloadBtn" title="Download overlay image" style="display:none;">
|
| 1043 |
-
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
|
| 1044 |
-
stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
|
| 1045 |
-
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
|
| 1046 |
-
<polyline points="7 10 12 15 17 10"/>
|
| 1047 |
-
<line x1="12" y1="15" x2="12" y2="3"/>
|
| 1048 |
-
</svg>
|
| 1049 |
-
SAVE
|
| 1050 |
-
</a>
|
| 1051 |
-
</div>
|
| 1052 |
-
<div class="ground-img-wrap" id="groundWrap">
|
| 1053 |
-
<img class="overlay-img" id="overlayImg" src="" style="display:none;" />
|
| 1054 |
-
<div class="ground-placeholder" id="groundPlaceholder">
|
| 1055 |
-
Active for Point / Detect tasks.<br>Run inference to visualise.
|
| 1056 |
-
</div>
|
| 1057 |
-
</div>
|
| 1058 |
-
</div>
|
| 1059 |
-
</div>
|
| 1060 |
-
|
| 1061 |
-
<div class="canvas-footer"></div>
|
| 1062 |
-
</div>
|
| 1063 |
-
|
| 1064 |
-
<script>
|
| 1065 |
-
// ══════════════════════════════════════════════
|
| 1066 |
-
// WIRE DRAWING
|
| 1067 |
-
// ══════════════════════════════════════════════
|
| 1068 |
-
const canvasEl = document.getElementById('canvas');
|
| 1069 |
-
function portCenter(id) {
|
| 1070 |
-
const el = document.getElementById(id);
|
| 1071 |
-
if (!el) return {x:0,y:0};
|
| 1072 |
-
const er = el.getBoundingClientRect(), cr = canvasEl.getBoundingClientRect();
|
| 1073 |
-
return { x: er.left + er.width/2 - cr.left, y: er.top + er.height/2 - cr.top };
|
| 1074 |
-
}
|
| 1075 |
-
function bezier(p1, p2) {
|
| 1076 |
-
const dx = Math.abs(p2.x - p1.x) * 0.55;
|
| 1077 |
-
return `M ${p1.x} ${p1.y} C ${p1.x+dx} ${p1.y}, ${p2.x-dx} ${p2.y}, ${p2.x} ${p2.y}`;
|
| 1078 |
-
}
|
| 1079 |
-
function updateWires() {
|
| 1080 |
-
const wires = [
|
| 1081 |
-
['wire-img-task', 'port-img-out', 'port-task-in'],
|
| 1082 |
-
['wire-model-task', 'port-model-out','port-task-in'],
|
| 1083 |
-
['wire-task-out', 'port-task-out', 'port-out-in'],
|
| 1084 |
-
['wire-task-gnd', 'port-task-out', 'port-gnd-in'],
|
| 1085 |
-
];
|
| 1086 |
-
for (const [id, from, to] of wires) {
|
| 1087 |
-
const el = document.getElementById(id);
|
| 1088 |
-
if (el) el.setAttribute('d', bezier(portCenter(from), portCenter(to)));
|
| 1089 |
-
}
|
| 1090 |
-
}
|
| 1091 |
-
|
| 1092 |
-
// ══════════════════════════════════════════════
|
| 1093 |
-
// DRAGGING
|
| 1094 |
-
// ══════════════════════════════════════════════
|
| 1095 |
-
document.querySelectorAll('.node').forEach(node => {
|
| 1096 |
-
const header = node.querySelector('.node-header');
|
| 1097 |
-
let drag = false, sx, sy, il, it;
|
| 1098 |
-
header.addEventListener('mousedown', e => {
|
| 1099 |
-
drag=true; sx=e.clientX; sy=e.clientY;
|
| 1100 |
-
il=parseInt(node.style.left)||0; it=parseInt(node.style.top)||0;
|
| 1101 |
-
node.style.zIndex=100; e.preventDefault();
|
| 1102 |
-
});
|
| 1103 |
-
document.addEventListener('mousemove', e => {
|
| 1104 |
-
if (!drag) return;
|
| 1105 |
-
node.style.left=`${il+e.clientX-sx}px`; node.style.top=`${it+e.clientY-sy}px`;
|
| 1106 |
-
updateWires();
|
| 1107 |
-
});
|
| 1108 |
-
document.addEventListener('mouseup', () => { if(drag){drag=false;node.style.zIndex=10;} });
|
| 1109 |
-
});
|
| 1110 |
-
window.addEventListener('resize', updateWires);
|
| 1111 |
-
window.addEventListener('scroll', updateWires);
|
| 1112 |
-
document.addEventListener('scroll', updateWires, true);
|
| 1113 |
-
requestAnimationFrame(updateWires);
|
| 1114 |
-
|
| 1115 |
-
// ══════════════════════════════════════════════
|
| 1116 |
-
// FILE UPLOAD + CLEAR
|
| 1117 |
-
// ══════════════════════════════════════════════
|
| 1118 |
-
let currentFile = null;
|
| 1119 |
-
const dropZone = document.getElementById('dropZone');
|
| 1120 |
-
const fileInput = document.getElementById('fileInput');
|
| 1121 |
-
const previewWrap = document.getElementById('previewWrap');
|
| 1122 |
-
const imgPreview = document.getElementById('imgPreview');
|
| 1123 |
-
const clearBtn = document.getElementById('clearBtn');
|
| 1124 |
-
const imgChip = document.getElementById('imgChip');
|
| 1125 |
-
const chipName = document.getElementById('chipName');
|
| 1126 |
-
const chipSize = document.getElementById('chipSize');
|
| 1127 |
-
const dotImg = document.getElementById('dot-img');
|
| 1128 |
-
|
| 1129 |
-
function formatBytes(b) {
|
| 1130 |
-
if (b<1024) return b+' B';
|
| 1131 |
-
if (b<1048576) return (b/1024).toFixed(1)+' KB';
|
| 1132 |
-
return (b/1048576).toFixed(1)+' MB';
|
| 1133 |
-
}
|
| 1134 |
-
function handleFile(file) {
|
| 1135 |
-
if (!file||!file.type.startsWith('image/')) return;
|
| 1136 |
-
currentFile=file;
|
| 1137 |
-
imgPreview.src=URL.createObjectURL(file);
|
| 1138 |
-
previewWrap.classList.add('visible');
|
| 1139 |
-
dropZone.style.display='none';
|
| 1140 |
-
chipName.textContent=file.name;
|
| 1141 |
-
chipSize.textContent=formatBytes(file.size);
|
| 1142 |
-
imgChip.classList.add('visible');
|
| 1143 |
-
dotImg.classList.add('active');
|
| 1144 |
-
requestAnimationFrame(updateWires);
|
| 1145 |
-
}
|
| 1146 |
-
function clearImage() {
|
| 1147 |
-
currentFile=null; imgPreview.src='';
|
| 1148 |
-
previewWrap.classList.remove('visible');
|
| 1149 |
-
dropZone.style.display='';
|
| 1150 |
-
imgChip.classList.remove('visible');
|
| 1151 |
-
chipName.textContent='—'; chipSize.textContent='';
|
| 1152 |
-
fileInput.value=''; dotImg.classList.remove('active');
|
| 1153 |
-
requestAnimationFrame(updateWires);
|
| 1154 |
-
}
|
| 1155 |
-
dropZone.onclick = () => fileInput.click();
|
| 1156 |
-
fileInput.onchange = e => handleFile(e.target.files[0]);
|
| 1157 |
-
clearBtn.onclick = e => { e.stopPropagation(); clearImage(); };
|
| 1158 |
-
dropZone.ondragover = e => { e.preventDefault(); dropZone.style.borderColor='var(--accent)'; };
|
| 1159 |
-
dropZone.ondragleave = () => { dropZone.style.borderColor=''; };
|
| 1160 |
-
dropZone.ondrop = e => {
|
| 1161 |
-
e.preventDefault(); dropZone.style.borderColor='';
|
| 1162 |
-
if (e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
|
| 1163 |
-
};
|
| 1164 |
-
|
| 1165 |
-
// ══════════════════════════════════════════════
|
| 1166 |
-
// MODEL SELECTOR
|
| 1167 |
-
// ══════════════════════════════════════════════
|
| 1168 |
-
const modelSelect = document.getElementById('modelSelect');
|
| 1169 |
-
const modelInfoBox = document.getElementById('modelInfoBox');
|
| 1170 |
-
const dotModel = document.getElementById('dot-model');
|
| 1171 |
-
dotModel.classList.add('active');
|
| 1172 |
-
|
| 1173 |
-
const MODEL_INFO = {
|
| 1174 |
-
qwen_vl_2b: {
|
| 1175 |
-
html: `<span class="model-badge qvl2b">QWEN3-VL · 2B</span><br><br>
|
| 1176 |
-
Qwen3-VL-2B-Instruct — dedicated vision-language model by Alibaba Cloud.
|
| 1177 |
-
Strong spatial grounding, OCR & instruction-following.`,
|
| 1178 |
-
bg: 'rgba(255,150,50,0.07)', border: 'rgba(255,150,50,0.30)',
|
| 1179 |
-
},
|
| 1180 |
-
qwen_vl_4b: {
|
| 1181 |
-
html: `<span class="model-badge qvl4b">QWEN3-VL · 4B</span><br><br>
|
| 1182 |
-
Qwen3-VL-4B-Instruct — enhanced vision-language model by Alibaba Cloud.
|
| 1183 |
-
Superior spatial grounding, richer OCR & stronger multi-step reasoning.`,
|
| 1184 |
-
bg: 'rgba(255,100,80,0.07)', border: 'rgba(255,100,80,0.25)',
|
| 1185 |
-
},
|
| 1186 |
-
qwen_4b_unredacted: {
|
| 1187 |
-
html: `<span class="model-badge q4bunred">QWEN 3.5 · 4B UNREDACTED MAX</span><br><br>
|
| 1188 |
-
Qwen3.5-4B-Unredacted-MAX by prithivMLmods. Uncensored fine-tune of Qwen3.5-4B
|
| 1189 |
-
with extended instruction-following & unrestricted reasoning.`,
|
| 1190 |
-
bg: 'rgba(255,80,80,0.07)', border: 'rgba(255,80,80,0.30)',
|
| 1191 |
-
},
|
| 1192 |
-
qwen_4b: {
|
| 1193 |
-
html: `<span class="model-badge q4b">QWEN 3.5 · 4B</span><br><br>
|
| 1194 |
-
Qwen3.5 4B multimodal model by Alibaba Cloud.
|
| 1195 |
-
Enhanced capacity — richer reasoning & better instruction following.`,
|
| 1196 |
-
bg: 'rgba(255,200,80,0.07)', border: 'rgba(255,200,80,0.30)',
|
| 1197 |
-
},
|
| 1198 |
-
qwen_2b: {
|
| 1199 |
-
html: `<span class="model-badge q2b">QWEN 3.5 · 2B</span><br><br>
|
| 1200 |
-
Qwen3.5 2B multimodal model by Alibaba Cloud.
|
| 1201 |
-
Lightweight & fast — ideal for quick Query, Caption, Point & Detect tasks.`,
|
| 1202 |
-
bg: 'rgba(124,106,247,0.07)', border: 'rgba(124,106,247,0.25)',
|
| 1203 |
-
},
|
| 1204 |
-
lfm_450: {
|
| 1205 |
-
html: `<span class="model-badge lfm450">LFM · 450M</span><br><br>
|
| 1206 |
-
LFM2.5-VL 450M by LiquidAI. Ultra-lightweight edge model
|
| 1207 |
-
with solid grounding capabilities.`,
|
| 1208 |
-
bg: 'rgba(78,205,196,0.07)', border: 'rgba(78,205,196,0.25)',
|
| 1209 |
-
},
|
| 1210 |
-
gemma4_e2b: {
|
| 1211 |
-
html: `<span class="model-badge g4e2b">GEMMA 4 · E2B</span><br><br>
|
| 1212 |
-
Gemma4-E2B-it by Google DeepMind. Efficient 2B multimodal model
|
| 1213 |
-
with strong vision-language understanding & instruction-following.`,
|
| 1214 |
-
bg: 'rgba(66,197,107,0.07)', border: 'rgba(66,197,107,0.25)',
|
| 1215 |
-
},
|
| 1216 |
-
lfm_16: {
|
| 1217 |
-
html: `<span class="model-badge lfm16">LFM · 1.6B</span><br><br>
|
| 1218 |
-
LFM2.5-VL 1.6B by LiquidAI. Larger liquid-state model offering
|
| 1219 |
-
enhanced reasoning & richer visual understanding.`,
|
| 1220 |
-
bg: 'rgba(107,203,119,0.07)', border: 'rgba(107,203,119,0.25)',
|
| 1221 |
-
},
|
| 1222 |
-
qwen_unredacted: {
|
| 1223 |
-
html: `<span class="model-badge qunred">QWEN 3.5 · 2B UNREDACTED MAX</span><br><br>
|
| 1224 |
-
Qwen3.5-2B-Unredacted-MAX by prithivMLmods. Fine-tuned variant of Qwen3.5-2B
|
| 1225 |
-
with uncensored & extended instruction-following capabilities.`,
|
| 1226 |
-
bg: 'rgba(255,80,160,0.07)', border: 'rgba(255,80,160,0.25)',
|
| 1227 |
-
},
|
| 1228 |
-
qwen25_vl_3b: {
|
| 1229 |
-
html: `<span class="model-badge q25vl3b">QWEN 2.5-VL · 3B</span><br><br>
|
| 1230 |
-
Qwen2.5-VL-3B-Instruct by Alibaba Cloud. Powerful 3B vision-language model
|
| 1231 |
-
with strong grounding, OCR & multi-task visual reasoning.`,
|
| 1232 |
-
bg: 'rgba(80,180,255,0.07)', border: 'rgba(80,180,255,0.25)',
|
| 1233 |
-
},
|
| 1234 |
-
};
|
| 1235 |
-
modelSelect.onchange = () => {
|
| 1236 |
-
const info = MODEL_INFO[modelSelect.value];
|
| 1237 |
-
if (!info) return;
|
| 1238 |
-
modelInfoBox.innerHTML = info.html;
|
| 1239 |
-
modelInfoBox.style.background = info.bg;
|
| 1240 |
-
modelInfoBox.style.border = `1px solid ${info.border}`;
|
| 1241 |
-
};
|
| 1242 |
-
|
| 1243 |
-
// ══════════════════════════════════════════════
|
| 1244 |
-
// CATEGORY PLACEHOLDER
|
| 1245 |
-
// ══════════════════════════════════════════════
|
| 1246 |
-
const categorySelect = document.getElementById('categorySelect');
|
| 1247 |
-
const promptInput = document.getElementById('promptInput');
|
| 1248 |
-
const PLACEHOLDERS = {
|
| 1249 |
-
Query: 'e.g., Count the total number of boats and describe the environment.',
|
| 1250 |
-
Caption: 'e.g., short | normal | detailed',
|
| 1251 |
-
Point: 'e.g., The gun held by the person.',
|
| 1252 |
-
Detect: 'e.g., The headlight of the car.',
|
| 1253 |
-
};
|
| 1254 |
-
categorySelect.onchange = e => { promptInput.placeholder = PLACEHOLDERS[e.target.value] || ''; };
|
| 1255 |
-
|
| 1256 |
-
// ══════════════════════════════════════════════
|
| 1257 |
-
// COPY BUTTON
|
| 1258 |
-
// ══════════════════════════════════════════════
|
| 1259 |
-
const copyBtn = document.getElementById('copyBtn');
|
| 1260 |
-
const outputBox = document.getElementById('outputBox');
|
| 1261 |
-
let copyTimer = null;
|
| 1262 |
-
|
| 1263 |
-
function resetCopyBtn() {
|
| 1264 |
-
copyBtn.classList.remove('copied');
|
| 1265 |
-
copyBtn.innerHTML = `
|
| 1266 |
-
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
|
| 1267 |
-
stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
|
| 1268 |
-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
| 1269 |
-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
| 1270 |
-
</svg> COPY`;
|
| 1271 |
-
}
|
| 1272 |
-
copyBtn.onclick = () => {
|
| 1273 |
-
const txt = outputBox.innerText || '';
|
| 1274 |
-
if (!txt || txt === 'Results will stream here...') return;
|
| 1275 |
-
navigator.clipboard.writeText(txt).then(() => {
|
| 1276 |
-
copyBtn.classList.add('copied');
|
| 1277 |
-
copyBtn.innerHTML = `
|
| 1278 |
-
<svg width="11" height="11" viewBox="0 0 24 24" fill="none"
|
| 1279 |
-
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
| 1280 |
-
<polyline points="20 6 9 17 4 12"/>
|
| 1281 |
-
</svg> COPIED`;
|
| 1282 |
-
clearTimeout(copyTimer);
|
| 1283 |
-
copyTimer = setTimeout(resetCopyBtn, 2000);
|
| 1284 |
-
}).catch(() => {
|
| 1285 |
-
const ta = document.createElement('textarea');
|
| 1286 |
-
ta.value = txt; ta.style.position = 'fixed'; ta.style.opacity = '0';
|
| 1287 |
-
document.body.appendChild(ta); ta.select(); document.execCommand('copy');
|
| 1288 |
-
document.body.removeChild(ta);
|
| 1289 |
-
});
|
| 1290 |
-
};
|
| 1291 |
-
|
| 1292 |
-
// ══════════════════════════════════════════════
|
| 1293 |
-
// GROUNDING DISPLAY (server-side annotated image)
|
| 1294 |
-
// ══════════════════════════════════════════════
|
| 1295 |
-
const overlayImg = document.getElementById('overlayImg');
|
| 1296 |
-
const groundPlaceholder = document.getElementById('groundPlaceholder');
|
| 1297 |
-
const downloadBtn = document.getElementById('downloadBtn');
|
| 1298 |
-
const dotGnd = document.getElementById('dot-gnd');
|
| 1299 |
-
|
| 1300 |
-
function showOverlay(b64png) {
|
| 1301 |
-
const src = 'data:image/png;base64,' + b64png;
|
| 1302 |
-
overlayImg.src = src;
|
| 1303 |
-
overlayImg.style.display = 'block';
|
| 1304 |
-
groundPlaceholder.style.display = 'none';
|
| 1305 |
-
dotGnd.classList.add('active');
|
| 1306 |
-
|
| 1307 |
-
// Update download button
|
| 1308 |
-
const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
| 1309 |
-
downloadBtn.href = src;
|
| 1310 |
-
downloadBtn.download = `grounding_${ts}.png`;
|
| 1311 |
-
downloadBtn.style.display = 'flex';
|
| 1312 |
-
}
|
| 1313 |
-
|
| 1314 |
-
function resetOverlay(msg) {
|
| 1315 |
-
overlayImg.src = '';
|
| 1316 |
-
overlayImg.style.display = 'none';
|
| 1317 |
-
groundPlaceholder.textContent = msg || 'Active for Point / Detect tasks.\nRun inference to visualise.';
|
| 1318 |
-
groundPlaceholder.style.display = 'flex';
|
| 1319 |
-
downloadBtn.style.display = 'none';
|
| 1320 |
-
dotGnd.classList.remove('active');
|
| 1321 |
-
}
|
| 1322 |
-
|
| 1323 |
-
// ══════════════════════════════════════════════
|
| 1324 |
-
// RUN INFERENCE
|
| 1325 |
-
// ══════════════════════════════════════════════
|
| 1326 |
-
const runBtn = document.getElementById('runBtn');
|
| 1327 |
-
const btnLoader = document.getElementById('btnLoader');
|
| 1328 |
-
const allWires = ['wire-img-task','wire-model-task','wire-task-out','wire-task-gnd'];
|
| 1329 |
-
const dotTask = document.getElementById('dot-task');
|
| 1330 |
-
const dotOut = document.getElementById('dot-out');
|
| 1331 |
-
|
| 1332 |
-
runBtn.onclick = async () => {
|
| 1333 |
-
if (!currentFile) { alert('Please upload an image into the Input Node.'); return; }
|
| 1334 |
-
const promptStr = promptInput.value.trim();
|
| 1335 |
-
if (!promptStr) { alert('Please enter a prompt directive.'); return; }
|
| 1336 |
-
|
| 1337 |
-
// ── Reset UI ──────────────────────────────
|
| 1338 |
-
runBtn.disabled = true;
|
| 1339 |
-
btnLoader.style.display = 'inline-block';
|
| 1340 |
-
outputBox.innerText = '';
|
| 1341 |
-
outputBox.style.color = '';
|
| 1342 |
-
dotTask.classList.add('active');
|
| 1343 |
-
dotOut.classList.remove('active');
|
| 1344 |
-
allWires.forEach(id => document.getElementById(id)?.classList.add('active'));
|
| 1345 |
-
resetCopyBtn();
|
| 1346 |
-
resetOverlay('Running inference…');
|
| 1347 |
-
|
| 1348 |
-
const category = categorySelect.value;
|
| 1349 |
-
const modelId = modelSelect.value;
|
| 1350 |
-
|
| 1351 |
-
// ── Step 1: stream text from /api/run ─────
|
| 1352 |
-
const formData = new FormData();
|
| 1353 |
-
formData.append('image', currentFile);
|
| 1354 |
-
formData.append('category', category);
|
| 1355 |
-
formData.append('prompt', promptStr);
|
| 1356 |
-
formData.append('model_id', modelId);
|
| 1357 |
-
|
| 1358 |
-
let fullText = '';
|
| 1359 |
-
|
| 1360 |
-
try {
|
| 1361 |
-
const response = await fetch('/api/run', { method: 'POST', body: formData });
|
| 1362 |
-
if (!response.ok) {
|
| 1363 |
-
const err = await response.json();
|
| 1364 |
-
throw new Error(err.error || 'Execution failed.');
|
| 1365 |
-
}
|
| 1366 |
-
|
| 1367 |
-
const reader = response.body.getReader();
|
| 1368 |
-
const decoder = new TextDecoder('utf-8');
|
| 1369 |
-
let buffer = '';
|
| 1370 |
-
|
| 1371 |
-
while (true) {
|
| 1372 |
-
const { value, done } = await reader.read();
|
| 1373 |
-
if (done) break;
|
| 1374 |
-
buffer += decoder.decode(value, { stream: true });
|
| 1375 |
-
const lines = buffer.split('\n\n');
|
| 1376 |
-
buffer = lines.pop();
|
| 1377 |
-
for (const line of lines) {
|
| 1378 |
-
if (!line.startsWith('data: ')) continue;
|
| 1379 |
-
const payload = line.slice(6);
|
| 1380 |
-
if (payload === '[DONE]') break;
|
| 1381 |
-
try {
|
| 1382 |
-
const data = JSON.parse(payload);
|
| 1383 |
-
if (data.chunk) {
|
| 1384 |
-
fullText += data.chunk;
|
| 1385 |
-
outputBox.innerText = fullText;
|
| 1386 |
-
outputBox.scrollTop = outputBox.scrollHeight;
|
| 1387 |
-
}
|
| 1388 |
-
} catch (_) {}
|
| 1389 |
-
}
|
| 1390 |
-
}
|
| 1391 |
-
|
| 1392 |
-
dotOut.classList.add('active');
|
| 1393 |
-
|
| 1394 |
-
// ── Step 2: if Point or Detect → call /api/annotate ──
|
| 1395 |
-
if ((category === 'Point' || category === 'Detect') && fullText.trim()) {
|
| 1396 |
-
groundPlaceholder.textContent = 'Annotating image…';
|
| 1397 |
-
groundPlaceholder.style.display = 'flex';
|
| 1398 |
-
|
| 1399 |
-
try {
|
| 1400 |
-
const annotForm = new FormData();
|
| 1401 |
-
annotForm.append('image', currentFile);
|
| 1402 |
-
annotForm.append('text', fullText);
|
| 1403 |
-
annotForm.append('category', category);
|
| 1404 |
-
|
| 1405 |
-
const annotResp = await fetch('/api/annotate', {
|
| 1406 |
-
method: 'POST', body: annotForm,
|
| 1407 |
-
});
|
| 1408 |
-
if (!annotResp.ok) throw new Error('Annotation request failed');
|
| 1409 |
-
|
| 1410 |
-
const annotData = await annotResp.json();
|
| 1411 |
-
if (annotData.error) {
|
| 1412 |
-
resetOverlay('Annotation error: ' + annotData.error);
|
| 1413 |
-
} else if (annotData.image_b64) {
|
| 1414 |
-
showOverlay(annotData.image_b64);
|
| 1415 |
-
} else {
|
| 1416 |
-
resetOverlay('No coordinates found in model output.');
|
| 1417 |
-
}
|
| 1418 |
-
} catch (annotErr) {
|
| 1419 |
-
resetOverlay('Annotation failed: ' + annotErr.message);
|
| 1420 |
-
console.error('Annotation error:', annotErr);
|
| 1421 |
-
}
|
| 1422 |
-
} else if (category !== 'Point' && category !== 'Detect') {
|
| 1423 |
-
resetOverlay('Active for Point / Detect tasks.\nRun inference to visualise.');
|
| 1424 |
-
}
|
| 1425 |
-
|
| 1426 |
-
} catch (err) {
|
| 1427 |
-
outputBox.innerText = `[Error] ${err.message}`;
|
| 1428 |
-
outputBox.style.color = '#ff6b6b';
|
| 1429 |
-
resetOverlay('Inference error — see Output Stream node.');
|
| 1430 |
-
} finally {
|
| 1431 |
-
runBtn.disabled = false;
|
| 1432 |
-
btnLoader.style.display = 'none';
|
| 1433 |
-
dotTask.classList.remove('active');
|
| 1434 |
-
allWires.forEach(id => document.getElementById(id)?.classList.remove('active'));
|
| 1435 |
-
}
|
| 1436 |
-
};
|
| 1437 |
-
</script>
|
| 1438 |
-
</body>
|
| 1439 |
-
</html>
|
| 1440 |
-
"""
|
| 1441 |
|
| 1442 |
if __name__ == "__main__":
|
| 1443 |
app.launch(show_error=True, ssr_mode=False)
|
|
|
|
| 400 |
# ---------------------------------------------------------------------------
|
| 401 |
# Inference Generator (Streaming)
|
| 402 |
# ---------------------------------------------------------------------------
|
| 403 |
+
@spaces.GPU(duration=120, size="xlarge")
|
| 404 |
def generate_inference_stream(
|
| 405 |
image: Image.Image, category: str, prompt: str, model_id: str = "qwen_vl_2b"
|
| 406 |
):
|
|
|
|
| 607 |
|
| 608 |
|
| 609 |
# ---------------------------------------------------------------------------
|
| 610 |
+
# Endpoint: /api/annotate — receives image + model output text + category
|
| 611 |
# Returns annotated PNG + structured JSON
|
| 612 |
# ---------------------------------------------------------------------------
|
| 613 |
@app.post("/api/annotate")
|
|
|
|
| 652 |
|
| 653 |
|
| 654 |
# ---------------------------------------------------------------------------
|
| 655 |
+
# Frontend — served from external index.html
|
| 656 |
# ---------------------------------------------------------------------------
|
| 657 |
@app.get("/", response_class=HTMLResponse)
|
| 658 |
+
async def homepage():
|
| 659 |
+
html_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "index.html")
|
| 660 |
+
with open(html_path, "r", encoding="utf-8") as f:
|
| 661 |
+
return f.read()
|
| 662 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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