Spaces:
Paused
Paused
Upload 25 files
Browse filesFiles changed (3)
- README.md+8-6
- START_HERE.txt+3-2
- floating_tutor.py+149-11
54 unmodified lines55565758596061626364 unmodified lines12812913013113213313413513613754 unmodified lineshandwritten image;- a deterministic local tutor for core explanations and image/OCR checking,with an optional conversational AI tutor when `OPENAI_API_KEY` is configured;- a persistent bottom-right **Ask Tutor** popup on the first page and every tab;it opens over the current page without changing tabs, keeps its own compactmission-linked conversation, and hyperlinks to the full multimodal tutor;- a classroom worksheet generator with teacher solutions in Markdown, editableWord, and print-ready PDF formats.64 unmodified lines### Mechanics Tutor ChatThe bottom-right **Ask Tutor** button is available on Mission Control and everyother tab. It opens a separate compact text-tutor box over the current page, sothe learner can ask for a first hint, equation choice, or custom clarificationwithout leaving the experiment or worksheet. The compact chat has its ownconversation and follows the current generated mission. Select **Open fullmultimodal tutor ↗** inside the popup only when voice or image input is needed;that explicit link opens the existing Mechanics Tutor Chat tab in the same54 unmodified lines5556575859606162636464 unmodified lines12913013113213313413513613713813954 unmodified lineshandwritten image;- a deterministic local tutor for core explanations and image/OCR checking,with an optional conversational AI tutor when `OPENAI_API_KEY` is configured;- a persistent, draggable **Ask Tutor** control on the first page and every tab;it floats in the current viewport, opens over the current page withoutchanging tabs, keeps its own compact mission-linked conversation, andhyperlinks to the full multimodal tutor;- a classroom worksheet generator with teacher solutions in Markdown, editableWord, and print-ready PDF formats.64 unmodified lines### Mechanics Tutor ChatThe floating **Ask Tutor** button is available on Mission Control and everyother tab. Click it to open a separate compact text-tutor box over the current page, sothe learner can ask for a first hint, equation choice, or custom clarificationwithout leaving the experiment or worksheet. Drag the button to any convenientviewport position; the browser remembers its position. The compact chat has its ownconversation and follows the current generated mission. Select **Open fullmultimodal tutor ↗** inside the popup only when voice or image input is needed;that explicit link opens the existing Mechanics Tutor Chat tab in the same
40 unmodified lines414243444546474840 unmodified linesMECHANICS TUTOR CHAT--------------------The "Ask Tutor" button remains at the bottom right of the first page and everytab. It opens a separate compact chat box without changing the current tab.Use "Open full multimodal tutor" inside that box to move to the existing fullvoice/image tutor only when required.40 unmodified lines41424344454647484940 unmodified linesMECHANICS TUTOR CHAT--------------------The "Ask Tutor" button floats over the first page and every tab. Click it toopen a separate compact chat box without changing the current tab. Drag thebutton to any convenient position in the browser window; its position is saved.Use "Open full multimodal tutor" inside that box to move to the existing fullvoice/image tutor only when required.
12346 unmodified lines1112131415161720 unmodified lines383940414243444 unmodified lines4950515253545516 unmodified lines72737475767778798081822 unmodified lines85868788899059 unmodified lines1501511521531541551561571581591605 unmodified lines16616716816917017117217317417517617717817918018118218318418518618718818919019119219319413 unmodified lines208209210211212213"""Persistent bottom-right launcher for the compact mechanics tutor."""from __future__ import annotations6 unmodified linesaria-controls="floating-tutor-panel"aria-expanded="false"aria-label="Open the floating mechanics tutor"><span class="floating-tutor-icon" aria-hidden="true">💬</span><span>Ask Tutor</span></button>20 unmodified linesbackground: linear-gradient(110deg, #6d28d9, #db2777);border: 1px solid rgba(255, 255, 255, .45);border-radius: 999px;bottom: 22px;box-shadow: 0 14px 34px rgba(76, 29, 149, .34);color: white;cursor: pointer;4 unmodified linespadding: 11px 17px 11px 12px;position: fixed;right: 22px;transition: transform .18s ease, box-shadow .18s ease;z-index: 1001;}.floating-tutor-launcher:hover {16 unmodified linesjustify-content: center;width: 30px;}#floating-tutor-panel {background: rgba(255, 255, 255, .98) !important;border: 1px solid rgba(109, 40, 217, .22) !important;border-radius: 22px !important;bottom: 82px;box-shadow: 0 24px 68px rgba(30, 41, 59, .3) !important;display: none;max-height: calc(100vh - 108px);2 unmodified linespadding: 14px !important;position: fixed;right: 22px;width: min(410px, calc(100vw - 28px));z-index: 1000;}59 unmodified lines#floating-tutor-panel .floating-tutor-chat { min-height: 235px; }#floating-tutor-panel .floating-tutor-status { font-size: 10px; margin: 0; }@media (max-width: 520px) {.floating-tutor-launcher { bottom: 13px; right: 13px; }#floating-tutor-panel {bottom: 75px;max-height: calc(100vh - 88px);right: 12px;width: calc(100vw - 24px);}}5 unmodified linesFLOATING_TUTOR_LAUNCHER_JS = r"""const openButton = element.querySelector("[data-floating-tutor-open]");const panel = document.getElementById("floating-tutor-panel");if (openButton && panel) {openButton.addEventListener("click", () => {const willOpen = !panel.classList.contains("is-open");panel.classList.toggle("is-open", willOpen);openButton.setAttribute("aria-expanded", String(willOpen));if (willOpen) {const input = panel.querySelector("textarea");window.setTimeout(() => input && input.focus(), 80);}});}"""FLOATING_TUTOR_HEADER_JS = r"""const panel = document.getElementById("floating-tutor-panel");const launcher = document.querySelector("[data-floating-tutor-open]");const closeButton = element.querySelector("[data-floating-tutor-close]");const fullTutorLink = element.querySelector("[data-floating-tutor-full]");function closeFloatingTutor() {if (panel) panel.classList.remove("is-open");if (launcher) launcher.setAttribute("aria-expanded", "false");}13 unmodified lines}document.addEventListener("keydown", (event) => {if (event.key === "Escape" && panel?.classList.contains("is-open")) {closeFloatingTutor();launcher?.focus();12346 unmodified lines11121314151617181920 unmodified lines404142434445464 unmodified lines515253545556575859606116 unmodified lines787980818283848586878889909192939495969798991002 unmodified lines10310410510610710810959 unmodified lines1691701711721731741751761771781791805 unmodified lines18618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933013 unmodified lines344345346347348349350351"""Persistent draggable viewport launcher for the compact mechanics tutor."""from __future__ import annotations6 unmodified linesaria-controls="floating-tutor-panel"aria-expanded="false"aria-label="Open the floating mechanics tutor"title="Click to open · drag to move"><span class="floating-tutor-grip" aria-hidden="true">⠿</span><span class="floating-tutor-icon" aria-hidden="true">💬</span><span>Ask Tutor</span></button>20 unmodified linesbackground: linear-gradient(110deg, #6d28d9, #db2777);border: 1px solid rgba(255, 255, 255, .45);border-radius: 999px;bottom: auto;box-shadow: 0 14px 34px rgba(76, 29, 149, .34);color: white;cursor: pointer;4 unmodified linespadding: 11px 17px 11px 12px;position: fixed;right: 22px;top: 40vh;touch-action: none;transition: transform .18s ease, box-shadow .18s ease;user-select: none;-webkit-user-select: none;z-index: 1001;}.floating-tutor-launcher:hover {16 unmodified linesjustify-content: center;width: 30px;}.floating-tutor-grip {color: rgba(255, 255, 255, .76);cursor: grab;font-size: 16px;line-height: 1;margin-right: -3px;}.floating-tutor-launcher.is-dragging {cursor: grabbing;transition: none;}.floating-tutor-launcher.is-dragging .floating-tutor-grip { cursor: grabbing; }#floating-tutor-panel {background: rgba(255, 255, 255, .98) !important;border: 1px solid rgba(109, 40, 217, .22) !important;border-radius: 22px !important;bottom: auto;box-shadow: 0 24px 68px rgba(30, 41, 59, .3) !important;display: none;max-height: calc(100vh - 108px);2 unmodified linespadding: 14px !important;position: fixed;right: 22px;top: 72px;width: min(410px, calc(100vw - 28px));z-index: 1000;}59 unmodified lines#floating-tutor-panel .floating-tutor-chat { min-height: 235px; }#floating-tutor-panel .floating-tutor-status { font-size: 10px; margin: 0; }@media (max-width: 520px) {.floating-tutor-launcher { right: 13px; top: 34vh; }#floating-tutor-panel {bottom: auto;max-height: calc(100vh - 88px);right: 12px;top: 44px;width: calc(100vw - 24px);}}5 unmodified linesFLOATING_TUTOR_LAUNCHER_JS = r"""const positionKey = "m1-floating-tutor-position-v2";function currentPanel() {// The panel can mount after this HTML component in Gradio. Resolve it only// when an interaction occurs instead of capturing a missing element.return document.getElementById("floating-tutor-panel");}function clamp(value, minimum, maximum) {return Math.min(Math.max(value, minimum), Math.max(minimum, maximum));}function placePanelBeside(button, panel) {window.requestAnimationFrame(() => {const buttonRect = button.getBoundingClientRect();const panelRect = panel.getBoundingClientRect();const gap = 12;let left = buttonRect.left - panelRect.width - gap;if (left < gap) left = buttonRect.right + gap;left = clamp(left, gap, window.innerWidth - panelRect.width - gap);const top = clamp(buttonRect.top, gap, window.innerHeight - panelRect.height - gap);panel.style.left = `${left}px`;panel.style.top = `${top}px`;panel.style.right = "auto";panel.style.bottom = "auto";});}const openButton = element.querySelector("[data-floating-tutor-open]");if (openButton && element.dataset.floatingTutorReady !== "true") {element.dataset.floatingTutorReady = "true";let pointerStart = null;let skipNextClick = false;try {const saved = JSON.parse(window.localStorage.getItem(positionKey) || "null");if (saved && Number.isFinite(saved.left) && Number.isFinite(saved.top)) {openButton.style.left = `${clamp(saved.left, 8, window.innerWidth - openButton.offsetWidth - 8)}px`;openButton.style.top = `${clamp(saved.top, 8, window.innerHeight - openButton.offsetHeight - 8)}px`;openButton.style.right = "auto";openButton.style.bottom = "auto";}} catch (error) {// Storage can be disabled by the browser; the viewport default still works.}openButton.addEventListener("pointerdown", (event) => {if (event.button !== 0) return;const rect = openButton.getBoundingClientRect();pointerStart = {id: event.pointerId,x: event.clientX,y: event.clientY,left: rect.left,top: rect.top,dragging: false,};openButton.setPointerCapture?.(event.pointerId);});openButton.addEventListener("pointermove", (event) => {if (!pointerStart || event.pointerId !== pointerStart.id) return;const dx = event.clientX - pointerStart.x;const dy = event.clientY - pointerStart.y;if (!pointerStart.dragging && Math.hypot(dx, dy) < 6) return;pointerStart.dragging = true;openButton.classList.add("is-dragging");const left = clamp(pointerStart.left + dx, 8, window.innerWidth - openButton.offsetWidth - 8);const top = clamp(pointerStart.top + dy, 8, window.innerHeight - openButton.offsetHeight - 8);openButton.style.left = `${left}px`;openButton.style.top = `${top}px`;openButton.style.right = "auto";openButton.style.bottom = "auto";const panel = currentPanel();if (panel?.classList.contains("is-open")) placePanelBeside(openButton, panel);});function finishDrag(event) {if (!pointerStart || event.pointerId !== pointerStart.id) return;if (pointerStart.dragging) {skipNextClick = true;const rect = openButton.getBoundingClientRect();try {window.localStorage.setItem(positionKey, JSON.stringify({left: rect.left, top: rect.top}));} catch (error) {// The floating control works even when browser storage is unavailable.}}openButton.classList.remove("is-dragging");openButton.releasePointerCapture?.(event.pointerId);pointerStart = null;}openButton.addEventListener("pointerup", finishDrag);openButton.addEventListener("pointercancel", finishDrag);// Delegate the click through this component and look up the panel now. This// remains reliable regardless of the order in which Gradio mounts siblings.element.addEventListener("click", (event) => {const target = event.target.closest?.("[data-floating-tutor-open]");if (!target || !element.contains(target)) return;if (skipNextClick) {skipNextClick = false;event.preventDefault();return;}const panel = currentPanel();if (!panel) return;const willOpen = !panel.classList.contains("is-open");panel.classList.toggle("is-open", willOpen);openButton.setAttribute("aria-expanded", String(willOpen));if (willOpen) {placePanelBeside(openButton, panel);const input = panel.querySelector("textarea");window.setTimeout(() => input && input.focus(), 120);}});window.addEventListener("resize", () => {const rect = openButton.getBoundingClientRect();const left = clamp(rect.left, 8, window.innerWidth - openButton.offsetWidth - 8);const top = clamp(rect.top, 8, window.innerHeight - openButton.offsetHeight - 8);openButton.style.left = `${left}px`;openButton.style.top = `${top}px`;openButton.style.right = "auto";openButton.style.bottom = "auto";const panel = currentPanel();if (panel?.classList.contains("is-open")) placePanelBeside(openButton, panel);});}"""FLOATING_TUTOR_HEADER_JS = r"""const closeButton = element.querySelector("[data-floating-tutor-close]");const fullTutorLink = element.querySelector("[data-floating-tutor-full]");function closeFloatingTutor() {const panel = document.getElementById("floating-tutor-panel");const launcher = document.querySelector("[data-floating-tutor-open]");if (panel) panel.classList.remove("is-open");if (launcher) launcher.setAttribute("aria-expanded", "false");}13 unmodified lines}document.addEventListener("keydown", (event) => {const panel = document.getElementById("floating-tutor-panel");const launcher = document.querySelector("[data-floating-tutor-open]");if (event.key === "Escape" && panel?.classList.contains("is-open")) {closeFloatingTutor();launcher?.focus();
README.md+8-6
START_HERE.txt+3-2
floating_tutor.py+149-11