ShadowNS/floorplan
Floorplan Segmentation API
FastAPI backend for the Raster·Vector floorplan vectorizer. Exposes a segmentation endpoint that the Netlify frontend calls to get wall masks and room labels. Runs CubiCasa5K when weights are present, otherwise a built-in OpenCV heuristic (so the Space works out of the box).
Endpoint
POST /segment
{ "image": "<base64 png>" }Response:
{ "wall_mask_png": "<base64>", "room_label_png": "<base64>", "n_labels": 7 }Room ids are encoded in the red channel of room_label_png (0 = background), matching the frontend's decoder.
GET / returns health + whether the model or heuristic is active.
Connect the frontend
In your Netlify site's environment variables, set:
VITE_SEGMENT_API=https://<your-username>-<space-name>.hf.space/segmentRedeploy the frontend; it will route segmentation through this Space.
Lock down CORS in production by setting the ALLOWED_ORIGINS Space secret to your Netlify URL (comma-separated for multiple).
Enabling the real model
The heuristic runs by default. To use CubiCasa5K:
- Add the CubiCasa5k repo's
floortrans/package into this Space. - Upload weights to
model/model_best_val_loss_var.pkl(use Git LFS — it's large). - Uncomment
torch,torchvision,scikit-imageinrequirements.txt. - Set Space variable
USE_MODEL=1. - Restart the Space.
GET /should report"mode": "model".
A free CPU Space runs the heuristic fine; the model is slow on CPU — consider an upgraded CPU or a GPU Space for real inference.
Local run
pip install -r requirements.txt
uvicorn app:app --reload --port 7860
# POST a base64 PNG to http://localhost:7860/segment