easyannotate 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data_factory/__init__.py +82 -0
- data_factory/__main__.py +6 -0
- data_factory/annotate/__init__.py +15 -0
- data_factory/annotate/attach.py +398 -0
- data_factory/annotate/demo.py +161 -0
- data_factory/annotate/images.py +443 -0
- data_factory/annotate/labels.py +399 -0
- data_factory/annotate/loop.py +359 -0
- data_factory/annotate/projects.py +207 -0
- data_factory/annotate/review.py +471 -0
- data_factory/annotate/schema.sql +171 -0
- data_factory/annotate/shapes.py +488 -0
- data_factory/annotate/store.py +292 -0
- data_factory/annotate/tools/__init__.py +39 -0
- data_factory/annotate/tools/fake.py +170 -0
- data_factory/annotate/tools/install.py +254 -0
- data_factory/annotate/tools/local.py +389 -0
- data_factory/annotate/tools/postprocess.py +175 -0
- data_factory/annotate/tools/protocol.py +238 -0
- data_factory/annotate/tools/registry.py +196 -0
- data_factory/annotate/tools/results.py +83 -0
- data_factory/annotate/tools/serve.py +106 -0
- data_factory/cli/__init__.py +21 -0
- data_factory/cli/main.py +837 -0
- data_factory/cli/menu.py +173 -0
- data_factory/cli/render.py +158 -0
- data_factory/core/__init__.py +11 -0
- data_factory/core/annotations/__init__.py +5 -0
- data_factory/core/annotations/coco.py +394 -0
- data_factory/core/annotations/csvfmt.py +174 -0
- data_factory/core/annotations/dota.py +98 -0
- data_factory/core/annotations/formats.py +626 -0
- data_factory/core/annotations/labelme.py +153 -0
- data_factory/core/annotations/model.py +334 -0
- data_factory/core/annotations/voc.py +231 -0
- data_factory/core/annotations/yolo.py +283 -0
- data_factory/core/bktree.py +89 -0
- data_factory/core/fs.py +245 -0
- data_factory/core/imaging.py +626 -0
- data_factory/core/ops/__init__.py +44 -0
- data_factory/core/ops/analyze.py +383 -0
- data_factory/core/ops/annotate_export.py +326 -0
- data_factory/core/ops/audit.py +274 -0
- data_factory/core/ops/augment.py +454 -0
- data_factory/core/ops/collect.py +241 -0
- data_factory/core/ops/combine.py +582 -0
- data_factory/core/ops/convert.py +212 -0
- data_factory/core/ops/dataset.py +246 -0
- data_factory/core/ops/dedup.py +235 -0
- data_factory/core/ops/export.py +168 -0
- data_factory/core/ops/image.py +407 -0
- data_factory/core/ops/labels.py +215 -0
- data_factory/core/ops/pairing.py +133 -0
- data_factory/core/ops/rename.py +154 -0
- data_factory/core/ops/report.py +323 -0
- data_factory/core/ops/visualize.py +164 -0
- data_factory/core/pairs.py +144 -0
- data_factory/core/parallel.py +191 -0
- data_factory/core/provenance.py +136 -0
- data_factory/core/registry.py +339 -0
- data_factory/core/stats.py +403 -0
- data_factory/core/types.py +148 -0
- data_factory/core/writer.py +194 -0
- data_factory/desktop.py +207 -0
- data_factory/hardware.py +243 -0
- data_factory/pipeline.py +192 -0
- data_factory/py.typed +0 -0
- data_factory/service/__init__.py +26 -0
- data_factory/service/app.py +483 -0
- data_factory/service/binding.py +174 -0
- data_factory/service/deps.py +133 -0
- data_factory/service/jobs.py +177 -0
- data_factory/service/limits.py +71 -0
- data_factory/service/routers/__init__.py +11 -0
- data_factory/service/routers/annotate.py +582 -0
- data_factory/service/routers/local.py +464 -0
- data_factory/service/routers/media.py +154 -0
- data_factory/service/routers/predictions.py +116 -0
- data_factory/service/routers/promote.py +182 -0
- data_factory/service/routers/tools.py +308 -0
- data_factory/service/static/annotate/api.js +246 -0
- data_factory/service/static/annotate/app.js +1696 -0
- data_factory/service/static/annotate/assist.js +106 -0
- data_factory/service/static/annotate/filmstrip.js +286 -0
- data_factory/service/static/annotate/hit.js +146 -0
- data_factory/service/static/annotate/labels.js +197 -0
- data_factory/service/static/annotate/render.js +286 -0
- data_factory/service/static/annotate/scene.js +277 -0
- data_factory/service/static/annotate/shapelist.js +72 -0
- data_factory/service/static/annotate/tools/box.js +96 -0
- data_factory/service/static/annotate/tools/line.js +96 -0
- data_factory/service/static/annotate/tools/obb.js +88 -0
- data_factory/service/static/annotate/tools/point.js +49 -0
- data_factory/service/static/annotate/tools/polygon.js +110 -0
- data_factory/service/static/annotate/tools/select.js +227 -0
- data_factory/service/static/annotate/undo.js +176 -0
- data_factory/service/static/annotate/viewport.js +156 -0
- data_factory/service/static/annotate.html +390 -0
- data_factory/service/static/index.html +632 -0
- data_factory/service/workspace.py +244 -0
- easyannotate/__init__.py +64 -0
- easyannotate/__main__.py +5 -0
- easyannotate/project.py +181 -0
- easyannotate/py.typed +0 -0
- easyannotate-0.4.0.dist-info/METADATA +767 -0
- easyannotate-0.4.0.dist-info/RECORD +109 -0
- easyannotate-0.4.0.dist-info/WHEEL +4 -0
- easyannotate-0.4.0.dist-info/entry_points.txt +4 -0
- easyannotate-0.4.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>EasyAnnotate</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root{
|
|
9
|
+
--bg:#f6f8fa; --panel:#fff; --ink:#12181d; --muted:#5d6b76; --line:#dfe5ea;
|
|
10
|
+
--accent:#0b6ef4; --accent-ink:#fff; --ok:#1c8a5a; --warn:#c07800; --err:#c8352c;
|
|
11
|
+
--mono:ui-monospace,"Cascadia Code",Consolas,monospace;
|
|
12
|
+
}
|
|
13
|
+
@media (prefers-color-scheme:dark){:root{
|
|
14
|
+
--bg:#0f1418; --panel:#171e24; --ink:#e8eef2; --muted:#94a3ad; --line:#28323a;
|
|
15
|
+
--accent:#4d9bff; --ok:#48c98a; --warn:#e8a33a; --err:#ff6b60;
|
|
16
|
+
}}
|
|
17
|
+
*{box-sizing:border-box}
|
|
18
|
+
body{margin:0;background:var(--bg);color:var(--ink);
|
|
19
|
+
font:15px/1.55 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
20
|
+
header{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
21
|
+
.bar{max-width:1140px;margin:0 auto;padding:1rem 1.25rem;display:flex;gap:1rem;align-items:baseline}
|
|
22
|
+
.bar h1{font-size:1.05rem;margin:0;letter-spacing:-.01em}
|
|
23
|
+
.bar .tag{color:var(--muted);font-size:.85rem}
|
|
24
|
+
.bar .right{margin-left:auto;font-family:var(--mono);font-size:.75rem;color:var(--muted)}
|
|
25
|
+
main{max-width:1140px;margin:0 auto;padding:1.5rem 1.25rem 5rem;display:grid;gap:1.25rem;
|
|
26
|
+
grid-template-columns:1fr}
|
|
27
|
+
@media(min-width:940px){main{grid-template-columns:minmax(0,1fr) 380px}}
|
|
28
|
+
.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:1.15rem}
|
|
29
|
+
.card h2{font-size:.72rem;text-transform:uppercase;letter-spacing:.09em;color:var(--muted);
|
|
30
|
+
margin:0 0 .85rem;font-weight:650}
|
|
31
|
+
.drop{border:1.5px dashed var(--line);border-radius:10px;padding:2.25rem 1rem;text-align:center;
|
|
32
|
+
cursor:pointer;transition:border-color .15s,background .15s}
|
|
33
|
+
.drop:hover,.drop.over{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 6%,transparent)}
|
|
34
|
+
.drop b{display:block;margin-bottom:.3rem}
|
|
35
|
+
.drop span{color:var(--muted);font-size:.87rem}
|
|
36
|
+
button{font:inherit;border:1px solid var(--line);background:var(--panel);color:var(--ink);
|
|
37
|
+
padding:.5rem .9rem;border-radius:7px;cursor:pointer}
|
|
38
|
+
button:hover:not(:disabled){border-color:var(--accent)}
|
|
39
|
+
button:disabled{opacity:.5;cursor:not-allowed}
|
|
40
|
+
button.primary{background:var(--accent);border-color:var(--accent);color:var(--accent-ink);font-weight:600}
|
|
41
|
+
select,input[type=text],input[type=number]{font:inherit;width:100%;padding:.45rem .6rem;
|
|
42
|
+
border:1px solid var(--line);border-radius:7px;background:var(--bg);color:var(--ink)}
|
|
43
|
+
label{display:block;margin-bottom:.75rem}
|
|
44
|
+
label .n{display:block;font-size:.8rem;font-weight:600;margin-bottom:.2rem}
|
|
45
|
+
label .h{display:block;font-size:.78rem;color:var(--muted);margin-top:.22rem}
|
|
46
|
+
.row{display:flex;gap:.5rem;align-items:center}
|
|
47
|
+
.row input[type=checkbox]{width:auto;margin:0}
|
|
48
|
+
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(88px,1fr));gap:.6rem;margin-bottom:1rem}
|
|
49
|
+
.stat{background:var(--bg);border:1px solid var(--line);border-radius:8px;padding:.6rem .7rem}
|
|
50
|
+
.stat b{display:block;font-size:1.25rem;font-family:var(--mono);letter-spacing:-.02em}
|
|
51
|
+
.stat span{font-size:.7rem;text-transform:uppercase;letter-spacing:.06em;color:var(--muted)}
|
|
52
|
+
.pill{display:inline-block;font-family:var(--mono);font-size:.72rem;padding:.12rem .45rem;
|
|
53
|
+
border-radius:4px;background:var(--bg);border:1px solid var(--line);margin:0 .3rem .3rem 0}
|
|
54
|
+
/* A bordered, inset scroll region. Without the frame the list clips mid-item
|
|
55
|
+
and reads as broken text rather than as something you can scroll. */
|
|
56
|
+
.ops{max-height:320px;overflow-y:auto;margin:0 0 1rem;padding:.45rem;
|
|
57
|
+
border:1px solid var(--line);border-radius:8px;background:var(--bg)}
|
|
58
|
+
.ops::-webkit-scrollbar{width:9px}
|
|
59
|
+
.ops::-webkit-scrollbar-thumb{background:var(--line);border-radius:9px}
|
|
60
|
+
.op{padding:.5rem .6rem;border-radius:7px;cursor:pointer;border:1px solid transparent}
|
|
61
|
+
.op:hover{background:var(--panel)}
|
|
62
|
+
.op.sel{background:color-mix(in srgb,var(--accent) 14%,transparent);border-color:var(--accent)}
|
|
63
|
+
.op b{display:block;font-family:var(--mono);font-size:.83rem}
|
|
64
|
+
.op span{font-size:.78rem;color:var(--muted)}
|
|
65
|
+
.cat{font-size:.68rem;text-transform:uppercase;letter-spacing:.09em;color:var(--muted);
|
|
66
|
+
margin:.85rem 0 .3rem;font-weight:650}
|
|
67
|
+
.cat:first-child{margin-top:0}
|
|
68
|
+
.job{border:1px solid var(--line);border-radius:8px;padding:.65rem .8rem;margin-bottom:.55rem;font-size:.87rem}
|
|
69
|
+
.job .t{display:flex;gap:.5rem;align-items:baseline}
|
|
70
|
+
.job .t b{font-family:var(--mono);font-size:.82rem}
|
|
71
|
+
.job .t .s{margin-left:auto;font-size:.72rem;text-transform:uppercase;letter-spacing:.06em}
|
|
72
|
+
.s.running{color:var(--accent)} .s.finished{color:var(--ok)}
|
|
73
|
+
.s.failed{color:var(--err)} .s.cancelled{color:var(--warn)} .s.queued{color:var(--muted)}
|
|
74
|
+
.track{height:4px;background:var(--bg);border-radius:2px;margin-top:.5rem;overflow:hidden}
|
|
75
|
+
.track i{display:block;height:100%;background:var(--accent);transition:width .25s}
|
|
76
|
+
.msg{font-size:.78rem;color:var(--muted);margin-top:.35rem;
|
|
77
|
+
white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
78
|
+
.finding{border-left:3px solid var(--line);padding:.45rem .7rem;margin:.4rem 0;font-size:.85rem;background:var(--bg);border-radius:0 6px 6px 0}
|
|
79
|
+
.finding.error{border-left-color:var(--err)} .finding.warning{border-left-color:var(--warn)}
|
|
80
|
+
.finding.note{border-left-color:var(--accent)}
|
|
81
|
+
.finding b{display:block}
|
|
82
|
+
.finding span{color:var(--muted);font-size:.8rem}
|
|
83
|
+
.note{color:var(--muted);font-size:.85rem}
|
|
84
|
+
.err{color:var(--err);font-size:.85rem}
|
|
85
|
+
.hide{display:none}
|
|
86
|
+
code{font-family:var(--mono);font-size:.85em;background:var(--bg);padding:.08em .35em;border-radius:4px}
|
|
87
|
+
</style>
|
|
88
|
+
</head>
|
|
89
|
+
<body>
|
|
90
|
+
<header><div class="bar">
|
|
91
|
+
<h1>EasyAnnotate</h1>
|
|
92
|
+
<span class="tag">Annotate, review, export — nothing to set up</span>
|
|
93
|
+
<span class="right" id="ver"></span>
|
|
94
|
+
</div></header>
|
|
95
|
+
|
|
96
|
+
<main>
|
|
97
|
+
<div>
|
|
98
|
+
<!-- This computer: shown inside the desktop window, or in a tab that the
|
|
99
|
+
launcher opened with its per-launch token (see routers/local.py). An
|
|
100
|
+
ordinary web page never sees it: without the token the server refuses,
|
|
101
|
+
and the card stays hidden. Opening a folder hands back a project id. -->
|
|
102
|
+
<div class="card hide" id="openFolderCard" style="margin-bottom:1.25rem">
|
|
103
|
+
<h2>Work on a folder on this computer</h2>
|
|
104
|
+
<div class="row">
|
|
105
|
+
<input type="text" id="folderPath" placeholder="Paste a folder path, e.g. D:\photos\doors"
|
|
106
|
+
autocomplete="off" spellcheck="false">
|
|
107
|
+
<button class="primary" id="btnOpenPath">Open</button>
|
|
108
|
+
<button id="btnOpenFolder">Browse…</button>
|
|
109
|
+
</div>
|
|
110
|
+
<p class="note" id="openFolderNote" style="margin:.6rem 0 0">
|
|
111
|
+
Labels already in the folder are loaded, and your edits are written back
|
|
112
|
+
into its own label files as you draw. Nothing is copied or uploaded.
|
|
113
|
+
</p>
|
|
114
|
+
<div id="recentProjects" class="hide" style="margin-top:.8rem">
|
|
115
|
+
<div class="note" style="margin-bottom:.35rem">Recent</div>
|
|
116
|
+
<div id="recentList"></div>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<!-- AI tools: never downloaded until asked. Local only, like the card above. -->
|
|
121
|
+
<div class="card hide" id="aiCard" style="margin-bottom:1.25rem">
|
|
122
|
+
<h2>AI tools</h2>
|
|
123
|
+
<p class="note" id="aiMachine" style="margin:0 0 .5rem"></p>
|
|
124
|
+
<p class="note" id="aiState" style="margin:0 0 .6rem"></p>
|
|
125
|
+
<div class="row">
|
|
126
|
+
<button class="primary" id="btnInstallAi">Install AI tools</button>
|
|
127
|
+
<label class="note" style="display:flex;gap:.35rem;align-items:center;white-space:nowrap">
|
|
128
|
+
<input type="checkbox" id="aiCpu"> CPU only
|
|
129
|
+
</label>
|
|
130
|
+
</div>
|
|
131
|
+
<pre id="aiLog" class="hide" style="max-height:9rem;overflow:auto;font-size:.75rem;margin:.6rem 0 0"></pre>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<!-- upload -->
|
|
135
|
+
<div class="card" id="uploadCard">
|
|
136
|
+
<h2>1 · Your dataset</h2>
|
|
137
|
+
<div class="drop" id="drop">
|
|
138
|
+
<b>Drop a .zip here, or click to choose</b>
|
|
139
|
+
<span>Pascal VOC, YOLO, COCO, LabelMe or CSV — detected automatically</span>
|
|
140
|
+
</div>
|
|
141
|
+
<p class="note" id="upNote" style="margin:.8rem 0 0"></p>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<!-- dataset summary -->
|
|
145
|
+
<div class="card hide" id="infoCard" style="margin-top:1.25rem">
|
|
146
|
+
<h2>Detected</h2>
|
|
147
|
+
<div class="stats" id="stats"></div>
|
|
148
|
+
<div id="classes"></div>
|
|
149
|
+
<p class="note" id="expiry"></p>
|
|
150
|
+
<div class="row" style="margin-top:.8rem">
|
|
151
|
+
<button class="primary" id="btnAnnotate">Start annotating</button>
|
|
152
|
+
<button id="btnDownloadSrc">Download source</button>
|
|
153
|
+
<button id="btnForget">Start over</button>
|
|
154
|
+
</div>
|
|
155
|
+
<p class="note" id="annotateNote" style="margin:.6rem 0 0">
|
|
156
|
+
Opens the editor. Any annotations already in this upload are imported, and
|
|
157
|
+
an existing class order is kept as-is so indices you have already exported
|
|
158
|
+
stay valid.
|
|
159
|
+
</p>
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
<!-- results -->
|
|
163
|
+
<div class="card hide" id="jobsCard" style="margin-top:1.25rem">
|
|
164
|
+
<h2>3 · Runs</h2>
|
|
165
|
+
<div id="jobs"></div>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<!-- operations -->
|
|
170
|
+
<div>
|
|
171
|
+
<div class="card">
|
|
172
|
+
<h2>2 · What to do</h2>
|
|
173
|
+
<div class="ops" id="ops"></div>
|
|
174
|
+
<form id="form"></form>
|
|
175
|
+
<div class="row" style="margin-top:.9rem">
|
|
176
|
+
<button class="primary" id="btnRun" disabled>Run</button>
|
|
177
|
+
<button id="btnPreview" disabled title="Show what would happen without writing anything">Dry run</button>
|
|
178
|
+
</div>
|
|
179
|
+
<p class="err hide" id="formErr" style="margin:.7rem 0 0"></p>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</main>
|
|
183
|
+
|
|
184
|
+
<script>
|
|
185
|
+
const $ = (id) => document.getElementById(id);
|
|
186
|
+
const api = (path, opts) => fetch(`/api${path}`, opts);
|
|
187
|
+
let OPS = [], selected = null, dataset = null, polling = new Map();
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------- startup
|
|
190
|
+
(async function init(){
|
|
191
|
+
const health = await (await api("/health")).json();
|
|
192
|
+
$("ver").textContent = `v${health.version} · ${health.operations} operations`;
|
|
193
|
+
OPS = (await (await api("/operations")).json()).operations;
|
|
194
|
+
renderOps();
|
|
195
|
+
})();
|
|
196
|
+
|
|
197
|
+
function renderOps(){
|
|
198
|
+
const groups = {};
|
|
199
|
+
for(const op of OPS) (groups[op.category] ??= []).push(op);
|
|
200
|
+
$("ops").innerHTML = Object.keys(groups).sort().map(cat =>
|
|
201
|
+
`<div class="cat">${cat}</div>` + groups[cat].map(op =>
|
|
202
|
+
`<div class="op" data-name="${op.name}">
|
|
203
|
+
<b>${op.name}</b><span>${esc(op.summary)}</span>
|
|
204
|
+
</div>`).join("")
|
|
205
|
+
).join("");
|
|
206
|
+
$("ops").querySelectorAll(".op").forEach(el =>
|
|
207
|
+
el.onclick = () => selectOp(el.dataset.name));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function selectOp(name){
|
|
211
|
+
selected = OPS.find(o => o.name === name);
|
|
212
|
+
$("ops").querySelectorAll(".op").forEach(el =>
|
|
213
|
+
el.classList.toggle("sel", el.dataset.name === name));
|
|
214
|
+
renderForm();
|
|
215
|
+
updateButtons();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Forms are generated from the operation's own declaration, so an operation
|
|
219
|
+
// added to the Python package appears here with no front-end change.
|
|
220
|
+
function renderForm(){
|
|
221
|
+
if(!selected){ $("form").innerHTML = ""; return; }
|
|
222
|
+
let html = "";
|
|
223
|
+
if(dataset && dataset.inputs.length > 1){
|
|
224
|
+
html += field("Run on", `<select name="__input">` +
|
|
225
|
+
dataset.inputs.map(i => `<option value="${i}">${i}</option>`).join("") + `</select>`,
|
|
226
|
+
"Use the uploaded dataset, or the result of an earlier step.");
|
|
227
|
+
}
|
|
228
|
+
if(selected.writes_output){
|
|
229
|
+
const suggested = selected.name.replace(/\./g, "_");
|
|
230
|
+
html += field("Name the result",
|
|
231
|
+
`<input type="text" name="__output" value="${suggested}">`,
|
|
232
|
+
"Becomes an input you can chain into the next step.");
|
|
233
|
+
}
|
|
234
|
+
for(const p of selected.params) html += control(p);
|
|
235
|
+
$("form").innerHTML = html || `<p class="note">No settings — just run it.</p>`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function control(p){
|
|
239
|
+
const req = p.required ? " *" : "";
|
|
240
|
+
const val = p.default ?? "";
|
|
241
|
+
let input;
|
|
242
|
+
if(p.kind === "bool"){
|
|
243
|
+
return `<label class="row" style="gap:.55rem">
|
|
244
|
+
<input type="checkbox" name="${p.name}" ${p.default ? "checked" : ""}>
|
|
245
|
+
<span><span class="n" style="margin:0">${p.name}</span>
|
|
246
|
+
<span class="h" style="margin:0">${esc(p.help)}</span></span></label>`;
|
|
247
|
+
}
|
|
248
|
+
if(p.kind === "choice"){
|
|
249
|
+
input = `<select name="${p.name}">` + p.choices.map(c =>
|
|
250
|
+
`<option ${c === p.default ? "selected" : ""}>${c}</option>`).join("") + `</select>`;
|
|
251
|
+
} else if(p.kind === "int" || p.kind === "float"){
|
|
252
|
+
const step = p.kind === "float" ? "0.05" : "1";
|
|
253
|
+
input = `<input type="number" step="${step}" name="${p.name}" value="${val}"
|
|
254
|
+
${p.minimum != null ? `min="${p.minimum}"` : ""} ${p.maximum != null ? `max="${p.maximum}"` : ""}>`;
|
|
255
|
+
} else {
|
|
256
|
+
input = `<input type="text" name="${p.name}" value="${esc(String(val))}"
|
|
257
|
+
placeholder="${p.kind === "strs" ? "comma,separated" : ""}">`;
|
|
258
|
+
}
|
|
259
|
+
return field(p.name + req, input, p.help);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const field = (name, input, help) =>
|
|
263
|
+
`<label><span class="n">${esc(name)}</span>${input}<span class="h">${esc(help || "")}</span></label>`;
|
|
264
|
+
|
|
265
|
+
// ---------------------------------------------------------------- upload
|
|
266
|
+
const drop = $("drop");
|
|
267
|
+
const picker = Object.assign(document.createElement("input"),
|
|
268
|
+
{type:"file", accept:".zip", style:"display:none"});
|
|
269
|
+
document.body.appendChild(picker);
|
|
270
|
+
drop.onclick = () => picker.click();
|
|
271
|
+
picker.onchange = () => picker.files[0] && upload(picker.files[0]);
|
|
272
|
+
["dragenter","dragover"].forEach(e => drop.addEventListener(e, ev => {
|
|
273
|
+
ev.preventDefault(); drop.classList.add("over"); }));
|
|
274
|
+
["dragleave","drop"].forEach(e => drop.addEventListener(e, ev => {
|
|
275
|
+
ev.preventDefault(); drop.classList.remove("over"); }));
|
|
276
|
+
drop.addEventListener("drop", ev => {
|
|
277
|
+
const file = ev.dataTransfer.files[0];
|
|
278
|
+
if(file) upload(file);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
async function upload(file){
|
|
282
|
+
if(!file.name.toLowerCase().endsWith(".zip"))
|
|
283
|
+
return note($("upNote"), "That needs to be a .zip of your dataset folder.", true);
|
|
284
|
+
note($("upNote"), `Uploading ${file.name} (${mb(file.size)})…`);
|
|
285
|
+
const body = new FormData(); body.append("file", file);
|
|
286
|
+
try{
|
|
287
|
+
const response = await api("/datasets", {method:"POST", body});
|
|
288
|
+
const payload = await response.json();
|
|
289
|
+
if(!response.ok) return note($("upNote"), payload.detail || "Upload failed.", true);
|
|
290
|
+
dataset = payload;
|
|
291
|
+
note($("upNote"), `${payload.uploaded.files.toLocaleString()} files unpacked.` +
|
|
292
|
+
(payload.uploaded.skipped ? ` ${payload.uploaded.skipped} unsafe entries skipped.` : ""));
|
|
293
|
+
showInfo();
|
|
294
|
+
}catch(err){ note($("upNote"), String(err), true); }
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function showInfo(){
|
|
298
|
+
const s = dataset.stats;
|
|
299
|
+
$("infoCard").classList.remove("hide");
|
|
300
|
+
$("stats").innerHTML = s ? [
|
|
301
|
+
["images", s.images], ["objects", s.objects], ["classes", s.classes],
|
|
302
|
+
["backgrounds", s.backgrounds], ["polygons", s.with_polygons],
|
|
303
|
+
].map(([k,v]) => `<div class="stat"><b>${(v??0).toLocaleString()}</b><span>${k}</span></div>`).join("")
|
|
304
|
+
: `<p class="note">No annotations detected — image-only operations still work.</p>`;
|
|
305
|
+
$("classes").innerHTML = (dataset.format ? `<span class="pill">${dataset.format}</span>` : "") +
|
|
306
|
+
(dataset.classes || []).map(c => `<span class="pill">${esc(c)}</span>`).join("");
|
|
307
|
+
const hours = Math.round((dataset.expires_in_seconds || 0) / 3600);
|
|
308
|
+
$("expiry").textContent = `Stored temporarily and deleted automatically in about ${hours} hours.`;
|
|
309
|
+
renderForm(); updateButtons();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function updateButtons(){
|
|
313
|
+
const ready = !!(dataset && selected);
|
|
314
|
+
$("btnRun").disabled = !ready;
|
|
315
|
+
$("btnPreview").disabled = !ready;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Promotion is the moment an anonymous upload becomes somebody's work: it
|
|
319
|
+
// stops expiring, and gains a class order that later exports are held to.
|
|
320
|
+
$("btnAnnotate").onclick = async () => {
|
|
321
|
+
if(!dataset) return;
|
|
322
|
+
const button = $("btnAnnotate");
|
|
323
|
+
button.disabled = true;
|
|
324
|
+
button.textContent = "Preparing…";
|
|
325
|
+
try{
|
|
326
|
+
const response = await api(`/datasets/${dataset.id}/promote`, {
|
|
327
|
+
method: "POST",
|
|
328
|
+
headers: {"Content-Type": "application/json"},
|
|
329
|
+
body: JSON.stringify({}),
|
|
330
|
+
});
|
|
331
|
+
const project = await response.json();
|
|
332
|
+
if(!response.ok) throw new Error(project.detail || "could not start annotating");
|
|
333
|
+
window.location = `/annotate?project=${encodeURIComponent(project.id)}`;
|
|
334
|
+
}catch(error){
|
|
335
|
+
$("annotateNote").textContent = String(error.message || error);
|
|
336
|
+
button.disabled = false;
|
|
337
|
+
button.textContent = "Start annotating";
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// ---------------------------------------------------------------- this computer
|
|
342
|
+
// Two ways to be allowed to open a local folder: the desktop window's own
|
|
343
|
+
// bridge, or the token a launcher put in this tab's URL fragment. Either way
|
|
344
|
+
// the page only ever gets a project id back.
|
|
345
|
+
const LOCAL_KEY = "easyannotate:local-token";
|
|
346
|
+
function adoptLocalToken(){
|
|
347
|
+
const match = /(?:^|[#&])token=([^&]+)/.exec(location.hash || "");
|
|
348
|
+
if(!match) return false;
|
|
349
|
+
try{ sessionStorage.setItem(LOCAL_KEY, decodeURIComponent(match[1])); }catch(e){}
|
|
350
|
+
history.replaceState(null, "", location.pathname + location.search);
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
adoptLocalToken();
|
|
354
|
+
// Pasting the launcher's URL into a tab already on this page changes only the
|
|
355
|
+
// fragment, which does not reload it -- so listen for that too.
|
|
356
|
+
window.addEventListener("hashchange", () => { if(adoptLocalToken()) enableLocal(); });
|
|
357
|
+
function localToken(){
|
|
358
|
+
try{ return sessionStorage.getItem(LOCAL_KEY) || ""; }catch(e){ return ""; }
|
|
359
|
+
}
|
|
360
|
+
const hasBridge = () => !!(window.pywebview && window.pywebview.api && window.pywebview.api.pick_folder);
|
|
361
|
+
let serverDialog = false;
|
|
362
|
+
|
|
363
|
+
async function localApi(path, body){
|
|
364
|
+
const response = await api(`/local${path}`, {
|
|
365
|
+
method: body === undefined ? "GET" : "POST",
|
|
366
|
+
headers: {"Content-Type": "application/json", "X-Local-Token": localToken()},
|
|
367
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
368
|
+
});
|
|
369
|
+
const payload = await response.json().catch(() => ({}));
|
|
370
|
+
if(!response.ok) throw new Error(payload.detail || `HTTP ${response.status}`);
|
|
371
|
+
return payload;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async function enableLocal(){
|
|
375
|
+
let viaToken = false;
|
|
376
|
+
if(localToken()){
|
|
377
|
+
try{
|
|
378
|
+
const status = await localApi("/status");
|
|
379
|
+
viaToken = true;
|
|
380
|
+
serverDialog = !!status.dialog;
|
|
381
|
+
}catch(e){ /* a stale or foreign token: behave as an ordinary page */ }
|
|
382
|
+
}
|
|
383
|
+
if(!viaToken && !hasBridge()) return;
|
|
384
|
+
$("openFolderCard").classList.remove("hide");
|
|
385
|
+
if(viaToken) showAiTools();
|
|
386
|
+
// Typing a path needs the token; browsing needs the bridge or a dialog.
|
|
387
|
+
$("folderPath").parentElement.querySelector("#btnOpenPath").classList.toggle("hide", !viaToken);
|
|
388
|
+
$("folderPath").classList.toggle("hide", !viaToken);
|
|
389
|
+
$("btnOpenFolder").classList.toggle("hide", !(hasBridge() || serverDialog));
|
|
390
|
+
showRecent();
|
|
391
|
+
}
|
|
392
|
+
window.addEventListener("pywebviewready", enableLocal);
|
|
393
|
+
enableLocal();
|
|
394
|
+
|
|
395
|
+
function goTo(result){
|
|
396
|
+
if(result.cancelled) return;
|
|
397
|
+
$("openFolderNote").textContent = `${result.name}: ${result.images} image(s)` +
|
|
398
|
+
(result.imported ? `, ${result.imported} existing shape(s) loaded` : "") + " — opening…";
|
|
399
|
+
window.location = `/annotate?project=${encodeURIComponent(result.project)}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async function withBusy(button, work){
|
|
403
|
+
button.disabled = true;
|
|
404
|
+
try{ await work(); }
|
|
405
|
+
catch(error){ $("openFolderNote").textContent = String(error.message || error); }
|
|
406
|
+
finally{ button.disabled = false; }
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
$("btnOpenPath").onclick = () => withBusy($("btnOpenPath"), async () => {
|
|
410
|
+
const path = $("folderPath").value.trim();
|
|
411
|
+
if(!path){ $("openFolderNote").textContent = "paste the folder's full path first"; return; }
|
|
412
|
+
goTo(await localApi("/open", {path}));
|
|
413
|
+
});
|
|
414
|
+
$("folderPath").addEventListener("keydown", (event) => {
|
|
415
|
+
if(event.key === "Enter") $("btnOpenPath").click();
|
|
416
|
+
});
|
|
417
|
+
$("btnOpenFolder").onclick = () => withBusy($("btnOpenFolder"), async () => {
|
|
418
|
+
if(hasBridge()){
|
|
419
|
+
const result = await window.pywebview.api.pick_folder();
|
|
420
|
+
if(result.error) throw new Error(result.error);
|
|
421
|
+
goTo(result);
|
|
422
|
+
}else{
|
|
423
|
+
goTo(await localApi("/pick", {}));
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// The heavy half, on request: what this machine would get, then the download.
|
|
428
|
+
async function showAiTools(){
|
|
429
|
+
let state;
|
|
430
|
+
try{ state = await localApi("/tools"); }catch(e){ return; }
|
|
431
|
+
$("aiCard").classList.remove("hide");
|
|
432
|
+
const plan = state.plan || {};
|
|
433
|
+
$("aiMachine").textContent = `This computer: ${plan.summary || "unknown"}` +
|
|
434
|
+
((plan.warnings || []).length ? ` — ${plan.warnings.join(" ")}` : "");
|
|
435
|
+
const button = $("btnInstallAi");
|
|
436
|
+
if(state.installed){
|
|
437
|
+
const profile = state.profile || {};
|
|
438
|
+
$("aiState").textContent = `Installed: ${profile.summary || ""} (PyTorch sees ${profile.verified_device || "?"}). ` +
|
|
439
|
+
"Open a project to use the Assist panel.";
|
|
440
|
+
button.textContent = "Reinstall";
|
|
441
|
+
}else{
|
|
442
|
+
$("aiState").textContent = `Not installed. About ${plan.download_gb || "?"} GB, into a separate ` +
|
|
443
|
+
"environment -- the editor works the same without it.";
|
|
444
|
+
}
|
|
445
|
+
if(state.job) watchInstall(state.job.id);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
$("btnInstallAi").onclick = () => withBusy($("btnInstallAi"), async () => {
|
|
449
|
+
const job = await localApi("/tools/install", {device: $("aiCpu").checked ? "cpu" : null});
|
|
450
|
+
watchInstall(job.id);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
async function watchInstall(jobId){
|
|
454
|
+
const log = $("aiLog");
|
|
455
|
+
log.classList.remove("hide");
|
|
456
|
+
$("btnInstallAi").disabled = true;
|
|
457
|
+
try{
|
|
458
|
+
for(;;){
|
|
459
|
+
const job = await (await api(`/jobs/${jobId}`)).json();
|
|
460
|
+
const message = (job.progress || {}).message;
|
|
461
|
+
if(message && !log.textContent.endsWith(message)){
|
|
462
|
+
log.textContent += (log.textContent ? "\n" : "") + message;
|
|
463
|
+
log.scrollTop = log.scrollHeight;
|
|
464
|
+
}
|
|
465
|
+
if(["finished", "failed", "cancelled"].includes(job.state)){
|
|
466
|
+
const result = job.result || {};
|
|
467
|
+
if(job.state !== "finished" || result.ok === false){
|
|
468
|
+
$("aiState").textContent = "Install failed: " + ((result.errors || []).join("; ") || job.error || job.state);
|
|
469
|
+
}else{
|
|
470
|
+
await showAiTools();
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
475
|
+
}
|
|
476
|
+
}finally{
|
|
477
|
+
$("btnInstallAi").disabled = false;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async function showRecent(){
|
|
482
|
+
try{
|
|
483
|
+
const payload = await (await api("/projects")).json();
|
|
484
|
+
const projects = (payload.projects || []).slice(0, 6);
|
|
485
|
+
if(!projects.length) return;
|
|
486
|
+
const list = $("recentList");
|
|
487
|
+
list.replaceChildren();
|
|
488
|
+
for(const project of projects){
|
|
489
|
+
const link = document.createElement("a");
|
|
490
|
+
link.href = `/annotate?project=${encodeURIComponent(project.id)}`;
|
|
491
|
+
link.textContent = project.name;
|
|
492
|
+
link.style.cssText = "display:block;padding:.2rem 0";
|
|
493
|
+
list.append(link);
|
|
494
|
+
}
|
|
495
|
+
$("recentProjects").classList.remove("hide");
|
|
496
|
+
}catch(e){ /* recent projects are a convenience */ }
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// ---------------------------------------------------------------- running
|
|
500
|
+
$("btnRun").onclick = () => run(false);
|
|
501
|
+
$("btnPreview").onclick = () => run(true);
|
|
502
|
+
|
|
503
|
+
async function run(dryRun){
|
|
504
|
+
if(!dataset || !selected) return;
|
|
505
|
+
const form = new FormData($("form"));
|
|
506
|
+
const params = {};
|
|
507
|
+
let input = null, outputName = "";
|
|
508
|
+
for(const p of selected.params){
|
|
509
|
+
if(p.kind === "bool"){ params[p.name] = form.has(p.name); continue; }
|
|
510
|
+
const raw = (form.get(p.name) ?? "").toString().trim();
|
|
511
|
+
if(raw !== "") params[p.name] = raw;
|
|
512
|
+
}
|
|
513
|
+
if(form.has("__input")) input = form.get("__input");
|
|
514
|
+
if(form.has("__output")) outputName = form.get("__output");
|
|
515
|
+
|
|
516
|
+
$("formErr").classList.add("hide");
|
|
517
|
+
const response = await api(`/datasets/${dataset.id}/run/${selected.name}`, {
|
|
518
|
+
method:"POST", headers:{"Content-Type":"application/json"},
|
|
519
|
+
body: JSON.stringify({params, input, output_name: outputName, dry_run: dryRun}),
|
|
520
|
+
});
|
|
521
|
+
const payload = await response.json();
|
|
522
|
+
if(!response.ok){
|
|
523
|
+
$("formErr").textContent = payload.detail || "That did not work.";
|
|
524
|
+
$("formErr").classList.remove("hide");
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
$("jobsCard").classList.remove("hide");
|
|
528
|
+
track(payload);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function track(job){
|
|
532
|
+
let el = $(`job-${job.id}`);
|
|
533
|
+
if(!el){
|
|
534
|
+
el = document.createElement("div");
|
|
535
|
+
el.className = "job"; el.id = `job-${job.id}`;
|
|
536
|
+
$("jobs").prepend(el);
|
|
537
|
+
}
|
|
538
|
+
paint(el, job);
|
|
539
|
+
if(["queued","running"].includes(job.state)){
|
|
540
|
+
if(!polling.has(job.id)){
|
|
541
|
+
polling.set(job.id, setInterval(async () => {
|
|
542
|
+
const next = await (await api(`/jobs/${job.id}`)).json();
|
|
543
|
+
paint($(`job-${job.id}`), next);
|
|
544
|
+
if(!["queued","running"].includes(next.state)){
|
|
545
|
+
clearInterval(polling.get(job.id)); polling.delete(job.id);
|
|
546
|
+
if(next.state === "finished") refreshInputs();
|
|
547
|
+
}
|
|
548
|
+
}, 600));
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function paint(el, job){
|
|
554
|
+
if(!el) return;
|
|
555
|
+
const p = job.progress || {};
|
|
556
|
+
const counts = job.result && job.result.counts || {};
|
|
557
|
+
const findings = (job.result && job.result.data && job.result.data.findings) || [];
|
|
558
|
+
const warnings = (job.result && job.result.warnings) || [];
|
|
559
|
+
el.innerHTML =
|
|
560
|
+
`<div class="t"><b>${job.operation}</b>
|
|
561
|
+
${job.output ? `<span class="note">→ ${esc(job.output)}</span>` : ""}
|
|
562
|
+
<span class="s ${job.state}">${job.state}</span></div>` +
|
|
563
|
+
(["queued","running"].includes(job.state)
|
|
564
|
+
? `<div class="track"><i style="width:${p.percent ?? 3}%"></i></div>
|
|
565
|
+
<div class="msg">${esc(p.message || "working…")} ${p.total ? `(${p.done}/${p.total})` : ""}</div>`
|
|
566
|
+
: "") +
|
|
567
|
+
(job.error ? `<div class="err" style="margin-top:.4rem">${esc(job.error)}</div>` : "") +
|
|
568
|
+
(Object.keys(counts).length
|
|
569
|
+
? `<div class="msg" style="margin-top:.45rem">` + Object.entries(counts)
|
|
570
|
+
.map(([k,v]) => `${k} <b>${Number(v).toLocaleString()}</b>`).join(" · ") + `</div>` : "") +
|
|
571
|
+
findings.slice(0,6).map(f =>
|
|
572
|
+
`<div class="finding ${f.severity}"><b>${esc(f.issue)}</b>
|
|
573
|
+
<span>${esc(f.detail)}</span><br><span>Fix: ${esc(f.fix)}</span></div>`).join("") +
|
|
574
|
+
(warnings.length && !findings.length
|
|
575
|
+
? `<div class="msg" style="margin-top:.4rem">${esc(warnings[0])}</div>` : "") +
|
|
576
|
+
(job.state === "finished" && job.output
|
|
577
|
+
? `<div class="row" style="margin-top:.6rem">
|
|
578
|
+
<button onclick="download('${job.output}')">Download result</button></div>` : "") +
|
|
579
|
+
(["queued","running"].includes(job.state)
|
|
580
|
+
? `<div class="row" style="margin-top:.6rem">
|
|
581
|
+
<button onclick="cancel('${job.id}')">Cancel</button></div>` : "");
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// A finished run adds a new chainable input, so the form has to re-render to
|
|
585
|
+
// offer it -- but re-rendering naively throws away whatever the user has
|
|
586
|
+
// already typed, which is infuriating right after a long run. Capture, render,
|
|
587
|
+
// restore.
|
|
588
|
+
async function refreshInputs(){
|
|
589
|
+
if(!dataset) return;
|
|
590
|
+
const fresh = await (await api(`/datasets/${dataset.id}`)).json();
|
|
591
|
+
dataset.inputs = fresh.inputs;
|
|
592
|
+
|
|
593
|
+
const previous = {};
|
|
594
|
+
$("form").querySelectorAll("input,select").forEach(el => {
|
|
595
|
+
previous[el.name] = el.type === "checkbox" ? el.checked : el.value;
|
|
596
|
+
});
|
|
597
|
+
renderForm();
|
|
598
|
+
$("form").querySelectorAll("input,select").forEach(el => {
|
|
599
|
+
if(!(el.name in previous)) return;
|
|
600
|
+
// Not the output name: reusing it would overwrite the result just made.
|
|
601
|
+
if(el.name === "__output") return;
|
|
602
|
+
if(el.type === "checkbox") el.checked = previous[el.name];
|
|
603
|
+
else if([...(el.options || [])].some(o => o.value === previous[el.name]) || !el.options)
|
|
604
|
+
el.value = previous[el.name];
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
window.download = (output) =>
|
|
609
|
+
window.location = `/api/datasets/${dataset.id}/download?output=${encodeURIComponent(output)}`;
|
|
610
|
+
window.cancel = (id) => api(`/jobs/${id}/cancel`, {method:"POST"});
|
|
611
|
+
|
|
612
|
+
$("btnDownloadSrc").onclick = () => window.download("source");
|
|
613
|
+
$("btnForget").onclick = async () => {
|
|
614
|
+
if(dataset) await api(`/datasets/${dataset.id}`, {method:"DELETE"});
|
|
615
|
+
dataset = null;
|
|
616
|
+
$("infoCard").classList.add("hide"); $("jobsCard").classList.add("hide");
|
|
617
|
+
$("jobs").innerHTML = ""; note($("upNote"), "");
|
|
618
|
+
renderForm(); updateButtons();
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// ---------------------------------------------------------------- helpers
|
|
622
|
+
function note(el, text, isError){
|
|
623
|
+
el.textContent = text; el.className = isError ? "err" : "note";
|
|
624
|
+
}
|
|
625
|
+
function esc(s){
|
|
626
|
+
return String(s ?? "").replace(/[&<>"']/g, c =>
|
|
627
|
+
({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
|
|
628
|
+
}
|
|
629
|
+
const mb = (b) => b > 1e9 ? `${(b/1e9).toFixed(1)} GB` : `${(b/1e6).toFixed(1)} MB`;
|
|
630
|
+
</script>
|
|
631
|
+
</body>
|
|
632
|
+
</html>
|