-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·69 lines (55 loc) · 2.1 KB
/
Copy pathmain.py
File metadata and controls
executable file
·69 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import uuid
import os
import shutil
from fastapi import FastAPI, UploadFile, File, BackgroundTasks
from fastapi.middleware.cors import CORSMiddleware
from pathlib import Path
import uvicorn
from backend.api_routes import router
from backend.tasks import run_pipeline
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
BASE_WORKSPACE = Path("/home/cave/3dapp/workspace")
app.include_router(router)
@app.post("/upload")
async def upload_video(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
job_id = str(uuid.uuid4())
session_dir = BASE_WORKSPACE / job_id
os.makedirs(session_dir / "images", exist_ok=True)
video_path = session_dir / "input.mp4"
with open(video_path, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
background_tasks.add_task(run_pipeline, job_id, video_path, session_dir)
return {"job_id": job_id, "status": "started"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
from fastapi.responses import FileResponse
import os
PLY_PATH = "/home/cave/3dapp/workspace" # we'll find the actual ply below
@app.get("/health")
def health():
ply_files = []
for root, dirs, files in os.walk("/home/cave/3dapp/workspace"):
for f in files:
if f.endswith(".ply"):
ply_files.append(os.path.join(root, f))
latest = sorted(ply_files)[-1] if ply_files else None
return {"status": "ok", "ply_ready": latest is not None, "ply_path": latest}
@app.get("/splat/latest.ply")
def serve_ply():
ply_files = []
for root, dirs, files in os.walk("/home/cave/3dapp/workspace"):
for f in files:
if f.endswith("cleaned_point_cloud.ply"):
ply_files.append(os.path.join(root, f))
if not ply_files:
from fastapi import HTTPException
raise HTTPException(status_code=404, detail="No PLY found. Run pipeline first.")
latest = sorted(ply_files)[-1]
return FileResponse(path=latest, media_type="application/octet-stream", filename="latest.ply")