CoolFace
Apppublic

ShadowNS/floorplan

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

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

json
{ "image": "<base64 png>" }

Response:

json
{ "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/segment

Redeploy 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:

  1. 1.Add the CubiCasa5k repo's floortrans/ package into this Space.
  2. 2.Upload weights to model/model_best_val_loss_var.pkl (use Git LFS — it's large).
  3. 3.Uncomment torch, torchvision, scikit-image in requirements.txt.
  4. 4.Set Space variable USE_MODEL=1.
  5. 5.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

bash
pip install -r requirements.txt
uvicorn app:app --reload --port 7860
# POST a base64 PNG to http://localhost:7860/segment