Hussein El-Hadidy
commited on
Commit
·
fe147ec
1
Parent(s):
4d2f608
Fix
Browse files
app.py
CHANGED
|
@@ -218,21 +218,31 @@ async def process_image(file: UploadFile = File(...)):
|
|
| 218 |
shutil.copyfileobj(file.file, buffer)
|
| 219 |
|
| 220 |
# Load the YOLO model
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
| 224 |
|
| 225 |
# Run YOLO detection on the image
|
| 226 |
try:
|
| 227 |
results = model(
|
| 228 |
source=image_path,
|
| 229 |
-
show=False,
|
| 230 |
save=False
|
| 231 |
)
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
except Exception as e:
|
| 236 |
raise HTTPException(status_code=500, detail=f"YOLO processing error: {str(e)}")
|
| 237 |
|
| 238 |
-
return JSONResponse(content={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
shutil.copyfileobj(file.file, buffer)
|
| 219 |
|
| 220 |
# Load the YOLO model
|
| 221 |
+
try:
|
| 222 |
+
model = YOLO("yolo11n-pose_float16.tflite")
|
| 223 |
+
print("Model loaded successfully")
|
| 224 |
+
except Exception as e:
|
| 225 |
+
raise HTTPException(status_code=500, detail=f"Model loading failed: {str(e)}")
|
| 226 |
|
| 227 |
# Run YOLO detection on the image
|
| 228 |
try:
|
| 229 |
results = model(
|
| 230 |
source=image_path,
|
| 231 |
+
show=False,
|
| 232 |
save=False
|
| 233 |
)
|
| 234 |
+
|
| 235 |
+
if not results or len(results) == 0 or results[0].keypoints is None or results[0].keypoints.xy is None:
|
| 236 |
+
return JSONResponse(content={"message": "No keypoints detected"}, status_code=200)
|
| 237 |
+
|
| 238 |
+
keypoints = results[0].keypoints.xy
|
| 239 |
+
confidences = results[0].boxes.conf if results[0].boxes is not None else []
|
| 240 |
+
|
| 241 |
except Exception as e:
|
| 242 |
raise HTTPException(status_code=500, detail=f"YOLO processing error: {str(e)}")
|
| 243 |
|
| 244 |
+
return JSONResponse(content={
|
| 245 |
+
"message": "Image processed successfully",
|
| 246 |
+
"KeypointsXY": keypoints.tolist(),
|
| 247 |
+
"confidences": confidences.tolist()
|
| 248 |
+
})
|
main.py
CHANGED
|
@@ -218,21 +218,31 @@ async def process_image(file: UploadFile = File(...)):
|
|
| 218 |
shutil.copyfileobj(file.file, buffer)
|
| 219 |
|
| 220 |
# Load the YOLO model
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
| 224 |
|
| 225 |
# Run YOLO detection on the image
|
| 226 |
try:
|
| 227 |
results = model(
|
| 228 |
source=image_path,
|
| 229 |
-
show=False,
|
| 230 |
save=False
|
| 231 |
)
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
except Exception as e:
|
| 236 |
raise HTTPException(status_code=500, detail=f"YOLO processing error: {str(e)}")
|
| 237 |
|
| 238 |
-
return JSONResponse(content={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
shutil.copyfileobj(file.file, buffer)
|
| 219 |
|
| 220 |
# Load the YOLO model
|
| 221 |
+
try:
|
| 222 |
+
model = YOLO("yolo11n-pose_float16.tflite")
|
| 223 |
+
print("Model loaded successfully")
|
| 224 |
+
except Exception as e:
|
| 225 |
+
raise HTTPException(status_code=500, detail=f"Model loading failed: {str(e)}")
|
| 226 |
|
| 227 |
# Run YOLO detection on the image
|
| 228 |
try:
|
| 229 |
results = model(
|
| 230 |
source=image_path,
|
| 231 |
+
show=False,
|
| 232 |
save=False
|
| 233 |
)
|
| 234 |
+
|
| 235 |
+
if not results or len(results) == 0 or results[0].keypoints is None or results[0].keypoints.xy is None:
|
| 236 |
+
return JSONResponse(content={"message": "No keypoints detected"}, status_code=200)
|
| 237 |
+
|
| 238 |
+
keypoints = results[0].keypoints.xy
|
| 239 |
+
confidences = results[0].boxes.conf if results[0].boxes is not None else []
|
| 240 |
+
|
| 241 |
except Exception as e:
|
| 242 |
raise HTTPException(status_code=500, detail=f"YOLO processing error: {str(e)}")
|
| 243 |
|
| 244 |
+
return JSONResponse(content={
|
| 245 |
+
"message": "Image processed successfully",
|
| 246 |
+
"KeypointsXY": keypoints.tolist(),
|
| 247 |
+
"confidences": confidences.tolist()
|
| 248 |
+
})
|