Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -23,17 +23,17 @@ async def root():
|
|
| 23 |
async def predict(request: ImageRequest):
|
| 24 |
# Check if the image string is empty
|
| 25 |
if not request.image:
|
| 26 |
-
return {"error": "
|
| 27 |
|
| 28 |
try:
|
| 29 |
# Attempt to decode Base64 string to bytes
|
| 30 |
image_bytes = base64.b64decode(request.image, validate=True)
|
| 31 |
except Exception as e:
|
| 32 |
-
return {"error": "Invalid
|
| 33 |
|
| 34 |
# Ensure the decoded bytes are not empty
|
| 35 |
if not image_bytes:
|
| 36 |
-
return {"error": "
|
| 37 |
|
| 38 |
np_arr = np.frombuffer(image_bytes, np.uint8)
|
| 39 |
image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
|
|
@@ -62,7 +62,6 @@ async def predict(request: ImageRequest):
|
|
| 62 |
key = f"{class_name}{class_counters[class_name]}" if class_counters[class_name] > 1 else class_name
|
| 63 |
json_result[key] = [x1, y1, x2, y2]
|
| 64 |
|
| 65 |
-
# Using model's summary output if available
|
| 66 |
if hasattr(result, "summary") and isinstance(result.summary, dict):
|
| 67 |
statistics_summary = result.summary
|
| 68 |
else:
|
|
|
|
| 23 |
async def predict(request: ImageRequest):
|
| 24 |
# Check if the image string is empty
|
| 25 |
if not request.image:
|
| 26 |
+
return {"error": "Invalid Image"}
|
| 27 |
|
| 28 |
try:
|
| 29 |
# Attempt to decode Base64 string to bytes
|
| 30 |
image_bytes = base64.b64decode(request.image, validate=True)
|
| 31 |
except Exception as e:
|
| 32 |
+
return {"error": "Invalid Image"}
|
| 33 |
|
| 34 |
# Ensure the decoded bytes are not empty
|
| 35 |
if not image_bytes:
|
| 36 |
+
return {"error": "Invalid Image"}
|
| 37 |
|
| 38 |
np_arr = np.frombuffer(image_bytes, np.uint8)
|
| 39 |
image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
|
|
|
|
| 62 |
key = f"{class_name}{class_counters[class_name]}" if class_counters[class_name] > 1 else class_name
|
| 63 |
json_result[key] = [x1, y1, x2, y2]
|
| 64 |
|
|
|
|
| 65 |
if hasattr(result, "summary") and isinstance(result.summary, dict):
|
| 66 |
statistics_summary = result.summary
|
| 67 |
else:
|