Spaces:
Paused
Paused
Fixed upload permission
Browse files- perception_roi_server.py +10 -7
perception_roi_server.py
CHANGED
|
@@ -38,6 +38,9 @@ DEFAULT_CONF = float(os.environ.get("YOLO_CONF", "0.25"))
|
|
| 38 |
DEFAULT_DEVICE = os.environ.get("YOLO_DEVICE", "auto")
|
| 39 |
FAST_DETECT_SCALE = float(os.environ.get("FAST_DETECT_SCALE", "0.65"))
|
| 40 |
FAST_DETECT_IMGSZ = int(os.environ.get("FAST_DETECT_IMGSZ", "512"))
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
app = FastAPI(title="ROI Compression Server", version="1.0.0")
|
| 43 |
app.add_middleware(
|
|
@@ -371,8 +374,8 @@ def _process_job(job: Job):
|
|
| 371 |
scale=max(0.25, min(1.0, (job.target_width / w) if (job.target_width and w) else 1.0)),
|
| 372 |
)
|
| 373 |
|
| 374 |
-
os.makedirs(
|
| 375 |
-
overlay_path = os.path.join(
|
| 376 |
overlay_writer = _open_writer(overlay_path, w, h, tfps)
|
| 377 |
|
| 378 |
with job.lock:
|
|
@@ -459,9 +462,9 @@ def _compress_job(job: Job, bandwidth_kbps: int, target_fps: int, target_w: int,
|
|
| 459 |
scale=resolution_scale,
|
| 460 |
)
|
| 461 |
|
| 462 |
-
os.makedirs(
|
| 463 |
-
compressed_path = os.path.join(
|
| 464 |
-
roi_path = os.path.join(
|
| 465 |
|
| 466 |
compressed_writer = _open_writer(compressed_path, tw, th, tfps)
|
| 467 |
roi_writer = _open_writer(roi_path, w, h, tfps)
|
|
@@ -564,8 +567,8 @@ async def track_async(
|
|
| 564 |
resolution_scale: float = Form(1.0),
|
| 565 |
):
|
| 566 |
job_id = uuid.uuid4().hex[:12]
|
| 567 |
-
os.makedirs(
|
| 568 |
-
dst = os.path.join(
|
| 569 |
data = await video.read()
|
| 570 |
with open(dst, "wb") as f:
|
| 571 |
f.write(data)
|
|
|
|
| 38 |
DEFAULT_DEVICE = os.environ.get("YOLO_DEVICE", "auto")
|
| 39 |
FAST_DETECT_SCALE = float(os.environ.get("FAST_DETECT_SCALE", "0.65"))
|
| 40 |
FAST_DETECT_IMGSZ = int(os.environ.get("FAST_DETECT_IMGSZ", "512"))
|
| 41 |
+
DATA_DIR = os.environ.get("DATA_DIR", "/tmp/roi_demo")
|
| 42 |
+
UPLOAD_DIR = os.path.join(DATA_DIR, "uploads")
|
| 43 |
+
OUTPUT_DIR = os.path.join(DATA_DIR, "outputs")
|
| 44 |
|
| 45 |
app = FastAPI(title="ROI Compression Server", version="1.0.0")
|
| 46 |
app.add_middleware(
|
|
|
|
| 374 |
scale=max(0.25, min(1.0, (job.target_width / w) if (job.target_width and w) else 1.0)),
|
| 375 |
)
|
| 376 |
|
| 377 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 378 |
+
overlay_path = os.path.join(OUTPUT_DIR, f"{job.id}_overlay.mp4")
|
| 379 |
overlay_writer = _open_writer(overlay_path, w, h, tfps)
|
| 380 |
|
| 381 |
with job.lock:
|
|
|
|
| 462 |
scale=resolution_scale,
|
| 463 |
)
|
| 464 |
|
| 465 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 466 |
+
compressed_path = os.path.join(OUTPUT_DIR, f"{job.id}_compressed_rt.mp4")
|
| 467 |
+
roi_path = os.path.join(OUTPUT_DIR, f"{job.id}_roi_rt.mp4")
|
| 468 |
|
| 469 |
compressed_writer = _open_writer(compressed_path, tw, th, tfps)
|
| 470 |
roi_writer = _open_writer(roi_path, w, h, tfps)
|
|
|
|
| 567 |
resolution_scale: float = Form(1.0),
|
| 568 |
):
|
| 569 |
job_id = uuid.uuid4().hex[:12]
|
| 570 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 571 |
+
dst = os.path.join(UPLOAD_DIR, f"{job_id}_{os.path.basename(video.filename or 'input.mp4')}")
|
| 572 |
data = await video.read()
|
| 573 |
with open(dst, "wb") as f:
|
| 574 |
f.write(data)
|