skibi11 commited on
Commit
0bc9984
·
verified ·
1 Parent(s): 7867fa0

this is it

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -96,6 +96,8 @@ def run_leukocoria_prediction(iris_crop):
96
  # --- 3. FastAPI Application ---
97
  app = FastAPI()
98
 
 
 
99
  @app.post("/detect/")
100
  async def full_detection_pipeline(image: UploadFile = File(...)):
101
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
@@ -111,10 +113,10 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
111
  if not detect_faces_roboflow(temp_image_path):
112
  return JSONResponse(status_code=400, content={"error": "No face detected."})
113
 
114
- # --- This is the final corrected logic with logging ---
115
 
116
  image_to_process = raw_image
117
- was_mirrored = False # Add a flag to track if we flipped the image
118
 
119
  print("--- 1. Attempting detection on original image... ---")
120
  eye_crops, error_msg = detect_eyes_roboflow(temp_image_path, image_to_process)
@@ -124,7 +126,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
124
  print("--- 3. Original failed. Attempting detection on mirrored image... ---")
125
  mirrored_image = cv2.flip(raw_image, 1)
126
  image_to_process = mirrored_image
127
- was_mirrored = True # Set the flag to true
128
 
129
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp_mirrored:
130
  cv2.imwrite(tmp_mirrored.name, mirrored_image)
@@ -141,7 +143,6 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
141
  content={"error": "Could not detect exactly two eyes. Please try another photo."}
142
  )
143
 
144
- # Get the bounding box coordinates before sorting
145
  initial_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
146
  print(f"--- 5. Initial eye coordinates (x,y,w,h): {initial_boxes} ---")
147
 
@@ -151,17 +152,14 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
151
  sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
152
  print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
153
 
154
- # --- THE CRITICAL FIX for SWAPPED LABELS ---
 
155
  if was_mirrored:
156
- print("--- 7. Image was mirrored, reversing eye order for correct labeling. ---")
157
- eye_crops.reverse()
158
- reversed_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
159
- print(f"--- 8. Reversed eye coordinates (x,y,w,h): {reversed_boxes} ---")
160
 
161
  flags = {}
162
  eye_images_b64 = {}
163
  for i, eye_crop in enumerate(eye_crops):
164
- # Because of the sort and potential reverse, i=0 is ALWAYS the person's right eye
165
  side = "right" if i == 0 else "left"
166
  print(f"--- 9. Processing loop index {i}, assigning to: {side} eye. ---")
167
 
@@ -177,7 +175,7 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
177
  has_leuko, confidence = run_leukocoria_prediction(iris_crop)
178
  flags[side] = has_leuko
179
  else:
180
- flags[side] = "No iris detected"
181
 
182
  print("--- 10. Final generated flags:", flags, "---")
183
 
 
96
  # --- 3. FastAPI Application ---
97
  app = FastAPI()
98
 
99
+ # In app.py, replace the existing function with this one for testing
100
+
101
  @app.post("/detect/")
102
  async def full_detection_pipeline(image: UploadFile = File(...)):
103
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
 
113
  if not detect_faces_roboflow(temp_image_path):
114
  return JSONResponse(status_code=400, content={"error": "No face detected."})
115
 
116
+ # --- This is the test logic with eye_crops.reverse() removed ---
117
 
118
  image_to_process = raw_image
119
+ was_mirrored = False
120
 
121
  print("--- 1. Attempting detection on original image... ---")
122
  eye_crops, error_msg = detect_eyes_roboflow(temp_image_path, image_to_process)
 
126
  print("--- 3. Original failed. Attempting detection on mirrored image... ---")
127
  mirrored_image = cv2.flip(raw_image, 1)
128
  image_to_process = mirrored_image
129
+ was_mirrored = True
130
 
131
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp_mirrored:
132
  cv2.imwrite(tmp_mirrored.name, mirrored_image)
 
143
  content={"error": "Could not detect exactly two eyes. Please try another photo."}
144
  )
145
 
 
146
  initial_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
147
  print(f"--- 5. Initial eye coordinates (x,y,w,h): {initial_boxes} ---")
148
 
 
152
  sorted_boxes = [cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY)) for c in eye_crops]
153
  print(f"--- 6. Sorted eye coordinates (x,y,w,h): {sorted_boxes} ---")
154
 
155
+ # --- THE CHANGE ---
156
+ # The eye_crops.reverse() line has been removed for this test.
157
  if was_mirrored:
158
+ print("--- 7. Image was mirrored. (Reverse logic is currently disabled for testing) ---")
 
 
 
159
 
160
  flags = {}
161
  eye_images_b64 = {}
162
  for i, eye_crop in enumerate(eye_crops):
 
163
  side = "right" if i == 0 else "left"
164
  print(f"--- 9. Processing loop index {i}, assigning to: {side} eye. ---")
165
 
 
175
  has_leuko, confidence = run_leukocoria_prediction(iris_crop)
176
  flags[side] = has_leuko
177
  else:
178
+ flags[side] = None
179
 
180
  print("--- 10. Final generated flags:", flags, "---")
181