yaghi27 commited on
Commit
a163efa
·
1 Parent(s): bd3a67d

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +12 -9
server.py CHANGED
@@ -32,20 +32,23 @@ 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:
 
32
  img_paths = []
33
  for upload in images:
34
  data = await upload.read()
35
+ # force 3-channel BGR
36
+ bgr = mmcv.imfrombytes(data, flag="color")
 
 
 
37
  tmp = f"/tmp/{upload.filename}"
38
  mmcv.imwrite(bgr, tmp)
 
39
  img_paths.append(tmp)
40
 
41
+ # wrap the inference in try/except
42
+ try:
43
+ bev_paths = infer_images(img_paths)
44
+ except Exception as e:
45
+ logging.exception("❌ inference failed")
46
+ # return the error message to the client for debugging
47
+ return JSONResponse(
48
+ status_code=500,
49
+ content={"error": str(e)}
50
+ )
51
 
 
52
  output = []
53
  for p in bev_paths:
54
  with open(p, "rb") as f: