/* WR92 Course EN / 中文 one-click localization. No models, GPU or network calls. The original student lab's DOM and its event listeners are preserved. */ (() => { "use strict"; const dictionary = {"WR92 Course · Related learning spaces / 课程联动":"WR92 Course · 教学实验室联动","WR92 Course · Related learning spaces":"WR92 Course · 课程实验室","Object Detection":"目标检测","Image Generation Lab":"图像生成实验室","SDXL Turbo · GPU":"SDXL Turbo · 实时生成","SANA-Sprint · GPU":"SANA-Sprint · 实时生成","No HF GPU needed · 不消耗 HF GPU":"本页不消耗 Hugging Face GPU","No Hugging Face GPU needed":"本页不消耗 Hugging Face GPU","Object detection runs in your browser. Hugging Face ZeroGPU minutes and image-generation call caps do NOT apply here. Your device, model downloads, network, and platform availability can still limit usage. / 目标检测在浏览器本地执行;无 HF ZeroGPU 每日分钟或生成次数限制,但受设备、下载与网络影响。":"目标检测在你自己的浏览器中运行,不调用 Hugging Face ZeroGPU,因此不受 ZeroGPU GPU 分钟或生成次数限制;但设备性能、模型下载、网络及平台服务仍可能影响体验。","Object detection runs in your browser. Hugging Face ZeroGPU minutes and image-generation call caps do NOT apply here. Your device, model downloads, network, and platform availability can still limit usage.":"目标检测在你自己的浏览器中运行,不调用 Hugging Face ZeroGPU,因此不受 ZeroGPU GPU 分钟或生成次数限制;但设备性能、模型下载、网络及平台服务仍可能影响体验。","HF ZeroGPU policy ↗":"HF ZeroGPU 官方说明 ↗","Building your own AI mini app?":"想制作自己的 AI 小应用?","How to Start":"入门指南","Image Generation":"图像生成","Creative Technology · Computer Vision":"创意科技 · 计算机视觉","AI-Powered":"AI 驱动的","Pick a COCO example or upload your own image. Then choose a pretrained detector and let AI answer:":"选择一张 COCO 示例图片或上传自己的照片,再选择一个预训练检测模型,让 AI 回答:","what objects are here, and where are they?":"图中有哪些物体?它们位于哪里?","Task":"任务","Object detection":"目标检测","Data":"数据","COCO validation examples":"COCO 验证集示例","Models":"模型","Choose an image":"选择图片","Start with a tested COCO example, or try a photo of your own.":"可以先用已验证的 COCO 示例,也可以上传自己的照片。","Start here · COCO examples":"从这里开始 · COCO 示例","Four images are drawn at random from 100 bundled COCO validation examples.":"从内置的 100 张 COCO 验证集图片中随机显示四张。","Shuffle":"随机换图","or try your own":"或者试试自己的图片","Upload an image":"上传图片","Useful for seeing where the model generalizes well—and where it does not.":"观察模型在哪些图片上表现良好、又会在哪些情况下失败。","Choose detector":"选择检测模型","RT-DETR is the recommended classroom default.":"课堂演示建议先选择 RT-DETR。","Confidence threshold":"置信度阈值","Higher values only keep predictions the model is more confident about.":"阈值越高,只保留模型更有把握的预测。","Run AI Detection":"运行目标检测","Choose a COCO example or upload your own image.":"请选择 COCO 示例或上传图片。","AI prediction":"AI 预测结果","What did the detector find?":"检测模型找到了什么?","Waiting":"等待开始","Choose an image first. The original image appears here before detection.":"先选择图片,检测前会在这里显示原图。","No detections yet.":"尚无检测结果。","Object":"物体","Confidence":"置信度","Bounding box":"边界框","Run the detector to see details.":"运行目标检测后在这里查看结果。","What you are doing":"你正在完成的任务","Use a learned AI capability instead of rebuilding the traditional task from scratch.":"调用已经学会目标检测的预训练模型,无需从零训练。","COCO contains everyday-object images with annotations. The selected pretrained detector has already learned the object-detection task from labeled data. In this mini-lab, you can switch models and compare how their predictions differ on the same image.":"COCO 包含带有标注的日常物体图片。这里使用已经通过有标签数据训练的模型,你可以固定同一张图片、切换不同检测模型,观察预测结果的差异。","COCO example or your image":"COCO 示例或你的图片","Selected pretrained detector":"已选的预训练模型","Boxes + labels + confidence":"位置框 + 类别标签 + 置信度","Compare models:":"比较不同模型:","keep the image fixed, switch detector, and observe how predictions, confidence, and speed change.":"保持图片不变,切换检测模型,观察预测内容、置信度与速度如何变化。","Hosted as a Hugging Face Static Space · Powered by Transformers.js":"使用 Hugging Face Static Space 托管 · 基于 Transformers.js","Bedroom furniture":"卧室家具","Kitchen objects":"厨房物品","Cats & remotes":"猫和遥控器","Cake & person":"蛋糕和人物","Skate park":"滑板场","Double-decker buses":"双层巴士","Snowboarder":"单板滑雪者","Bathroom sink & toilet":"浴室洗手池与马桶","Bike & traffic":"自行车与交通","Herd & person":"动物群与人物","Cat & dog at home":"家里的猫与狗","Surfer":"冲浪者","Dining table":"餐桌","Street scene":"街景","Packed suitcase":"装满的行李箱","Person & cell phone":"人物与手机","Bathroom objects":"浴室物品","Busy kitchen":"繁忙的厨房","Bananas at market":"市场上的香蕉","Horses & riders":"马与骑手","Passenger train":"旅客列车","Skateboarder":"滑板运动员","Airplane landing":"飞机降落","Boat at the beach":"海边的小船","Could not read that image.":"无法读取这张图片。","Loading sample":"正在加载样例","COCO val2017":"COCO 验证集 2017","Could not load that COCO example. Try another one.":"无法加载该 COCO 示例,请更换图片。","No objects passed the current confidence threshold.":"没有物体通过当前置信度阈值。","Please choose an image file.":"请选择图片文件。","Model ready":"模型已就绪","Preparing model":"正在准备模型","Loading model":"正在加载模型","Recommended classroom default: modern real-time transformer-style detector.":"课堂推荐的默认模型:采用现代 Transformer 架构的实时检测器。","Representative DETR-family detector. Larger download; useful for comparison.":"典型 DETR 系列模型,下载文件较大,适合对照不同架构。","Small browser-friendly detector. Useful for showing that model choice changes results.":"适合浏览器运行的小型检测模型,可观察选择不同模型如何影响结果。","Image ready":"图片已就绪","Image error":"图片出错","Selected image ready":"已选择图片"}; const normalized = s => String(s).trim().replace(/\s+/g, " "); const enToZh = new Map(Object.entries(dictionary)); const zhToEn = new Map(Object.entries(dictionary).map(([en, zh]) => [zh, en])); const originalText = new WeakMap(), lastPainted = new WeakMap(); const attrOriginal = new WeakMap(), attrPainted = new WeakMap(); const localeKey = "wr92-course-" + "det" + "-locale"; const buttons = Array.from(document.querySelectorAll("[data-wr92-lang]")); const controls = ["alt","title","placeholder","aria-label"]; let locale = "en", scheduled = false; function translateDynamic(en) { if (enToZh.has(en)) return enToZh.get(en); const statusPrefixes = [ [/^Loading COCO example: (.+)…$/, "正在加载 COCO 示例:$1…"], [/^Downloading model: (.+)$/, "正在下载模型文件:$1"], [/^Model changed to (.+)\. Run again to compare results\.$/, "已切换到 $1,请重新运行以便比较结果。"], [/^Loading (.+)$/, "正在加载 $1"], [/^Preparing (.+)\. The first run may download model files\.$/, "正在准备 $1,首次运行可能下载模型文件。"], [/^Done in (.+)s with (.+)\. Change model or threshold to compare\.$/, "$2 检测完成,用时 $1 秒。可切换模型或阈值进行比较。"], [/^(.+) failed to run\. Check your connection or switch back to RT-DETR\.$/, "$1 运行失败,请检查网络或切回 RT-DETR。"], [/^(.+): no detections\. Try a lower threshold or another image\.$/, "$1 未检测到物体,可降低阈值或更换图片。"], [/^(.+) found — (.+)$/, "$1 检测到:$2"] ]; for (const [re, target] of statusPrefixes) if (re.test(en)) return en.replace(re, target); return en; } function paintText(node) { const element = node.parentElement; if (!element || element.closest("script,style,textarea,[data-wr92-lang],.wr92-language-toolbar")) return; const current = node.nodeValue || ""; if (!current.trim()) return; let raw = originalText.get(node); if (raw === undefined || current !== lastPainted.get(node)) { // Another application script may replace status/results; store the // new raw value instead of rewriting the experiment's original data. raw = current; originalText.set(node, raw); } const key = normalized(raw); let translation; if (locale === "zh") { translation = translateDynamic(key); } else { translation = zhToEn.get(key) || key; } // Preserve the original node's whitespace around the user-facing phrase. if (key === translation) { lastPainted.set(node, current); return; } const front = raw.match(/^\s*/)?.[0] || ""; const back = raw.match(/\s*$/)?.[0] || ""; const output = front + translation + back; lastPainted.set(node, output); if (current !== output) node.nodeValue = output; } function paintAttributes(el) { if (!el || !el.attributes || el.closest(".wr92-language-toolbar")) return; let seen = attrOriginal.get(el) || {}, painted = attrPainted.get(el) || {}; for (const key of controls) { if (!el.hasAttribute(key)) continue; const current = el.getAttribute(key); if (seen[key] === undefined || current !== painted[key]) seen[key] = current; const raw = normalized(seen[key]); const next = locale === "zh" ? translateDynamic(raw) : (zhToEn.get(raw) || raw); painted[key] = next; if (current !== next) el.setAttribute(key, next); } attrOriginal.set(el, seen); attrPainted.set(el, painted); } function paintAll() { scheduled = false; const root = document.body; const tw = document.createTreeWalker(root, NodeFilter.SHOW_TEXT); let node; while ((node = tw.nextNode())) paintText(node); for (const el of root.querySelectorAll("[alt],[title],[placeholder],[aria-label]")) paintAttributes(el); document.documentElement.lang = locale === "zh" ? "zh-CN" : "en"; document.title = locale === "zh" ? "AI 目标检测 · WR92 Course" : "AI-Powered Object Detection"; for (const button of buttons) { button.disabled = false; button.setAttribute("aria-pressed", String(button.dataset.wr92Lang === locale)); } } function schedulePaint() { if (!scheduled) { scheduled = true; requestAnimationFrame(paintAll); } } const observer = new MutationObserver(() => schedulePaint()); observer.observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: controls, }); for (const button of buttons) { button.addEventListener("click", () => { locale = button.dataset.wr92Lang === "zh" ? "zh" : "en"; try { localStorage.setItem(localeKey, locale); } catch (_) { /* Private browsing retains current page switch. */ } schedulePaint(); }); } try { if (localStorage.getItem(localeKey) === "zh") locale = "zh"; } catch (_) { /* No persisted data: English default. */ } paintAll(); })();