Spaces:
Running
Running
hf login button + sink routing
Browse files- review.html +36 -3
review.html
CHANGED
|
@@ -72,10 +72,30 @@ footer .sp { flex: 1; }
|
|
| 72 |
<span class="sp"></span><span id="count"></span>
|
| 73 |
<input id="hubtok" type="password" placeholder="HF token" title="write token for data-use-annotations; only needed on static hosting without the bundled server"
|
| 74 |
style="font:inherit;color:var(--fg);background:var(--bg);border:1px solid var(--line);border-radius:8px;padding:8px 10px;max-width:130px">
|
| 75 |
-
<button id="
|
| 76 |
<button id="hubBtn" onclick="exp()">export</button>
|
| 77 |
</footer>
|
| 78 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
const DS = { sample: './queue_annotate_sample.json', gold: './queue_review473.json',
|
| 80 |
paddy: './queue_annotate_paddy.json', aj: './queue_annotate_aj.json',
|
| 81 |
aivin: './queue_annotate_aivin.json', rafael: './queue_annotate_rafael.json' };
|
|
@@ -254,9 +274,9 @@ async function rule(v) {
|
|
| 254 |
const r = await fetch('/api/rulings', {method: 'POST', headers: {'Content-Type': 'application/json'},
|
| 255 |
body: JSON.stringify(entry)});
|
| 256 |
if (r.ok) saved = (await r.json()).pushed ? 'server + Hub' : 'server';
|
| 257 |
-
else
|
| 258 |
} catch (e) {
|
| 259 |
-
saved = await
|
| 260 |
}
|
| 261 |
lastSaved = saved;
|
| 262 |
// next unruled span in passage, else next passage
|
|
@@ -266,6 +286,19 @@ async function rule(v) {
|
|
| 266 |
else if (i < ITEMS.length - 1) show(i + 1, 0);
|
| 267 |
else { light(); }
|
| 268 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
async function hubCommit(entry) {
|
| 270 |
// static hosting has no ruling sink: commit straight to the public
|
| 271 |
// dataset with the annotator's own write token (stored locally only).
|
|
|
|
| 72 |
<span class="sp"></span><span id="count"></span>
|
| 73 |
<input id="hubtok" type="password" placeholder="HF token" title="write token for data-use-annotations; only needed on static hosting without the bundled server"
|
| 74 |
style="font:inherit;color:var(--fg);background:var(--bg);border:1px solid var(--line);border-radius:8px;padding:8px 10px;max-width:130px">
|
| 75 |
+
<button id="hfBtn" onclick="hfLogin()" title="log in to push rulings to the Hub as yourself">log in with HF</button>
|
| 76 |
<button id="hubBtn" onclick="exp()">export</button>
|
| 77 |
</footer>
|
| 78 |
<script>
|
| 79 |
+
let SINK = null, HFFUSER = null;
|
| 80 |
+
fetch('./sink.json').then(r => r.ok ? r.json() : null).then(async j => {
|
| 81 |
+
if (!j || !j.url) return;
|
| 82 |
+
SINK = j.url.replace(/\/$/, '');
|
| 83 |
+
paintLogin();
|
| 84 |
+
try {
|
| 85 |
+
const m = await fetch(SINK + '/me', {credentials: 'include'});
|
| 86 |
+
if (m.ok) { HFFUSER = (await m.json()).user; paintLogin(); }
|
| 87 |
+
} catch (e) {}
|
| 88 |
+
});
|
| 89 |
+
function paintLogin() {
|
| 90 |
+
const b = $('hfBtn');
|
| 91 |
+
if (!b) return;
|
| 92 |
+
b.textContent = HFFUSER ? 'HF: ' + HFFUSER : 'log in with HF';
|
| 93 |
+
b.title = HFFUSER ? 'logged in — rulings commit as you' : 'log in to push rulings to the Hub as yourself';
|
| 94 |
+
}
|
| 95 |
+
function hfLogin() {
|
| 96 |
+
if (!SINK) return;
|
| 97 |
+
location.href = SINK + '/login?next=' + encodeURIComponent(location.href.split('?')[0] + location.search);
|
| 98 |
+
}
|
| 99 |
const DS = { sample: './queue_annotate_sample.json', gold: './queue_review473.json',
|
| 100 |
paddy: './queue_annotate_paddy.json', aj: './queue_annotate_aj.json',
|
| 101 |
aivin: './queue_annotate_aivin.json', rafael: './queue_annotate_rafael.json' };
|
|
|
|
| 274 |
const r = await fetch('/api/rulings', {method: 'POST', headers: {'Content-Type': 'application/json'},
|
| 275 |
body: JSON.stringify(entry)});
|
| 276 |
if (r.ok) saved = (await r.json()).pushed ? 'server + Hub' : 'server';
|
| 277 |
+
else saved = await sinkCommit(entry);
|
| 278 |
} catch (e) {
|
| 279 |
+
saved = await sinkCommit(entry);
|
| 280 |
}
|
| 281 |
lastSaved = saved;
|
| 282 |
// next unruled span in passage, else next passage
|
|
|
|
| 286 |
else if (i < ITEMS.length - 1) show(i + 1, 0);
|
| 287 |
else { light(); }
|
| 288 |
}
|
| 289 |
+
async function sinkCommit(entry) {
|
| 290 |
+
// shared sink (Cloudflare Worker) if configured, else the annotator's
|
| 291 |
+
// own token, else local-only. The sink holds no shared secret: with HF
|
| 292 |
+
// login it commits with the annotator's own OAuth token.
|
| 293 |
+
if (SINK) {
|
| 294 |
+
try {
|
| 295 |
+
const r = await fetch(SINK + '/rulings', {method: 'POST', credentials: 'include',
|
| 296 |
+
headers: {'Content-Type': 'application/json'}, body: JSON.stringify(entry)});
|
| 297 |
+
if (r.ok) return 'Hub (' + ((await r.json()).as || 'you') + ')';
|
| 298 |
+
} catch (e) {}
|
| 299 |
+
}
|
| 300 |
+
return hubCommit(entry);
|
| 301 |
+
}
|
| 302 |
async function hubCommit(entry) {
|
| 303 |
// static hosting has no ruling sink: commit straight to the public
|
| 304 |
// dataset with the annotator's own write token (stored locally only).
|