Spaces:
Sleeping
Download docs/multi-frontend.md from JoeTach/cdpr-simulator: direct link, hf CLI and curl.
- Browser
- Download file 7.77 kB
-
https://huggingface.co/spaces/JoeTach/cdpr-simulator/resolve/main/docs/multi-frontend.md
- Command line
-
hf download hf://spaces/JoeTach/cdpr-simulator/docs/multi-frontend.md
-
curl -L -o multi-frontend.md https://huggingface.co/spaces/JoeTach/cdpr-simulator/resolve/main/docs/multi-frontend.md
A newer version of the Gradio SDK is available: 6.32.0
Multi-frontend topology and deployment guide
How the cdpr scientific core feeds multiple coexisting frontends, and how to deploy each.
Topology
ββββββββββββββββββββββββββββββββββββββββ
β cdpr core (Python, NumPy/SciPy) β one source of truth
β src/cdpr/β¦ β 195 tests
ββββββββββββββ¬ββββββββββββββββββββββββββ
β Python import
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
PowerShell / bash CLI FastAPI backend Examples registry
scripts/*.py cdpr.interface.api scripts/examples.py
(run_simulation, (deployed on Render) (5 built-in demos)
train_from_csv,
compare_models,
run_example,
train_interactive.ps1)
β β β
ββββββββββββββββββββββΌβββββββββββββββββββ β
β β β
ββββββββββββββββΌβββββββββ β β
βΌ βΌ βΌ βΌ βΌ
Streamlit (local) Gradio Dash (next) curl all GUIs read
streamlit_app.py gradio_app.py users EXAMPLES from
examples.py
Properties:
- Each frontend imports cdpr directly. No HTTP boundary required between the GUI and the simulator. Each GUI runs the simulator in-process, then renders the artifacts.
- Disk is the shared artifact contract. Every successful run
writes
out/<id>/timeseries.csv,manifest.json,feasibility.json, plus 14 PNGs. Any other frontend can read those. - FastAPI is the optional network boundary. Clients without
Python (curl, mobile, JS) hit
/simulate,/plot,/workspaceinstead of importing. - The examples registry is the only state the GUIs share (via
scripts/examples.py). Adding a new example surfaces it simultaneously in the CLI, Streamlit, and Gradio.
Deployment surfaces
| Surface | What runs there | URL |
|---|---|---|
| GitHub (sources) | All code | github.com/Tachia/cdpr_simulator |
| Render | FastAPI backend (Docker) | cdpr-api.onrender.com |
| Cloudflare Pages | Static docs landing | cdpr-simulator.pages.dev |
| Streamlit Cloud | Streamlit GUI (experimental β see frontend-architecture.md) | cdprsimulator-β¦streamlit.app |
| Hugging Face Spaces | Gradio GUI (recommended) | huggingface.co/spaces//cdpr-simulator |
| Supabase | Postgres + storage (optional) | db.nohbtlhhisfiajjsbguy.supabase.co |
| Local dev box | All of the above (concurrently if desired) | localhost |
How to deploy the new Gradio frontend to Hugging Face Spaces
This is the recommended hosted demonstration URL going forward.
One-time setup
- Make a free account at https://huggingface.co.
- New β Space:
- Owner: your username
- Space name:
cdpr-simulator - License: MIT
- Space SDK: Gradio
- Space hardware: CPU basic (free; 16 GB RAM, 2 vCPU)
- Visibility: Public (or Private if you prefer)
- After creation, get the URL of the form:
https://huggingface.co/spaces/<your-username>/cdpr-simulator.
Upload the files
From your local checkout:
# PowerShell
git remote add space https://huggingface.co/spaces/<your-username>/cdpr-simulator
git push space main
# bash / zsh
git remote add space https://huggingface.co/spaces/<your-username>/cdpr-simulator
git push space main
HF will pick up gradio_app.py and requirements-gradio.txt and
build the Space automatically (3β6 minutes).
What HF needs to find at the repo root
The repo already contains everything required:
gradio_app.py # Gradio app entry-point
requirements-gradio.txt # HF Spaces' pip requirements file
src/cdpr/β¦ # the scientific core (installed by '.' in requirements)
scripts/examples.py # the 5-example registry
scripts/_csv_io.py # shared CSV loader
pyproject.toml # hatchling build descriptor
Verify the deployment
After the Space rebuilds, open its URL. You should see:
- "CDPR Simulator β Gradio frontend" header with the build banner,
- three tabs: Built-in examples, Custom Phase-1 simulation, Upload CSV / Phase-2.
- The example dropdown lists the five built-in demos.
- Clicking Run example on
circleproduces 14 figures (60-100 s on the free CPU Space).
The same UI runs identically against python gradio_app.py on a
local box.
How to run Streamlit locally (the supported Streamlit mode)
streamlit run streamlit_app.py
# open http://localhost:8501
The Streamlit Cloud URL stays live but is now tagged
"experimental" β see docs/frontend-architecture.md for why.
How to drive the FastAPI backend without any GUI
# PowerShell
.\scripts\call_render.ps1 -Action simulate -Kind circle
.\scripts\call_render.ps1 -Action plot -PlotKind cable_tensions -OpenPng
# bash: warm the worker, then simulate
curl -s https://cdpr-api.onrender.com/health
curl -s -X POST https://cdpr-api.onrender.com/simulate \
-H "Content-Type: application/json" \
-d '{"robot":"ipanema_class","duration":1.5,"dt":2e-3,
"trajectory":{"kind":"circle","duration":1.5,
"params":{"center":[0,0,0.5],"radius":0.2,
"axis":[0,0,1],"angle_span":6.283}}}' \
| python -m json.tool | head -40
Running multiple frontends concurrently on the same machine
Three separate terminals:
# Terminal 1 β Streamlit
streamlit run streamlit_app.py # localhost:8501
# Terminal 2 β Gradio
python gradio_app.py # localhost:7860
# Terminal 3 β FastAPI
uvicorn cdpr.interface.api:app --reload --port 8000 # localhost:8000
# Terminal 4 β CLI for everything else
python scripts/run_example.py --list
All four interfaces import the same cdpr package. There is no
state collision because each writes to a unique
out/<id>-<timestamp>/ folder.
Picking the right frontend for the right task
| You want to β¦ | Use β¦ |
|---|---|
| Demo the project to a non-Python audience | Hugging Face Gradio Space |
| Debug your own simulation with full plot interactivity | Streamlit local |
| Sweep 100 simulations programmatically | PowerShell CLI |
| Call from a mobile app or non-Python client | FastAPI on Render |
| Get one quick sim result with bookmarkable settings | Gradio local |
| Compare 5 ML models on uploaded data | Gradio local or CLI |
| Run a long PINN training over lunch | PowerShell CLI |
Cross-references
docs/frontend-architecture.mdβ full architectural assessment + comparison matrixdocs/terminal-execution.mdβ clean-clone-to-running-sim universal guidedocs/examples.mdβ built-in examples registrydocs/csv-schema.mdβ accepted CSV layouts + alias tabledocs/runbook.mdβ operational runbook (pre-Gradio)docs/deployment-status.mdβ current deployment health snapshot