Spaces:
Running
Running
File size: 7,777 Bytes
36f68cc e7369eb 5e65d06 8bd62c1 36f68cc 5e65d06 36f68cc 53f7d61 36f68cc 5e65d06 53f7d61 5e65d06 36f68cc 5e65d06 36f68cc 4755cbc 5e65d06 7006f4b 36f68cc 4755cbc 51992f4 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 7006f4b 5e65d06 92853cc 5e65d06 4755cbc 5e65d06 92853cc 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 53f7d61 5e65d06 53f7d61 5e65d06 53f7d61 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 36f68cc 5e65d06 7006f4b 92853cc 5e65d06 7006f4b 2499b0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | ---
title: Snap2Sim Inside The Machine
sdk: gradio
app_file: app.py
license: mit
colorFrom: blue
colorTo: yellow
short_description: Photograph a part. Get a mechanical cutaway.
models:
- unsloth/NVIDIA-Nemotron-3-Nano-Omni-30B-A3B-Reasoning-GGUF
tags:
- build-small-hackathon
- backyard-ai
- llama-champion
- nvidia-nemotron-quest
- modal-award
- openai-codex
- off-brand
- best-demo
- sharing-is-caring
- llama-cpp
- gguf
- gradio
- three-js
- track:backyard
- sponsor:openai
- sponsor:nvidia
- sponsor:modal
- achievement:offbrand
- achievement:llama
- achievement:sharing
---
# Snap2Sim: Inside the Machine
You find a small metal cylinder at a flea market. What is it? How does it work
inside?
Snap2Sim turns a photo of a hardware component into a narrated mechanical
cutaway. Drop in a picture of a valve, lock, pump, gear train, fan, latch, or
other mystery part; the app identifies the likely mechanism, names the internal
pieces, and renders a moving 3D field-manual view that explains how the object
works.
The goal is not just recognition. It is the moment a curious maker gets to see
the hidden motion: the plunger sliding, the spring loading, the rotor spinning,
the pawl catching, the port opening.
## Demo
- Hugging Face Space: https://huggingface.co/spaces/build-small-hackathon/Snap2Sim
- App host: https://build-small-hackathon-snap2sim.hf.space
- Source of truth: https://github.com/Bigstonks1/Snap2Sim
- Demo video: https://youtu.be/nuisDKMyyF8
- X post: https://x.com/Ryno67114241/status/2066660199558152411
The Space is public for submission under the Build Small Hackathon organization.
The app is built as a Gradio Space with a custom `gradio.Server` shell; GitHub
remains the source of truth for code changes.
## Hackathon Fit
Snap2Sim is a Backyard AI project for people who learn by taking things apart:
garage tinkerers, repair hobbyists, thrift-store scavengers, robotics students,
and anyone holding an unknown part and wondering what is going on inside.
The README metadata tags request consideration for:
| Track or badge | Why it applies |
|---|---|
| Backyard AI | Explains real-world objects from a user's own photo. |
| Llama Champion | Runs the primary model through llama.cpp with GGUF assets. |
| NVIDIA Nemotron Quest | Uses NVIDIA Nemotron 3 Nano Omni as the vision-reasoning model. |
| Modal Award | GPU inference is deployed through Modal with cached model assets. |
| OpenAI Codex | Built with Codex assistance and Codex-attributed commits in the linked GitHub repo. |
| Off-Brand | The experience is a branded maker tool, not a generic chatbot or image demo. |
| Best Demo / Sharing is Caring | Public demo video and X post are linked in the Demo section. |
| Off the Grid | Not claimed while inference runs on Modal. |
## How It Works
1. The browser accepts a component photo and sends it to the Space's same-origin
`/analyze_image` API.
2. The Space calls a secured Modal endpoint running
`unsloth/NVIDIA-Nemotron-3-Nano-Omni-30B-A3B-Reasoning-GGUF` through
llama.cpp and `llama-mtmd-cli`.
3. Nemotron returns a structured mechanism JSON payload: component name,
confidence, internal parts, geometry hints, motion types, annotations, and a
plain-language explanation.
4. `/generate_scene` validates the analysis and chooses the render mode.
5. The browser renders the result with trusted deterministic Three.js code. If a
confident 3D reconstruction is not justified, it falls back to annotated
callouts on the original photo instead of pretending.
The model describes the mechanism. The browser owns the rendering. That keeps
the demo reliable and avoids injecting model-authored HTML or JavaScript into
the page.
## Tech Stack
- Frontend: plain `index.html`, CSS, and JavaScript served directly by
`gradio.Server`.
- Rendering: deterministic Three.js primitives, labels, OrbitControls, camera
fitting, and an annotated-photo fallback.
- Model runtime: NVIDIA Nemotron 3 Nano Omni 30B-A3B GGUF, `UD-Q4_K_M`, with
`mmproj-F16.gguf` through llama.cpp.
- GPU service: Modal, with weights cached in a Modal Volume and bearer-token
protection between the Space and Modal.
- Space runtime: Hugging Face `cpu-basic`; expensive inference happens on Modal.
- Contract: JSON schema validation in `snap2sim/schema.py` before anything is
rendered.
The primary model is approximately 30B total parameters with roughly 3B active
per MoE token, keeping the single-model pipeline under the hackathon's 32B model
budget.
## What Makes It Different
Most image demos stop at a label. Snap2Sim tries to answer the maker's next
question: "what would I see if I cut this open?"
- It produces a mechanism explanation, not just a class name.
- It maps internal parts into a moving technical cutaway.
- It shows uncertainty honestly with a confidence threshold and a photo
annotation fallback.
- It uses a custom public-facing interface instead of a default chat or form UI.
- It keeps secrets and GPU endpoints server-side while the client calls only
same-origin APIs.
## Current Verification
Recent local and deployed checks confirmed:
- The public Space serves the trusted `index.html` shell.
- `/analyze_image` returns validated mechanism payloads through the secured
Modal bearer-token flow.
- A public smoke test on the org-owned Space on June 15, 2026 returned a real
Modal analysis for a synthetic target-like image as `rotary indexing
mechanism` at `0.85` confidence with 3 parts.
- `/generate_scene` returns a deterministic Three.js scene descriptor, not raw
HTML; a public smoke test returned `renderer: three`.
- The renderer handles six-part scenes, axial orientation from geometry sizes,
geometry-aware motion-axis fallback, fitted camera framing, orbit controls,
reset view, mobile layout, and annotated-photo fallbacks.
- Unauthenticated Modal requests return `401 Unauthorized`.
## Run Locally
```powershell
pip install -r requirements.txt
python app.py
```
For UI-only development, set:
```powershell
$env:INFERENCE_BACKEND="local"
python app.py
```
For the real demo path, configure the public variables and private token as
described in `.env.example` and `SECURITY.md`. Do not commit tokens, Modal
endpoint URLs, uploaded user photos, or downloaded model weights.
## Runtime Preflight
Check the selected GGUF and projector metadata before spending GPU time:
```powershell
python scripts/verify_runtime_assets.py
```
Useful Modal checks:
```powershell
python -m modal run modal_app.py::check_remote_imports
python -m modal run modal_app.py::download_runtime_assets
python -m modal run modal_app.py::smoke_test_llamacpp_image
python -m modal run modal_app.py::run_analysis_endpoint_check
```
On Windows, use UTF-8 output when running Modal commands:
```powershell
$env:PYTHONIOENCODING="utf-8"; python -m modal run modal_app.py::run_runtime_preflight
```
## Repository Map
- `app.py` - Gradio Server app, same-origin APIs, image validation, rate limits.
- `index.html` - upload flow, analysis panel, Three.js renderer, fallback UI.
- `modal_app.py` - Modal deployment, llama.cpp runtime, diagnostics.
- `prompts/` - archived original build prompt, GitHub sync prompt, and deck prompt.
- `presentation/deck.html` - reveal.js judging deck for the hackathon pitch.
- `docs/` - implementation notes, review passes, and representative fixtures.
- `snap2sim/backend.py` - backend selection and authenticated Modal client.
- `snap2sim/prompts.py` - vision prompt contract.
- `snap2sim/schema.py` - mechanism JSON schema and sample payload.
- `scripts/verify_runtime_assets.py` - Hugging Face model metadata preflight.
- `SECURITY.md` - public deployment handling rules.
## Acknowledgements
Built by Jason Do with implementation assistance from OpenAI Codex.
|