Spaces:
Sleeping
Sleeping
Random dataset: secondary button in the input bar
Browse files- static/index.html +10 -9
static/index.html
CHANGED
|
@@ -18,6 +18,7 @@ input:focus{outline:none}
|
|
| 18 |
form:focus-within{border-color:var(--bar);box-shadow:0 0 0 3px var(--bar-soft)}
|
| 19 |
button{font:600 15px "Schibsted Grotesk",sans-serif;border:0;border-radius:7px;background:var(--ink);color:#fff;cursor:pointer;padding:0 18px}
|
| 20 |
button:focus-visible,a:focus-visible{outline:2px solid var(--bar);outline-offset:3px}
|
|
|
|
| 21 |
.examples{margin:10px 0 42px;color:var(--muted);font-size:14px}
|
| 22 |
.examples button{font:14px "Schibsted Grotesk",sans-serif;background:none;color:var(--ink);text-decoration:underline;text-decoration-color:#C9CED8;text-underline-offset:3px;margin-right:14px;padding:0;border-radius:0}
|
| 23 |
.grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:44px;align-items:start}
|
|
@@ -45,6 +46,7 @@ h2{font-size:14px;font-weight:600;margin:0 0 12px;color:var(--muted)}
|
|
| 45 |
.about{margin-top:52px;max-width:64ch;font-size:15px;color:#3A4150;border-top:1px solid var(--rule);padding-top:20px}.about p{margin:0 0 10px}.todo{color:#B04A2F;font-style:italic}
|
| 46 |
.timing{margin-top:18px;color:var(--muted);font-size:13px}
|
| 47 |
.status{margin:-28px 0 42px;font-size:15px;max-width:680px}.status:empty{display:none}.status.err{color:#B04A2F}.status.load{color:var(--muted)}button:disabled{opacity:.6;cursor:default}
|
|
|
|
| 48 |
@media (max-width:760px){.grid{grid-template-columns:1fr;gap:34px}.row{grid-template-columns:minmax(0,1fr) 80px 48px}}
|
| 49 |
</style>
|
| 50 |
</head>
|
|
@@ -52,8 +54,8 @@ h2{font-size:14px;font-weight:600;margin:0 0 12px;color:var(--muted)}
|
|
| 52 |
<main>
|
| 53 |
<h1>What is this dataset for?</h1>
|
| 54 |
<p class="lede">Paste a Hugging Face dataset id. A small fine-tuned model reads the column names and the first row, then suggests task tags.</p>
|
| 55 |
-
<form id="f"><input id="q" aria-label="Dataset id" placeholder="owner/dataset" autocomplete="off"><button>Suggest tags</button></form>
|
| 56 |
-
<div class="examples">Examples: <span id="ex"></span><
|
| 57 |
<p class="status" id="status" role="status" aria-live="polite"></p>
|
| 58 |
|
| 59 |
<section id="out" hidden>
|
|
@@ -109,13 +111,13 @@ function show(ex){
|
|
| 109 |
: `Fetched the preview in ${ex.timing.fetch_ms} ms. The model took ${ex.timing.model_ms} ms on a free CPU.`;
|
| 110 |
}
|
| 111 |
let pending = null;
|
|
|
|
| 112 |
async function run(id){
|
| 113 |
id = id.trim();
|
| 114 |
if (!id) { $("out").hidden = true; status("Paste a dataset id first, for example " + EXAMPLES[0] + ".", "err"); return; }
|
| 115 |
if (pending) pending.abort();
|
| 116 |
pending = new AbortController();
|
| 117 |
-
|
| 118 |
-
button.disabled = true; $("out").hidden = true;
|
| 119 |
status("Reading the dataset…", "load");
|
| 120 |
try {
|
| 121 |
const r = await fetch("api/predict", {method: "POST", headers: {"Content-Type": "application/json"},
|
|
@@ -133,15 +135,14 @@ async function run(id){
|
|
| 133 |
if (e.name === "AbortError") return;
|
| 134 |
status("Could not reach the server. Check your connection and try again.", "err");
|
| 135 |
} finally {
|
| 136 |
-
|
| 137 |
}
|
| 138 |
}
|
| 139 |
$("ex").innerHTML = EXAMPLES.map((id,i) => `<button type="button" data-i="${i}">${id.length > 40 ? id.slice(0,38) + "…" : id}</button>`).join("");
|
| 140 |
$("ex").onclick = e => { const i = e.target.dataset.i; if (i !== undefined) { $("q").value = EXAMPLES[i]; run(EXAMPLES[i]); } };
|
| 141 |
$("random").onclick = async () => {
|
| 142 |
if (pending) pending.abort();
|
| 143 |
-
|
| 144 |
-
button.disabled = true; $("out").hidden = true;
|
| 145 |
status("Picking a random dataset…", "load");
|
| 146 |
try {
|
| 147 |
const r = await fetch("api/random");
|
|
@@ -153,11 +154,11 @@ $("random").onclick = async () => {
|
|
| 153 |
return;
|
| 154 |
}
|
| 155 |
$("q").value = body.dataset_id;
|
| 156 |
-
run(body.dataset_id);
|
| 157 |
} catch (e) {
|
| 158 |
status("Could not reach the server. Check your connection and try again.", "err");
|
| 159 |
} finally {
|
| 160 |
-
|
| 161 |
}
|
| 162 |
};
|
| 163 |
$("f").onsubmit = e => { e.preventDefault(); run($("q").value); };
|
|
|
|
| 18 |
form:focus-within{border-color:var(--bar);box-shadow:0 0 0 3px var(--bar-soft)}
|
| 19 |
button{font:600 15px "Schibsted Grotesk",sans-serif;border:0;border-radius:7px;background:var(--ink);color:#fff;cursor:pointer;padding:0 18px}
|
| 20 |
button:focus-visible,a:focus-visible{outline:2px solid var(--bar);outline-offset:3px}
|
| 21 |
+
#go,button.secondary{border:1px solid var(--ink)}button.secondary{background:#fff;color:var(--ink)}
|
| 22 |
.examples{margin:10px 0 42px;color:var(--muted);font-size:14px}
|
| 23 |
.examples button{font:14px "Schibsted Grotesk",sans-serif;background:none;color:var(--ink);text-decoration:underline;text-decoration-color:#C9CED8;text-underline-offset:3px;margin-right:14px;padding:0;border-radius:0}
|
| 24 |
.grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:44px;align-items:start}
|
|
|
|
| 46 |
.about{margin-top:52px;max-width:64ch;font-size:15px;color:#3A4150;border-top:1px solid var(--rule);padding-top:20px}.about p{margin:0 0 10px}.todo{color:#B04A2F;font-style:italic}
|
| 47 |
.timing{margin-top:18px;color:var(--muted);font-size:13px}
|
| 48 |
.status{margin:-28px 0 42px;font-size:15px;max-width:680px}.status:empty{display:none}.status.err{color:#B04A2F}.status.load{color:var(--muted)}button:disabled{opacity:.6;cursor:default}
|
| 49 |
+
@media (max-width:560px){form{flex-wrap:wrap}input{flex:1 1 100%}form button{flex:1 1 100%;padding:11px 18px}}
|
| 50 |
@media (max-width:760px){.grid{grid-template-columns:1fr;gap:34px}.row{grid-template-columns:minmax(0,1fr) 80px 48px}}
|
| 51 |
</style>
|
| 52 |
</head>
|
|
|
|
| 54 |
<main>
|
| 55 |
<h1>What is this dataset for?</h1>
|
| 56 |
<p class="lede">Paste a Hugging Face dataset id. A small fine-tuned model reads the column names and the first row, then suggests task tags.</p>
|
| 57 |
+
<form id="f"><input id="q" aria-label="Dataset id" placeholder="owner/dataset" autocomplete="off"><button type="button" id="random" class="secondary">Random dataset</button><button id="go">Suggest tags</button></form>
|
| 58 |
+
<div class="examples">Examples: <span id="ex"></span></div>
|
| 59 |
<p class="status" id="status" role="status" aria-live="polite"></p>
|
| 60 |
|
| 61 |
<section id="out" hidden>
|
|
|
|
| 111 |
: `Fetched the preview in ${ex.timing.fetch_ms} ms. The model took ${ex.timing.model_ms} ms on a free CPU.`;
|
| 112 |
}
|
| 113 |
let pending = null;
|
| 114 |
+
function busy(on){ $("go").disabled = on; $("random").disabled = on; }
|
| 115 |
async function run(id){
|
| 116 |
id = id.trim();
|
| 117 |
if (!id) { $("out").hidden = true; status("Paste a dataset id first, for example " + EXAMPLES[0] + ".", "err"); return; }
|
| 118 |
if (pending) pending.abort();
|
| 119 |
pending = new AbortController();
|
| 120 |
+
busy(true); $("out").hidden = true;
|
|
|
|
| 121 |
status("Reading the dataset…", "load");
|
| 122 |
try {
|
| 123 |
const r = await fetch("api/predict", {method: "POST", headers: {"Content-Type": "application/json"},
|
|
|
|
| 135 |
if (e.name === "AbortError") return;
|
| 136 |
status("Could not reach the server. Check your connection and try again.", "err");
|
| 137 |
} finally {
|
| 138 |
+
busy(false);
|
| 139 |
}
|
| 140 |
}
|
| 141 |
$("ex").innerHTML = EXAMPLES.map((id,i) => `<button type="button" data-i="${i}">${id.length > 40 ? id.slice(0,38) + "…" : id}</button>`).join("");
|
| 142 |
$("ex").onclick = e => { const i = e.target.dataset.i; if (i !== undefined) { $("q").value = EXAMPLES[i]; run(EXAMPLES[i]); } };
|
| 143 |
$("random").onclick = async () => {
|
| 144 |
if (pending) pending.abort();
|
| 145 |
+
busy(true); $("out").hidden = true;
|
|
|
|
| 146 |
status("Picking a random dataset…", "load");
|
| 147 |
try {
|
| 148 |
const r = await fetch("api/random");
|
|
|
|
| 154 |
return;
|
| 155 |
}
|
| 156 |
$("q").value = body.dataset_id;
|
| 157 |
+
await run(body.dataset_id); // run() keeps both buttons disabled until the prediction arrives
|
| 158 |
} catch (e) {
|
| 159 |
status("Could not reach the server. Check your connection and try again.", "err");
|
| 160 |
} finally {
|
| 161 |
+
busy(false);
|
| 162 |
}
|
| 163 |
};
|
| 164 |
$("f").onsubmit = e => { e.preventDefault(); run($("q").value); };
|