github-actions[bot] commited on
Commit ·
6d430cd
1
Parent(s): 2c659a8
Automated Deploy: a1680434660a105b47e3c9d41a56e6cea6390822
Browse files- README.md +13 -0
- SETUP.md +18 -0
- app.py +151 -28
- requirements-base.txt +2 -0
README.md
CHANGED
|
@@ -38,6 +38,19 @@ When configured, the frontend can send the final tile-rendered image to
|
|
| 38 |
`/gemini/refine-tile-render` for a conservative reflection, shadow, and detail
|
| 39 |
polish pass.
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
GPU run:
|
| 42 |
|
| 43 |
```bash
|
|
|
|
| 38 |
`/gemini/refine-tile-render` for a conservative reflection, shadow, and detail
|
| 39 |
polish pass.
|
| 40 |
|
| 41 |
+
Optional DigitalOcean Spaces upload archive in `backend/floor-visualizer/.env`:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
SPACES_BUCKET="your-space-name"
|
| 45 |
+
SPACES_REGION="nyc3"
|
| 46 |
+
SPACES_ACCESS_KEY_ID="your-spaces-access-key"
|
| 47 |
+
SPACES_SECRET_ACCESS_KEY="your-spaces-secret-key"
|
| 48 |
+
SPACES_UPLOAD_PREFIX="room-uploads"
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
When these are set, `/viz2d/convert` keeps the current frontend flow unchanged
|
| 52 |
+
and uploads a copy of each room image to Spaces in the background.
|
| 53 |
+
|
| 54 |
GPU run:
|
| 55 |
|
| 56 |
```bash
|
SETUP.md
CHANGED
|
@@ -33,3 +33,21 @@ It also downloads `Ruicheng/moge-2-vitl-normal`, the primary GPU geometry model.
|
|
| 33 |
|
| 34 |
- Environment variables override TOML values, for example `SEGMENTATION_MODEL=segformer`.
|
| 35 |
- `requirements.txt` is a full freeze from an existing environment. Prefer the smaller platform files above when recreating `.venv`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
- Environment variables override TOML values, for example `SEGMENTATION_MODEL=segformer`.
|
| 35 |
- `requirements.txt` is a full freeze from an existing environment. Prefer the smaller platform files above when recreating `.venv`.
|
| 36 |
+
|
| 37 |
+
## Optional DigitalOcean Spaces upload archive
|
| 38 |
+
|
| 39 |
+
The `/viz2d/convert` endpoint can copy each uploaded room image to a private
|
| 40 |
+
DigitalOcean Spaces bucket in the background without changing the frontend
|
| 41 |
+
flow. Add these values to `backend/floor-visualizer/.env`:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
SPACES_BUCKET="your-space-name"
|
| 45 |
+
SPACES_REGION="nyc3"
|
| 46 |
+
SPACES_ACCESS_KEY_ID="your-spaces-access-key"
|
| 47 |
+
SPACES_SECRET_ACCESS_KEY="your-spaces-secret-key"
|
| 48 |
+
SPACES_UPLOAD_PREFIX="room-uploads"
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
`SPACES_ENDPOINT_URL` is optional and defaults to
|
| 52 |
+
`https://$SPACES_REGION.digitaloceanspaces.com`. `SPACES_ACL` defaults to
|
| 53 |
+
`private`.
|
app.py
CHANGED
|
@@ -22,10 +22,15 @@ except ImportError:
|
|
| 22 |
raise ImportError(
|
| 23 |
"No TOML library found. Please run on Python 3.11+, or run 'pip install tomli' to support Python 3.10."
|
| 24 |
)
|
| 25 |
-
import uuid
|
| 26 |
-
from pathlib import Path
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
import numpy as np
|
| 30 |
import torch
|
| 31 |
from fastapi import FastAPI, File, Form, HTTPException, Response, UploadFile, BackgroundTasks
|
|
@@ -70,9 +75,12 @@ ADE20K_CLASSES = [
|
|
| 70 |
"vase", "traffic light", "tray", "ashcan", "fan", "pier", "crt screen",
|
| 71 |
"plate", "monitor", "bulletin board", "shower", "radiator", "glass",
|
| 72 |
"clock", "flag",
|
| 73 |
-
]
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
| 76 |
config_path = os.getenv("VISUALIZER_CONFIG")
|
| 77 |
if not config_path:
|
| 78 |
return {}
|
|
@@ -229,11 +237,53 @@ VISUALIZER_DATA_DIR = str(config_value(
|
|
| 229 |
"runtime",
|
| 230 |
"data_dir",
|
| 231 |
"data",
|
| 232 |
-
))
|
| 233 |
-
|
| 234 |
-
"
|
| 235 |
-
"
|
| 236 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
"",
|
| 238 |
)).strip()
|
| 239 |
GEMINI_IMAGE_MODEL = str(config_value(
|
|
@@ -3307,10 +3357,80 @@ def read_job(job_id: str):
|
|
| 3307 |
return json.loads(path.read_text())
|
| 3308 |
|
| 3309 |
|
| 3310 |
-
def write_job(job: dict):
|
| 3311 |
-
job_path(job["id"]).write_text(json.dumps(job))
|
| 3312 |
-
|
| 3313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3314 |
def run_conversion_task(job_id: str, upload_path: Path):
|
| 3315 |
try:
|
| 3316 |
t_start = time.perf_counter()
|
|
@@ -3501,14 +3621,16 @@ async def prepare_material_maps(
|
|
| 3501 |
|
| 3502 |
|
| 3503 |
@app.post("/viz2d/convert")
|
| 3504 |
-
async def convert_to_viz2d(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
|
| 3505 |
-
if file.content_type and not file.content_type.startswith("image/"):
|
| 3506 |
-
raise HTTPException(status_code=400, detail="Upload must be a JPG or PNG image.")
|
| 3507 |
-
|
| 3508 |
-
job_id = uuid.uuid4().hex
|
| 3509 |
-
|
| 3510 |
-
|
| 3511 |
-
|
|
|
|
|
|
|
| 3512 |
upload_path = UPLOAD_DIR / f"{job_id}{ext}"
|
| 3513 |
with upload_path.open("wb") as out:
|
| 3514 |
shutil.copyfileobj(file.file, out)
|
|
@@ -3518,10 +3640,11 @@ async def convert_to_viz2d(background_tasks: BackgroundTasks, file: UploadFile =
|
|
| 3518 |
"status": "PROCESSING",
|
| 3519 |
"inputUrl": f"/uploads/{upload_path.name}",
|
| 3520 |
"outputUrl": f"/viz2d/jobs/{job_id}/file",
|
| 3521 |
-
}
|
| 3522 |
-
write_job(job)
|
| 3523 |
-
background_tasks.add_task(run_conversion_task, job_id, upload_path)
|
| 3524 |
-
|
|
|
|
| 3525 |
|
| 3526 |
|
| 3527 |
@app.get("/viz2d/jobs/{job_id}")
|
|
|
|
| 22 |
raise ImportError(
|
| 23 |
"No TOML library found. Please run on Python 3.11+, or run 'pip install tomli' to support Python 3.10."
|
| 24 |
)
|
| 25 |
+
import uuid
|
| 26 |
+
from pathlib import Path
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
from dotenv import load_dotenv
|
| 30 |
+
except ImportError:
|
| 31 |
+
load_dotenv = None
|
| 32 |
+
|
| 33 |
+
import cv2
|
| 34 |
import numpy as np
|
| 35 |
import torch
|
| 36 |
from fastapi import FastAPI, File, Form, HTTPException, Response, UploadFile, BackgroundTasks
|
|
|
|
| 75 |
"vase", "traffic light", "tray", "ashcan", "fan", "pier", "crt screen",
|
| 76 |
"plate", "monitor", "bulletin board", "shower", "radiator", "glass",
|
| 77 |
"clock", "flag",
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
if load_dotenv is not None:
|
| 81 |
+
load_dotenv(Path(__file__).resolve().parent / ".env")
|
| 82 |
+
|
| 83 |
+
def load_config() -> dict:
|
| 84 |
config_path = os.getenv("VISUALIZER_CONFIG")
|
| 85 |
if not config_path:
|
| 86 |
return {}
|
|
|
|
| 237 |
"runtime",
|
| 238 |
"data_dir",
|
| 239 |
"data",
|
| 240 |
+
))
|
| 241 |
+
SPACES_BUCKET = str(config_value(
|
| 242 |
+
"SPACES_BUCKET",
|
| 243 |
+
"spaces",
|
| 244 |
+
"bucket",
|
| 245 |
+
"",
|
| 246 |
+
)).strip()
|
| 247 |
+
SPACES_REGION = str(config_value(
|
| 248 |
+
"SPACES_REGION",
|
| 249 |
+
"spaces",
|
| 250 |
+
"region",
|
| 251 |
+
"",
|
| 252 |
+
)).strip()
|
| 253 |
+
SPACES_ENDPOINT_URL = str(config_value(
|
| 254 |
+
"SPACES_ENDPOINT_URL",
|
| 255 |
+
"spaces",
|
| 256 |
+
"endpoint_url",
|
| 257 |
+
"",
|
| 258 |
+
)).strip().rstrip("/")
|
| 259 |
+
SPACES_ACCESS_KEY_ID = str(config_value(
|
| 260 |
+
"SPACES_ACCESS_KEY_ID",
|
| 261 |
+
"spaces",
|
| 262 |
+
"access_key_id",
|
| 263 |
+
"",
|
| 264 |
+
)).strip()
|
| 265 |
+
SPACES_SECRET_ACCESS_KEY = str(config_value(
|
| 266 |
+
"SPACES_SECRET_ACCESS_KEY",
|
| 267 |
+
"spaces",
|
| 268 |
+
"secret_access_key",
|
| 269 |
+
"",
|
| 270 |
+
)).strip()
|
| 271 |
+
SPACES_UPLOAD_PREFIX = str(config_value(
|
| 272 |
+
"SPACES_UPLOAD_PREFIX",
|
| 273 |
+
"spaces",
|
| 274 |
+
"upload_prefix",
|
| 275 |
+
"room-uploads",
|
| 276 |
+
)).strip().strip("/")
|
| 277 |
+
SPACES_ACL = str(config_value(
|
| 278 |
+
"SPACES_ACL",
|
| 279 |
+
"spaces",
|
| 280 |
+
"acl",
|
| 281 |
+
"private",
|
| 282 |
+
)).strip()
|
| 283 |
+
GEMINI_API_KEY = str(config_value(
|
| 284 |
+
"GEMINI_API_KEY",
|
| 285 |
+
"gemini",
|
| 286 |
+
"api_key",
|
| 287 |
"",
|
| 288 |
)).strip()
|
| 289 |
GEMINI_IMAGE_MODEL = str(config_value(
|
|
|
|
| 3357 |
return json.loads(path.read_text())
|
| 3358 |
|
| 3359 |
|
| 3360 |
+
def write_job(job: dict):
|
| 3361 |
+
job_path(job["id"]).write_text(json.dumps(job))
|
| 3362 |
+
|
| 3363 |
+
|
| 3364 |
+
def spaces_upload_enabled() -> bool:
|
| 3365 |
+
return bool(SPACES_BUCKET and SPACES_REGION and SPACES_ACCESS_KEY_ID and SPACES_SECRET_ACCESS_KEY)
|
| 3366 |
+
|
| 3367 |
+
|
| 3368 |
+
def spaces_endpoint_url() -> str:
|
| 3369 |
+
return SPACES_ENDPOINT_URL or f"https://{SPACES_REGION}.digitaloceanspaces.com"
|
| 3370 |
+
|
| 3371 |
+
|
| 3372 |
+
def spaces_upload_key(job_id: str, upload_path: Path) -> str:
|
| 3373 |
+
suffix = upload_path.suffix.lower()
|
| 3374 |
+
if suffix not in {".jpg", ".jpeg", ".png", ".webp"}:
|
| 3375 |
+
suffix = ".jpg"
|
| 3376 |
+
date_prefix = time.strftime("%Y/%m/%d", time.gmtime())
|
| 3377 |
+
filename = f"{job_id}{suffix}"
|
| 3378 |
+
return "/".join(part for part in [SPACES_UPLOAD_PREFIX, date_prefix, filename] if part)
|
| 3379 |
+
|
| 3380 |
+
|
| 3381 |
+
def upload_input_image_to_spaces(
|
| 3382 |
+
job_id: str,
|
| 3383 |
+
upload_path: Path,
|
| 3384 |
+
original_filename: str | None,
|
| 3385 |
+
content_type: str | None,
|
| 3386 |
+
):
|
| 3387 |
+
if not spaces_upload_enabled():
|
| 3388 |
+
return
|
| 3389 |
+
|
| 3390 |
+
try:
|
| 3391 |
+
import boto3
|
| 3392 |
+
from botocore.config import Config
|
| 3393 |
+
except ImportError:
|
| 3394 |
+
print("DigitalOcean Spaces upload skipped; install boto3 to enable object storage.", flush=True)
|
| 3395 |
+
return
|
| 3396 |
+
|
| 3397 |
+
try:
|
| 3398 |
+
key = spaces_upload_key(job_id, upload_path)
|
| 3399 |
+
metadata = {"job-id": job_id}
|
| 3400 |
+
if original_filename:
|
| 3401 |
+
metadata["original-filename"] = urllib.parse.quote(original_filename)[:900]
|
| 3402 |
+
|
| 3403 |
+
extra_args = {
|
| 3404 |
+
"ContentType": content_type or "application/octet-stream",
|
| 3405 |
+
"Metadata": metadata,
|
| 3406 |
+
}
|
| 3407 |
+
if SPACES_ACL:
|
| 3408 |
+
extra_args["ACL"] = SPACES_ACL
|
| 3409 |
+
|
| 3410 |
+
client = boto3.client(
|
| 3411 |
+
"s3",
|
| 3412 |
+
region_name=SPACES_REGION,
|
| 3413 |
+
endpoint_url=spaces_endpoint_url(),
|
| 3414 |
+
aws_access_key_id=SPACES_ACCESS_KEY_ID,
|
| 3415 |
+
aws_secret_access_key=SPACES_SECRET_ACCESS_KEY,
|
| 3416 |
+
config=Config(signature_version="s3v4"),
|
| 3417 |
+
)
|
| 3418 |
+
client.upload_file(str(upload_path), SPACES_BUCKET, key, ExtraArgs=extra_args)
|
| 3419 |
+
|
| 3420 |
+
job = read_job(job_id)
|
| 3421 |
+
job["inputObjectStorage"] = {
|
| 3422 |
+
"provider": "digitalocean-spaces",
|
| 3423 |
+
"bucket": SPACES_BUCKET,
|
| 3424 |
+
"region": SPACES_REGION,
|
| 3425 |
+
"key": key,
|
| 3426 |
+
"endpointUrl": spaces_endpoint_url(),
|
| 3427 |
+
}
|
| 3428 |
+
write_job(job)
|
| 3429 |
+
print(f"Uploaded input image for job {job_id} to DigitalOcean Spaces: {SPACES_BUCKET}/{key}", flush=True)
|
| 3430 |
+
except Exception as exc:
|
| 3431 |
+
print(f"DigitalOcean Spaces upload failed for job {job_id}: {exc}", flush=True)
|
| 3432 |
+
|
| 3433 |
+
|
| 3434 |
def run_conversion_task(job_id: str, upload_path: Path):
|
| 3435 |
try:
|
| 3436 |
t_start = time.perf_counter()
|
|
|
|
| 3621 |
|
| 3622 |
|
| 3623 |
@app.post("/viz2d/convert")
|
| 3624 |
+
async def convert_to_viz2d(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
|
| 3625 |
+
if file.content_type and not file.content_type.startswith("image/"):
|
| 3626 |
+
raise HTTPException(status_code=400, detail="Upload must be a JPG or PNG image.")
|
| 3627 |
+
|
| 3628 |
+
job_id = uuid.uuid4().hex
|
| 3629 |
+
original_filename = file.filename
|
| 3630 |
+
content_type = file.content_type
|
| 3631 |
+
ext = Path(file.filename or "room.jpg").suffix.lower()
|
| 3632 |
+
if ext not in {".jpg", ".jpeg", ".png", ".webp"}:
|
| 3633 |
+
ext = ".jpg"
|
| 3634 |
upload_path = UPLOAD_DIR / f"{job_id}{ext}"
|
| 3635 |
with upload_path.open("wb") as out:
|
| 3636 |
shutil.copyfileobj(file.file, out)
|
|
|
|
| 3640 |
"status": "PROCESSING",
|
| 3641 |
"inputUrl": f"/uploads/{upload_path.name}",
|
| 3642 |
"outputUrl": f"/viz2d/jobs/{job_id}/file",
|
| 3643 |
+
}
|
| 3644 |
+
write_job(job)
|
| 3645 |
+
background_tasks.add_task(run_conversion_task, job_id, upload_path)
|
| 3646 |
+
background_tasks.add_task(upload_input_image_to_spaces, job_id, upload_path, original_filename, content_type)
|
| 3647 |
+
return job
|
| 3648 |
|
| 3649 |
|
| 3650 |
@app.get("/viz2d/jobs/{job_id}")
|
requirements-base.txt
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
aiofiles==24.1.0
|
|
|
|
| 2 |
fastapi==0.115.12
|
| 3 |
huggingface-hub==0.32.0
|
| 4 |
numpy==2.2.6
|
| 5 |
opencv-python-headless==4.11.0.86
|
| 6 |
pillow==11.2.1
|
| 7 |
python-multipart==0.0.20
|
|
|
|
| 8 |
safetensors==0.5.3
|
| 9 |
timm==1.0.15
|
| 10 |
tokenizers==0.20.3
|
|
|
|
| 1 |
aiofiles==24.1.0
|
| 2 |
+
boto3>=1.34,<2
|
| 3 |
fastapi==0.115.12
|
| 4 |
huggingface-hub==0.32.0
|
| 5 |
numpy==2.2.6
|
| 6 |
opencv-python-headless==4.11.0.86
|
| 7 |
pillow==11.2.1
|
| 8 |
python-multipart==0.0.20
|
| 9 |
+
python-dotenv>=1.0,<2
|
| 10 |
safetensors==0.5.3
|
| 11 |
timm==1.0.15
|
| 12 |
tokenizers==0.20.3
|