Update app.py
Browse files
app.py
CHANGED
|
@@ -63,6 +63,19 @@ async def segment_image(file: UploadFile = File(...)):
|
|
| 63 |
except Exception as e:
|
| 64 |
raise HTTPException(status_code=500, detail=str(e))
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# CVAT-specific endpoint
|
| 67 |
@app.post("/predict")
|
| 68 |
async def predict_for_cvat(body: str = Form(...)):
|
|
@@ -99,15 +112,17 @@ async def predict_for_cvat(body: str = Form(...)):
|
|
| 99 |
# Convert mask to CVAT format
|
| 100 |
height, width = mask.shape
|
| 101 |
rle = mask_to_rle(mask)
|
| 102 |
-
|
| 103 |
return {
|
|
|
|
| 104 |
"annotations": [{
|
| 105 |
-
"
|
| 106 |
-
"
|
| 107 |
-
"
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
| 111 |
}]
|
| 112 |
}
|
| 113 |
except Exception as e:
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
raise HTTPException(status_code=500, detail=str(e))
|
| 65 |
|
| 66 |
+
|
| 67 |
+
@app.get("/models")
|
| 68 |
+
def list_models():
|
| 69 |
+
return {
|
| 70 |
+
"models": [
|
| 71 |
+
{
|
| 72 |
+
"name": "sam-cvat",
|
| 73 |
+
"type": "segmentation",
|
| 74 |
+
"labels": ["object"]
|
| 75 |
+
}
|
| 76 |
+
]
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
# CVAT-specific endpoint
|
| 80 |
@app.post("/predict")
|
| 81 |
async def predict_for_cvat(body: str = Form(...)):
|
|
|
|
| 112 |
# Convert mask to CVAT format
|
| 113 |
height, width = mask.shape
|
| 114 |
rle = mask_to_rle(mask)
|
|
|
|
| 115 |
return {
|
| 116 |
+
"model": "sam-cvat",
|
| 117 |
"annotations": [{
|
| 118 |
+
"name": "object",
|
| 119 |
+
"score": float(scores[best_mask_idx]),
|
| 120 |
+
"mask": {
|
| 121 |
+
"rle": rle,
|
| 122 |
+
"width": width,
|
| 123 |
+
"height": height
|
| 124 |
+
},
|
| 125 |
+
"type": "mask"
|
| 126 |
}]
|
| 127 |
}
|
| 128 |
except Exception as e:
|