Spaces:
Running
Running
A newer version of the Gradio SDK is available: 6.20.0
AGENTS.md
Project Overview
Snap2Sim / Inside the Machine is a Build Small Hackathon Backyard AI project for curious tinkerers and makers. The app is intended to accept a photo of a hardware component, infer its internal mechanism, and render an annotated technical cutaway animation.
Commit Instructions
- When Codex creates a git commit in this repository, include this trailer in
the commit message:
Co-authored-by: OpenAI Codex <codex@openai.com> - Do not rewrite already-pushed public history only to add a co-author trailer unless the user explicitly asks for that history rewrite.
Runtime Notes
- Preferred model path:
unsloth/NVIDIA-Nemotron-3-Nano-Omni-30B-A3B-Reasoning-GGUFthrough llama.cpp. - Verification note from June 13, 2026: the Unsloth GGUF repo lists
mmprojfiles and llama.cpp usage instructions. Modal GPU smoke testing confirms the selectedUD-Q4_K_MGGUF andmmproj-F16.ggufwork withllama-mtmd-cliimage input. - Fallback model path:
nvidia/Nemotron-3-Nano-Omni-30B-A3B-Reasoning-NVFP4through Transformers/custom code for the vision step if GGUF endpoint quality is not reliable enough for the demo. - Local code serves a trusted
index.htmlthroughgradio.Serverand exposes/analyze_imageplus/generate_scene. The final public Space isbuild-small-hackathon/Snap2Simathttps://build-small-hackathon-snap2sim.hf.space; any new code changes still need the normal GitHub-to-HF sync and deployment verification. - Scene rendering is deterministic browser-side Three.js from the validated analysis JSON. Do not reintroduce model-authored HTML scene injection.
- Endpoint naming is
generate_sceneeverywhere in active code. - Bonus claims after Modal deployment: Llama Champion confirmed, NVIDIA Nemotron Quest confirmed, Off-Brand confirmed, Modal Award confirmed. Do not claim Off the Grid unless the final deployment moves inference to ZeroGPU or another non-cloud-API path that satisfies that bonus.
Project Structure
prompts/- archived build prompts and Codex task specs.docs/- implementation notes, review passes, and representative fixtures.README.md- quickstart, runtime decision, and repo map.SECURITY.md- public deployment data handling rules for humans and agents..env.example- public Hugging Face Space / local demo variables..hfignore- excludes local credentials, caches, GGUF files, and artifacts from Hugging Face uploads..github/workflows/sync_to_hf.yml- GitHub Actions workflow that syncs GitHubmainto an existing Hugging Face Space.requirements.txt- Python dependencies for the Gradio Space and Modal scaffold.app.py- Hugging Face Space entry point usinggradio.Server; servesindex.htmlat/and exposes/analyze_imageplus/generate_scene.index.html- self-contained HTML/CSS/JS shell loaded bygradio.Server; includes Three.js, upload UI, source-photo preview, pipeline orchestration, and deterministic Three.js rendering.modal_app.py- Modal app scaffold with runtime asset caching, a llama.cpp GPU smoke-test function, aruntime_probediagnostic endpoint, and placeholder plus experimental llama.cppanalyze_image/generate_sceneweb endpoints.scripts/verify_runtime_assets.py- Hugging Face metadata preflight for the selected GGUF quant andmmprojfile.snap2sim/__init__.py- package marker.snap2sim/backend.py- backend config, local placeholder inference, Modal HTTP client, and image base64 encoding.snap2sim/prompts.py- prompt template for the vision analysis step.snap2sim/schema.py- structured JSON schema plus a sample mechanism payload.
What Has Been Done
- Read
prompts/PROMPT.mdand implemented the requested initial scaffold. - Added a modular Gradio app with a two-pane technical cutaway / field manual visual direction.
- Added loading/status language and a styled fallback visualization path so the viewport is not blank when Three.js generation is unavailable.
- Added a backend abstraction controlled by
INFERENCE_BACKEND. - Added placeholder Modal endpoints for the two required inference steps.
- Added a Modal Volume-based runtime asset cache helper and runtime probe.
- Added
smoke_test_llamacpp_image, which builds llama.cpp with CUDA on Modal and runs one image prompt throughllama-mtmd-cliusing the selected GGUF andmmproj-F16.gguf. - Confirmed
smoke_test_llamacpp_imagereturns"ok": true. - Confirmed
run_analysis_endpoint_checkreturns a validated mechanism payload from the real llama.cpp analysis task. - Changed runtime asset resolution so endpoint calls use cached Modal Volume
files directly; repeated
Fetching 3 fileslogs were cached Hugging Face metadata checks, not full model downloads. - Added
run_runtime_preflightlocal entrypoint to cache assets and run the GPU smoke test in one Modal command. - Added a local Hugging Face metadata preflight script and confirmed it passes
for
UD-Q4_K_Mplusmmproj-F16.gguf. - Modal is authenticated under the
bigstonks1workspace; use$env:PYTHONIOENCODING='utf-8'; python -m modal ...on Windows to avoid CLI Unicode/charmap errors. - Defined the vision-to-scene JSON schema for parts, geometry hints, and motion.
- Added JSON-schema validation before scene generation.
- Added deterministic Three.js scene generation for local and Modal placeholder mode, so validated payloads render as an animated 3D cutaway before model code-generation is wired in.
- Added model response parsing helpers for JSON analysis payloads and complete HTML documents.
- Added a local coercion fallback for verbose/partial model JSON so the analysis endpoint does not launch a second slow repair generation.
- Added experimental
analyze_image_llamacppand scene-generation Modal GPU endpoints. They are not wired into the Gradio app by default; pointMODAL_ANALYZE_URL/MODAL_GENERATE_URLat them only after the smoke test passes. - Fixed Modal packaging for local
snap2simimports by addingadd_local_python_source("snap2sim")as the final image step for both Modal images. - Added
check_remote_imports;python -m modal run modal_app.py::check_remote_importsnow creates thePythonPackage:snap2simmount and hydrates the web functions withoutModuleNotFoundError. - Added prompt templates for image analysis and Three.js scene generation.
- Deployed
modal_app.pyto Modal athttps://modal.com/apps/bigstonks1/main/deployed/snap2sim-inside-the-machine. - Production endpoint checks passed for
runtime_probe,analyze_image_llamacpp, and deterministic scene generation before the current endpoint rename. - Modal web endpoints are secured with
Authorization: Bearer SNAP2SIM_API_TOKEN; the token lives in Modal secretsnap2sim-api-authand Hugging Face Space secretSNAP2SIM_API_TOKEN. - Verified unauthenticated Modal requests return
401 Unauthorized. - Added
SECURITY.md,.env.example, and.hfignoreso public deployment config is explicit while credentials and runtime caches stay out of uploads. - Added Hugging Face Space metadata to
README.md. - Hugging Face auth is now valid for user
jasondo111. - Uploaded the Space to
jasondo111/Snap2Sim; the Space isRUNNINGoncpu-basicathttps://jasondo111-snap2sim.hf.space. - The Space remains private as of the latest deployment.
- User decision on June 13, 2026: keep the Hugging Face Space private for now. Do not make it public unless the user explicitly asks.
- Removed accidentally uploaded Playwright artifacts/screenshots from the Space
and expanded
.gitignoreso futurehf uploadruns skip them. - Verified the private Space with an authenticated
gradio_clientcall usinghandle_file; the/run_pipelineAPI returnedCUTAWAY READY. - Re-verified
/run_pipelineafter endpoint auth was added; it still returnsCUTAWAY READY. - Added
.github/workflows/sync_to_hf.ymlfor one-way GitHub to Hugging Face Space sync on pushes tomain. The workflow targetsjasondo111/Snap2Simand requires GitHub secretHF_TOKEN. - User reported the GitHub Actions
HF_TOKENsecret has been added. - PR #1 was merged to
main. The first GitHub-to-HF sync run reached the final push step but failed with Hugging Face HTTP429; the workflow was updated to retry that final push with bounded backoff. - The next GitHub Actions sync run succeeded:
https://github.com/Bigstonks1/Snap2Sim/actions/runs/27487136019. - Hugging Face Space
jasondo111/Snap2Simreports SHAd70e374bea16acaa41c322942815d3cb213745f4, matching GitHubmain. prompts/PROMPT.mdwas updated with a new critical path:gradio.Server,index.html, A-Frame model scene generation,generate_scenenaming, and a deterministic Three.js fallback in browser JS.- Documented GitHub as the source of truth:
https://github.com/Bigstonks1/Snap2Sim. Do not edit files directly on the Hugging Face Space; they will be overwritten by the sync workflow. - Added README acknowledgement: built by Jason Do with implementation assistance from OpenAI Codex.
- Updated
README.mdwith local run instructions, runtime preflight, Modal deployment path, and the current runtime decision. - Rewrote
app.pyas agradio.Serverapp with/,/analyze_image, and/generate_sceneroutes. - Added
index.htmlwith upload orchestration, analysis readout, A-Frame scene injection, 3-second blank-scene fallback, play/pause, and deterministic browser-side Three.js fallback. - Renamed active backend and Modal scene generation paths to
generate_scene. - Updated scene-generation prompts and parsing for
<a-scene>...</a-scene>output. - Deleted the legacy Gradio Blocks UI, Python iframe Three.js generator, and SVG fallback modules.
- Local verification passed with FastAPI
TestClient:/returned the HTML shell,/analyze_imagereturned the placeholder analysis, and/generate_scenereturned an<a-scene>block. - Deployed the renamed Modal app on June 14, 2026. Modal now exposes
generate_sceneandgenerate_scene_llamacppweb endpoints. - Updated Hugging Face Space variable
MODAL_GENERATE_URLto the deployedgenerate_sceneendpoint.MODAL_ANALYZE_URLremains pointed at the verifiedanalyze_image_llamacppendpoint. - PR #2 merged to
main; GitHub Actions sync runhttps://github.com/Bigstonks1/Snap2Sim/actions/runs/27492198915completed successfully. - Hugging Face Space
jasondo111/Snap2Simreported SHA9175771c1d3a2e39d7191b24e5729473fdaae0ef, matching GitHubmain, and remained private/running oncpu-basic. - Verified the private Space root with authenticated HTTP on June 14, 2026:
status
200, trustedindex.htmlshell text present. - Verified the private Space endpoint chain with an authenticated image request
on June 14, 2026:
/analyze_imagereturned a validated mechanism payload through the secured Modal bearer-token flow, and/generate_scenereturned an A-Frame<a-scene>block. - Implemented the
docs/reviews/security-hardening.mdsecurity pass on June 14, 2026: Space-layer rate limiting for/analyze_imageand/generate_scene, upload-size caps, PIL decompression-bomb handling, clean image decode errors, unique Modal temp image files with cleanup, and no model-authored scene HTML. - Consolidated rendering on deterministic browser-side Three.js from validated analysis JSON. Removed the A-Frame runtime import, unused Gradio client import, A-Frame scene builder, A-Frame scene prompt, and raw scene parser.
- Updated the UI with source-photo preview, screen-reader live status, lighter muted text, client-side image validation, keyboard-accessible drop zone, a retry affordance, and a disabled initial Play state.
- PR #3 merged to
main; GitHub Actions sync runhttps://github.com/Bigstonks1/Snap2Sim/actions/runs/27495583577completed successfully. - Hugging Face Space
jasondo111/Snap2Simreported SHA62cfa90093cc5d7de8d12dec831210d142c08a9d, matching GitHubmain, and the private root served the trusted Three.js shell. - Verified the private Space endpoint chain after the security pass:
/analyze_imagereturned a validated mechanism payload through the secured Modal bearer-token flow, and/generate_scenereturned{ "renderer": "three", "analysis": ... }with no HTML field. - Implemented the
docs/reviews/interaction-and-fallback-review.mdlocal code pass on June 14, 2026: fixed the label-overlay pointer-events bug that blocked OrbitControls, added bounded camera controls plus Reset view and orbit/zoom hint, changed the source-photo preview to a stable contained image box, added optional normalized per-partannotationfields, addedrender_modescene descriptors, and added a browser-side annotated-photo fallback plus an honest unavailable state. - Updated model prompting/parsing for longer reasoning: prompts may allow
reasoning before the final JSON, parser strips
<think>blocks and prefers the last complete JSON object, and llama.cpp analysis now uses larger token/context/timeout budgets (4096output tokens,8192context,300stimeout at the analysis call site). - Local verification after the
docs/reviews/interaction-and-fallback-review.mdpass: schema/parser checks passed, FastAPITestClientconfirmed/,/analyze_image, and/generate_scene, and browser verification confirmed left-drag orbit, right-drag pan, wheel zoom, mobile canvas event targeting, contained source preview, annotated-photo fallback, and unavailable retry state. - Modal reasoning-budget follow-up on June 14, 2026: an initial
run_analysis_endpoint_checkreturned a generic fallback, so a local-onlyrun_analysis_raw_checkdiagnostic was added. The raw diagnostic showed the model used schema-adjacent fields (radius,height, string axes). The prompt now explicitly requiressizevectors and numeric axis vectors, and coercion preserves common radius/height/length/axis-string mistakes instead of accepting nested JSON fragments as generic fallbacks. After the fix,run_analysis_raw_checkparsed strict JSON successfully in35.12s, andrun_analysis_endpoint_checkreturned a parsed per-imagetargeting reticlepayload at0.7confidence. - User decision after the
docs/reviews/interaction-and-fallback-review.mdpass: use the real Modalanalyze_image_llamacppanalysis path for the demo.INFERENCE_BACKENDnow defaults tomodal;INFERENCE_BACKEND=localis an explicit UI-development sample mode only and should not be used for public submission. - Deployed the updated Modal app after the real-analysis decision on June 14,
- The stable deployment exposes
analyze_image_llamacppwith the latest prompt/parsing/coercion fixes. A lightweight deployedruntime_proberequest without credentials returned401 Unauthorized. Authenticated deployed web verification could not be run from the local shell becauseSNAP2SIM_API_TOKENwas not set locally; use the Hugging Face Space secret or a local secret store for the normal authenticated check.
- The stable deployment exposes
- Committed and pushed
51992f4(Use real Modal analysis path) to GitHubmain. GitHub Actions sync run27509085142completed successfully, and the private Hugging Face Space reported SHA51992f4d9aff7f298fc377791228999e98054579. - Authenticated private Space verification after the real-analysis sync:
root returned
200, a blank tan synthetic image returned the honestunavailablephoto-render state, and the target-like synthetic image returned a real Modal analysis forreticle assemblyat0.7confidence with 4 parts;/generate_scenereturnedrender_mode: threeandrenderer: three. - Implemented the optional visual-polish pass after private deployment verification: component watermark populated from the analysis component name, subtle static noise overlay, stronger viewport vignette, and refined scan-line reveal. Local browser verification confirmed the scene still renders, orbit drag still works, the canvas remains the pointer target, the source preview remains contained, and the mobile layout has no horizontal overflow.
- Implemented the
docs/features/confidence-threshold.mdconfidence-threshold control on June 14, 2026: added a toolbar slider defaulting to0.5, made the browser recompute render mode from cached analysis plus the current slider value, and kept slider changes local with no extra/analyze_imageor/generate_scenecalls. AddedDEFAULT_CONFIDENCE_THRESHOLD = 0.5for the server's advisory fallback. Local verification passed for schema/parser checks, FastAPITestClient, slider downgrade/promote behavior, annotated-photo fallback, keyboard slider operation, mobile no-overflow layout, and canvas pointer targeting. - Committed and pushed
a0540e9(Add confidence threshold control) to GitHubmain. GitHub Actions sync run27515143658completed successfully, and the private Hugging Face Space reported SHAa0540e92f19174f8b828374b201c1da94ef125a4. - Authenticated private Space verification after the confidence-threshold sync:
root returned
200with the slider shell present, a synthetic target image returned real Modal analysis forTarget Reticleat0.7confidence with 3 parts, and/generate_scenereturnedrenderer: three,render_mode: three, and no HTML field. - Implemented the
docs/features/confidence-threshold.mdconfidence-threshold re-spec on June 14, 2026: the slider is enabled before the first upload, sendsconfidence_thresholdonly with/generate_scene, no longer re-renders cached analysis on slider movement, and the server clamps/coerces the threshold before selectingrender_mode. The browser now trusts the server'srender_modeand only downgrades when geometry or annotation data is missing. - Implemented the
docs/features/annotated-photo-fallback.mdfallback pass: fixed portrait and landscape image containment by giving the annotation frame a definite viewport-bounded box, added numbered marker dots, leader lines, and optional annotation bounding boxes, and kept all annotation text rendered throughtextContent. - Implemented the
docs/features/renderer-vocabulary.mdrenderer/prompt vocabulary pass: added deterministiccone,capsule,torus, andspringshapes; addedscrew,orbit, andpulsemotions; raised the usable part cap to 6 across prompt, schema, coercion, and browser renderability; and updated the sample analysis to exercise all four new primitives. - Local verification after the
docs/features/annotated-photo-fallback.md/docs/features/renderer-vocabulary.mdpass: schema and coercion checks passed, FastAPITestClientconfirmed/,/analyze_image, and/generate_scene, browser verification confirmed contained portrait and landscape annotated-photo fallbacks with labels in bounds and no mobile horizontal overflow, and the deterministic Three.js path reachedCUTAWAY READYwith a nonblank six-part scene. - Committed and pushed
682623a(Expand renderer vocabulary and annotation fallback) to GitHubmain. GitHub Actions sync run27518719440completed successfully, and the private Hugging Face Space reported SHA682623a979e351c3fb6d5b5b9ade907c7a979aea. - Deployed the updated Modal app after the
docs/features/annotated-photo-fallback.md/docs/features/renderer-vocabulary.mdpass soanalyze_image_llamacppuses the richer prompt plus expanded schema and coercion. Authenticated private Space verification passed: root returned200with the updated vocabulary shell, a synthetic target image returned a real Modal analysis forpiston mechanismat0.85confidence with 3 parts,/generate_scenereturnedrenderer: three,render_mode: three, and no HTML field, and a high confidence threshold returnedrender_mode: annotate. - Implemented the
docs/features/vision-prompt-roles.mdprompt-role split on June 15, 2026: moved the invariant analysis contract intoVISION_SYSTEM_PROMPT, reducedbuild_vision_prompt()to a backward-compatible per-image user-prompt alias, addedbuild_vision_messages(), and wired Modal llama.cpp analysis calls to pass-syswith a fallback that prepends the system text only if the deployed binary rejects the system-prompt flag. - Verification after the
docs/features/vision-prompt-roles.mdpass: prompt-helper checks, schema/parser/coercion checks, FastAPITestClientchecks for/,/analyze_image, and/generate_scene, and amodal_app.pyimport/helper check all passed locally. Modal dev raw analysis parsed strict JSON in28.59swithcoerced_render_mode: three, and the endpoint-style Modal diagnostic returned a validated two-part mechanism payload. Stable Modal deploy completed on June 15, 2026, and the stable unauthenticatedruntime_proberequest returned401 Unauthorized. - Committed and pushed
f24826e(Split vision prompt roles) to GitHubmain. GitHub Actions sync run27530875972completed successfully, and the private Hugging Face Space reported SHAf24826e7a4f7335cb4310f88c01baef7d8155860. - Authenticated private Space verification after the prompt-role sync: root
returned
200, the trusted shell was present, the synthetic target image returned a real Modal analysis forcutaway mechanismat0.7confidence with 3 parts, and/generate_scenereturnedrenderer: three,render_mode: three, and no HTML field. - Implemented the
docs/reviews/scene-geometry-review.mddeterministic renderer pass on June 15, 2026: axial and disk-like primitives now infer their axis fromgeometry.size, radius comes from the cross-section pair, explicitgeometry.rotationremains additive, the Three.js assembly recenters before reveal animation, camera/OrbitControls fit is derived from the bounding sphere and viewport aspect, the grid moves to the recentered assembly bottom, and label projection uses world positions. Prompt wording now tells the model that the renderer infers primitive orientation from the odd-one-out size dimension. - Local verification after the
docs/reviews/scene-geometry-review.mdpass: prompt/schema imports, schema validation, parser/coercion validation, FastAPITestClientchecks inINFERENCE_BACKEND=local, browser verification fordocs/fixtures/mini-fan-analysis.jsonandEXAMPLE_ANALYSIS, desktop/mobile nonblank screenshots, mobile no-overflow measurement, orbit drag, and Reset view all passed. - Reworked
README.mdfor Build Small judging on June 15, 2026: added judge-facing YAML tags for the Backyard AI track plus Llama Champion, NVIDIA Nemotron Quest, Modal Award, OpenAI Codex, Off-Brand, Best Demo, and Sharing is Caring; shifted the body from a maintainer runbook to a public pitch with concise idea, demo, tech stack, verification, and setup sections; kept private Modal endpoint URLs and credentials out of public docs. - Cleaned up repository notes on June 15, 2026: moved feature specs to
docs/features/, review passes todocs/reviews/, and the mini-fan model output fixture todocs/fixtures/mini-fan-analysis.json; addeddocs/README.mdas an index. - Implemented the
docs/reviews/motion-axis-bias.mdpass on June 15, 2026: de-anchored the vision prompt from[0, 1, 0], added balanced X/Y/Z axis examples and a shaft exemplar, made missing browser-side motion axes derive from the same size-based primitive axis used for geometry orientation, and removed the hard-coded Y axis from the generic fallback rotor. - Verification after the motion-axis pass: schema/parser/coercion checks
passed, FastAPI
TestClientchecks passed inINFERENCE_BACKEND=local, Playwright renderer probes confirmed missing-axis X, Y, and Z parts infer the expected axes with no horizontal overflow, Modal devrun_analysis_endpoint_checkreturned a rotatingdialwithaxis: [1, 0, 0], stable Modal deploy completed, and unauthenticated stableruntime_probestill returned401 Unauthorized. - Committed and pushed
5e65d06(Reduce motion axis bias) to GitHubmain. The first GitHub-to-HF sync failed because the new READMEshort_descriptionexceeded Hugging Face's 60-character metadata limit. Committed and pushede7369eb(Fix Space metadata length), after which GitHub Actions sync run27544185461completed successfully. - Hugging Face Space
jasondo111/Snap2Simreported SHAe7369eb7e22f8e25bbbac95a1531bacf242446cb, remained private, and was running oncpu-basic. Authenticated private Space verification after the motion-axis sync: root returned200with the trusted shell present, the synthetic target image returned real Modal analysis forrotating shaft assemblyat0.65confidence with an emitted motion axis of[1.0, 0.0, 0.0], and/generate_scenereturnedrenderer: three,render_mode: three, and no HTML field. - User made Hugging Face Space
jasondo111/Snap2Simpublic on June 15, 2026. Verification confirmed Hub metadataprivate=false, the public Space page returned200, and the public app hosthttps://jasondo111-snap2sim.hf.spacereturned the trusted shell with the confidence slider present. The Space has not been transferred tobuild-small-hackathon/Snap2Sim; that target repo did not exist at the time of verification. - Public endpoint smoke verification on June 15, 2026 passed:
/generate_scenereturnedrenderer: threewith no HTML field forEXAMPLE_ANALYSIS, and/analyze_imagereturned a real Modal analysis for a synthetic target-like image asrotary indexerat0.6confidence with 3 parts. - Committed and pushed
92853cc(Add hackathon presentation deck) to GitHubmain. GitHub Actions sync run27576590128completed successfully, and the public Hugging Face Space reported SHA92853cc9acf19555524a7f65b189926e9088f4fb. The synced Space includesprompts/PRESENTATION_PROMPT.md,presentation/deck.html, andpresentation/assets/.gitkeep. - User transferred the public Space to
build-small-hackathon/Snap2Simon June 15, 2026. Verification confirmed the org-owned Space is public, running oncpu-basic, and serveshttps://build-small-hackathon-snap2sim.hf.space. The transferred Space kept SHAf4134f7379db5abd0b6b58130da2d677c0fcb218at verification time. - Org-owned Space endpoint smoke verification on June 15, 2026 passed:
/generate_scenereturnedrenderer: three,render_mode: three, and no HTML field forEXAMPLE_ANALYSIS;/analyze_imagereturned a real Modal analysis for a synthetic target-like image asrotary indexing mechanismat0.85confidence with 3 parts. - Final public submission links were added on June 15, 2026:
YouTube demo
https://youtu.be/nuisDKMyyF8and X posthttps://x.com/Ryno67114241/status/2066660199558152411.
Final State / Maintenance Notes
- The Hugging Face Space is now public under
build-small-hackathon/Snap2Sim. Keep README, presentation links, and.github/workflows/sync_to_hf.ymlpointed at that org-owned Space. - The public submission is complete with the app, README, presentation deck, YouTube demo, and X post linked from the repository.
- Keep the README opening hook intact: "You find a small metal cylinder at a flea market. What is it? How does it work inside?" Maintain the judge-facing YAML tags and public pitch if future README updates are needed.