Spaces:
Runtime error
Runtime error
Update server.py
Browse files
server.py
CHANGED
|
@@ -27,24 +27,29 @@ async def root():
|
|
| 27 |
with open("index.html", "r", encoding="utf-8") as f:
|
| 28 |
return HTMLResponse(f.read())
|
| 29 |
|
| 30 |
-
|
| 31 |
@app.post("/infer")
|
| 32 |
async def run_inference(images: list[UploadFile] = File(...)):
|
| 33 |
-
# save uploads
|
| 34 |
img_paths = []
|
| 35 |
-
for
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
img_paths.append(tmp)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
bev_paths = infer_images(img_paths)
|
| 43 |
|
| 44 |
-
#
|
| 45 |
output = []
|
| 46 |
for p in bev_paths:
|
| 47 |
with open(p, "rb") as f:
|
| 48 |
b64 = base64.b64encode(f.read()).decode("utf-8")
|
| 49 |
output.append({"bev_image": b64})
|
|
|
|
| 50 |
return JSONResponse(content=output)
|
|
|
|
| 27 |
with open("index.html", "r", encoding="utf-8") as f:
|
| 28 |
return HTMLResponse(f.read())
|
| 29 |
|
|
|
|
| 30 |
@app.post("/infer")
|
| 31 |
async def run_inference(images: list[UploadFile] = File(...)):
|
|
|
|
| 32 |
img_paths = []
|
| 33 |
+
for upload in images:
|
| 34 |
+
data = await upload.read()
|
| 35 |
+
|
| 36 |
+
# Decode bytes → BGR image, dropping any alpha channel
|
| 37 |
+
bgr = mmcv.imfrombytes(data, flag="color")
|
| 38 |
+
|
| 39 |
+
# Overwrite to disk as a 3-channel PNG (or JPEG)
|
| 40 |
+
tmp = f"/tmp/{upload.filename}"
|
| 41 |
+
mmcv.imwrite(bgr, tmp)
|
| 42 |
+
|
| 43 |
img_paths.append(tmp)
|
| 44 |
|
| 45 |
+
# Now all inputs are (3, H, W)—your model won’t hit that dim==4 assertion
|
| 46 |
bev_paths = infer_images(img_paths)
|
| 47 |
|
| 48 |
+
# Base64-encode outputs
|
| 49 |
output = []
|
| 50 |
for p in bev_paths:
|
| 51 |
with open(p, "rb") as f:
|
| 52 |
b64 = base64.b64encode(f.read()).decode("utf-8")
|
| 53 |
output.append({"bev_image": b64})
|
| 54 |
+
|
| 55 |
return JSONResponse(content=output)
|