Download app.js from LOPATA-AI-Hub/neuroconstructor-study: direct link, hf CLI and curl.
- Browser
- Download file 4.52 kB
-
https://huggingface.co/spaces/LOPATA-AI-Hub/neuroconstructor-study/resolve/main/app.js
- Command line
-
hf download hf://spaces/LOPATA-AI-Hub/neuroconstructor-study/app.js
-
curl -L -o app.js https://huggingface.co/spaces/LOPATA-AI-Hub/neuroconstructor-study/resolve/main/app.js
4.52 kB
| ; | |
| const select = document.querySelector("#task"); | |
| const example = document.querySelector("#example"); | |
| const statusLine = document.querySelector("#status"); | |
| const languages = { | |
| ru: { builds:["Лёгкая", "Средняя", "Тяжёлая"], positions:["сверху слева","сверху справа","снизу слева","снизу справа"], clips:["Первая запись","Вторая запись"], truth:"Правильная ячейка", selected:"выбрана инструкцией", task:"Задание", ok:"верно", error:"ошибка", image:"Экран с четырьмя значками", loadError:"Не удалось загрузить примеры. Обновите страницу." }, | |
| en: { builds:["Light", "Medium", "Heavy"], positions:["top left","top right","bottom left","bottom right"], clips:["First clip","Second clip"], truth:"Correct cell", selected:"selected by the instruction", task:"Task", ok:"correct", error:"wrong", image:"Panel with four icons", loadError:"The examples could not be loaded. Refresh the page to retry." } | |
| }; | |
| const keys = ["light","medium","heavy"]; | |
| let language = navigator.language?.toLowerCase().startsWith("ru") ? "ru" : "en"; | |
| let data; | |
| function node(tag, value, className) { | |
| const el = document.createElement(tag); | |
| if (value !== undefined) el.textContent = value; | |
| if (className) el.className = className; | |
| return el; | |
| } | |
| function renderTask() { | |
| const row = data.tasks[select.selectedIndex]; | |
| const labels = languages[language]; | |
| const panel = document.querySelector("#panel"); | |
| panel.src = "examples/" + row.image; | |
| panel.alt = labels.image + " · " + row.task; | |
| document.querySelector("#truth").textContent = labels.truth + " — " + labels.positions[row.expected]; | |
| document.querySelector("#command").textContent = row.command; | |
| const clips = document.querySelector("#clips"); | |
| const texts = document.querySelector("#transcripts"); | |
| clips.replaceChildren(); | |
| texts.replaceChildren(); | |
| row.audio.forEach((file, index) => { | |
| const entry = data.recordings[file]; | |
| const title = labels.clips[index] + (index === row.order ? " · " + labels.selected : ""); | |
| const player = node("audio"); | |
| player.controls = true; | |
| player.preload = "metadata"; | |
| player.src = "examples/" + file; | |
| player.setAttribute("aria-label",title); | |
| clips.append(node("span",title,"clip"),player); | |
| texts.append(node("p",labels.clips[index] + " — «" + entry.source + "»")); | |
| const list = node("ul"); | |
| keys.forEach((key,i) => { const li=node("li"); li.append(node("b",labels.builds[i] + " — "),node("bdi",entry[key])); list.append(li); }); | |
| texts.append(list); | |
| }); | |
| const table = document.querySelector("#decisions"); | |
| table.replaceChildren(); | |
| keys.forEach((key,i) => { | |
| const tr=node("tr"); | |
| const th=node("th", labels.builds[i]); | |
| th.scope="row"; | |
| tr.append(th); | |
| for (const mode of ["before","after"]) { | |
| const current=row[key][mode]; | |
| const ok=current === row.expected; | |
| const td=node("td",(ok ? "✓ " : "× ") + labels.positions[current],ok ? "correct" : "wrong"); | |
| td.setAttribute("aria-label",(ok ? labels.ok : labels.error) + ", " + labels.positions[current]); | |
| tr.append(td); | |
| } | |
| table.append(tr); | |
| }); | |
| } | |
| function setLanguage(next) { | |
| language = next; | |
| document.documentElement.lang = next; | |
| document.title = next === "ru" ? "Нейроконструктор · LOPATA AI Hub" : "Neuroconstructor · LOPATA AI Hub"; | |
| document.querySelectorAll("[data-ru]").forEach(el => { el.textContent=el.dataset[next]; }); | |
| document.querySelectorAll("[data-lang]").forEach(el => { el.setAttribute("aria-pressed",String(el.dataset.lang===next)); }); | |
| if (data) { | |
| Array.from(select.options).forEach((option,i) => { option.textContent=String(i+1) + " / " + data.tasks.length; }); | |
| renderTask(); | |
| } | |
| } | |
| for (const btn of document.querySelectorAll("[data-lang]")) btn.addEventListener("click",()=>setLanguage(btn.dataset.lang)); | |
| select.addEventListener("change",renderTask); | |
| setLanguage(language); | |
| fetch("data.json").then(async res => { | |
| if (!res.ok) throw new Error(String(res.status)); | |
| data=await res.json(); | |
| data.tasks.forEach(row => { const option=node("option"); option.value=String(row.task); select.append(option); }); | |
| select.value="6"; | |
| select.disabled=false; | |
| example.hidden=false; | |
| statusLine.hidden=true; | |
| setLanguage(language); | |
| }).catch(() => { statusLine.textContent=languages[language].loadError; }); | |