Spaces:
Running
Running
using temporary files for every Roboflow call
Browse files
app.py
CHANGED
|
@@ -50,11 +50,19 @@ def detect_eyes_roboflow(image_path, raw_image):
|
|
| 50 |
return crops
|
| 51 |
|
| 52 |
def get_largest_iris_prediction(eye_crop):
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def run_leukocoria_prediction(iris_crop):
|
| 60 |
if leuko_model is None: return {"error": "Leukocoria model not loaded"}, 0.0
|
|
|
|
| 50 |
return crops
|
| 51 |
|
| 52 |
def get_largest_iris_prediction(eye_crop):
|
| 53 |
+
"Calls Roboflow to find the largest iris using a temporary file for reliability."
|
| 54 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
|
| 55 |
+
cv2.imwrite(tmp.name, eye_crop)
|
| 56 |
+
temp_iris_path = tmp.name
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
# Use the file path for inference, which is more robust
|
| 60 |
+
resp = CLIENT_IRIS.infer(temp_iris_path, model_id="iris_120_set/7")
|
| 61 |
+
preds = resp.get("predictions", [])
|
| 62 |
+
return max(preds, key=lambda p: p["width"] * p["height"]) if preds else None
|
| 63 |
+
finally:
|
| 64 |
+
# Ensure the temporary file is always deleted
|
| 65 |
+
os.remove(temp_iris_path)
|
| 66 |
|
| 67 |
def run_leukocoria_prediction(iris_crop):
|
| 68 |
if leuko_model is None: return {"error": "Leukocoria model not loaded"}, 0.0
|