Spaces:
Sleeping
Sleeping
Demo v1: FastAPI backend + single-page frontend
Browse files- static/index.html +4 -7
static/index.html
CHANGED
|
@@ -44,7 +44,7 @@ h2{font-size:14px;font-weight:600;margin:0 0 12px;color:var(--muted)}
|
|
| 44 |
.viewer iframe{width:100%;height:520px;border:1px solid var(--rule);border-radius:10px;background:#fff}
|
| 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)}
|
| 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>
|
|
@@ -91,7 +91,7 @@ const $ = id => document.getElementById(id);
|
|
| 91 |
function pct(p){ return p < 0.001 ? "<0.1%" : (p*100).toFixed(p < 0.1 ? 1 : 0) + "%"; }
|
| 92 |
function status(text, kind){ $("status").textContent = text; $("status").className = "status " + (kind || ""); }
|
| 93 |
function show(ex){
|
| 94 |
-
$("out").hidden = false; $("
|
| 95 |
$("name").textContent = ex.dataset_id;
|
| 96 |
$("card").href = "https://huggingface.co/datasets/" + ex.dataset_id;
|
| 97 |
const declared = new Set(ex.declared), inSet = new Set(ex.set);
|
|
@@ -110,11 +110,11 @@ function show(ex){
|
|
| 110 |
let pending = null;
|
| 111 |
async function run(id){
|
| 112 |
id = id.trim();
|
| 113 |
-
if (!id) { status("Paste a dataset id first, for example " + EXAMPLES[0] + ".", "err"); return; }
|
| 114 |
if (pending) pending.abort();
|
| 115 |
pending = new AbortController();
|
| 116 |
const button = $("f").querySelector("button");
|
| 117 |
-
button.disabled = true; $("out").
|
| 118 |
status("Reading the dataset…", "load");
|
| 119 |
try {
|
| 120 |
const r = await fetch("api/predict", {method: "POST", headers: {"Content-Type": "application/json"},
|
|
@@ -122,7 +122,6 @@ async function run(id){
|
|
| 122 |
let body = null;
|
| 123 |
try { body = await r.json(); } catch (_) {}
|
| 124 |
if (!r.ok) {
|
| 125 |
-
$("out").classList.remove("stale");
|
| 126 |
status(body && body.message ? body.message
|
| 127 |
: `Something went wrong on the server (status ${r.status}). Try again in a minute.`, "err");
|
| 128 |
return;
|
|
@@ -131,7 +130,6 @@ async function run(id){
|
|
| 131 |
show(body);
|
| 132 |
} catch (e) {
|
| 133 |
if (e.name === "AbortError") return;
|
| 134 |
-
$("out").classList.remove("stale");
|
| 135 |
status("Could not reach the server. Check your connection and try again.", "err");
|
| 136 |
} finally {
|
| 137 |
button.disabled = false;
|
|
@@ -140,7 +138,6 @@ async function run(id){
|
|
| 140 |
$("ex").innerHTML = EXAMPLES.map((id,i) => `<button type="button" data-i="${i}">${id.length > 40 ? id.slice(0,38) + "…" : id}</button>`).join("");
|
| 141 |
$("ex").onclick = e => { const i = e.target.dataset.i; if (i !== undefined) { $("q").value = EXAMPLES[i]; run(EXAMPLES[i]); } };
|
| 142 |
$("f").onsubmit = e => { e.preventDefault(); run($("q").value); };
|
| 143 |
-
$("q").value = EXAMPLES[0]; run(EXAMPLES[0]);
|
| 144 |
</script>
|
| 145 |
</body>
|
| 146 |
</html>
|
|
|
|
| 44 |
.viewer iframe{width:100%;height:520px;border:1px solid var(--rule);border-radius:10px;background:#fff}
|
| 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>
|
|
|
|
| 91 |
function pct(p){ return p < 0.001 ? "<0.1%" : (p*100).toFixed(p < 0.1 ? 1 : 0) + "%"; }
|
| 92 |
function status(text, kind){ $("status").textContent = text; $("status").className = "status " + (kind || ""); }
|
| 93 |
function show(ex){
|
| 94 |
+
$("out").hidden = false; $("q").value = ex.dataset_id;
|
| 95 |
$("name").textContent = ex.dataset_id;
|
| 96 |
$("card").href = "https://huggingface.co/datasets/" + ex.dataset_id;
|
| 97 |
const declared = new Set(ex.declared), inSet = new Set(ex.set);
|
|
|
|
| 110 |
let pending = null;
|
| 111 |
async function run(id){
|
| 112 |
id = id.trim();
|
| 113 |
+
if (!id) { $("out").hidden = true; status("Paste a dataset id first, for example " + EXAMPLES[0] + ".", "err"); return; }
|
| 114 |
if (pending) pending.abort();
|
| 115 |
pending = new AbortController();
|
| 116 |
const button = $("f").querySelector("button");
|
| 117 |
+
button.disabled = true; $("out").hidden = true;
|
| 118 |
status("Reading the dataset…", "load");
|
| 119 |
try {
|
| 120 |
const r = await fetch("api/predict", {method: "POST", headers: {"Content-Type": "application/json"},
|
|
|
|
| 122 |
let body = null;
|
| 123 |
try { body = await r.json(); } catch (_) {}
|
| 124 |
if (!r.ok) {
|
|
|
|
| 125 |
status(body && body.message ? body.message
|
| 126 |
: `Something went wrong on the server (status ${r.status}). Try again in a minute.`, "err");
|
| 127 |
return;
|
|
|
|
| 130 |
show(body);
|
| 131 |
} catch (e) {
|
| 132 |
if (e.name === "AbortError") return;
|
|
|
|
| 133 |
status("Could not reach the server. Check your connection and try again.", "err");
|
| 134 |
} finally {
|
| 135 |
button.disabled = false;
|
|
|
|
| 138 |
$("ex").innerHTML = EXAMPLES.map((id,i) => `<button type="button" data-i="${i}">${id.length > 40 ? id.slice(0,38) + "…" : id}</button>`).join("");
|
| 139 |
$("ex").onclick = e => { const i = e.target.dataset.i; if (i !== undefined) { $("q").value = EXAMPLES[i]; run(EXAMPLES[i]); } };
|
| 140 |
$("f").onsubmit = e => { e.preventDefault(); run($("q").value); };
|
|
|
|
| 141 |
</script>
|
| 142 |
</body>
|
| 143 |
</html>
|