CoolFace
Apppublic

ShadowNS/floorplan

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
README.md63 linesDownload Raw Back to root
1---2title: Floorplan Segmentation API3emoji: 📐4colorFrom: blue5colorTo: indigo6sdk: docker7app_port: 78608pinned: false9---10 11# Floorplan Segmentation API12 13FastAPI backend for the Raster·Vector floorplan vectorizer. Exposes a14segmentation endpoint that the Netlify frontend calls to get wall masks and15room labels. Runs CubiCasa5K when weights are present, otherwise a built-in16OpenCV heuristic (so the Space works out of the box).17 18## Endpoint19 20`POST /segment`21```json22{ "image": "<base64 png>" }23```24Response:25```json26{ "wall_mask_png": "<base64>", "room_label_png": "<base64>", "n_labels": 7 }27```28Room ids are encoded in the **red channel** of `room_label_png`29(0 = background), matching the frontend's decoder.30 31`GET /` returns health + whether the model or heuristic is active.32 33## Connect the frontend34 35In your Netlify site's environment variables, set:36```37VITE_SEGMENT_API=https://<your-username>-<space-name>.hf.space/segment38```39Redeploy the frontend; it will route segmentation through this Space.40 41Lock down CORS in production by setting the `ALLOWED_ORIGINS` Space secret to42your Netlify URL (comma-separated for multiple).43 44## Enabling the real model45 46The heuristic runs by default. To use CubiCasa5K:471. Add the CubiCasa5k repo's `floortrans/` package into this Space.482. Upload weights to `model/model_best_val_loss_var.pkl`49   (use Git LFS — it's large).503. Uncomment `torch`, `torchvision`, `scikit-image` in `requirements.txt`.514. Set Space variable `USE_MODEL=1`.525. Restart the Space. `GET /` should report `"mode": "model"`.53 54A free CPU Space runs the heuristic fine; the model is slow on CPU — consider55an upgraded CPU or a GPU Space for real inference.56 57## Local run58```bash59pip install -r requirements.txt60uvicorn app:app --reload --port 786061# POST a base64 PNG to http://localhost:7860/segment62```63