Spaces:
Runtime error
Runtime error
remove debug logging
Browse files
app.py
CHANGED
|
@@ -59,19 +59,13 @@ def detect_brain_tumor_owlv2(image, seg_input, debug: bool = True):
|
|
| 59 |
Returns:
|
| 60 |
tuple: (numpy array of image, list of (label, (x1, y1, x2, y2)) tuples)
|
| 61 |
"""
|
| 62 |
-
if debug:
|
| 63 |
-
logger.debug(f"Image received, shape: {image.shape}")
|
| 64 |
|
| 65 |
# Step 2: Detect brain tumor using owl_v2
|
| 66 |
prompt = "detect brain tumor"
|
| 67 |
detections = owl_v2(prompt, image)
|
| 68 |
-
if debug:
|
| 69 |
-
logger.debug(f"Raw detections: {detections}")
|
| 70 |
|
| 71 |
# Step 3: Overlay bounding boxes on the image
|
| 72 |
image_with_bboxes = overlay_bounding_boxes(image, detections)
|
| 73 |
-
if debug:
|
| 74 |
-
logger.debug("Bounding boxes overlaid on the image")
|
| 75 |
|
| 76 |
# Prepare annotations for AnnotatedImage output
|
| 77 |
annotations = []
|
|
@@ -85,9 +79,6 @@ def detect_brain_tumor_owlv2(image, seg_input, debug: bool = True):
|
|
| 85 |
x1, y1, x2, y2 = int(x1*width), int(y1*height), int(x2*width), int(y2*height)
|
| 86 |
annotations.append(((x1, y1, x2, y2), f"{label} {score:.2f}"))
|
| 87 |
|
| 88 |
-
if debug:
|
| 89 |
-
logger.debug(f"Annotations: {annotations}")
|
| 90 |
-
|
| 91 |
# Convert image to numpy array if it's not already
|
| 92 |
if isinstance(image_with_bboxes, Image.Image):
|
| 93 |
image_with_bboxes = np.array(image_with_bboxes)
|
|
@@ -107,19 +98,13 @@ def detect_brain_tumor_dino(image, seg_input, debug: bool = True):
|
|
| 107 |
Returns:
|
| 108 |
tuple: (numpy array of image, list of (label, (x1, y1, x2, y2)) tuples)
|
| 109 |
"""
|
| 110 |
-
if debug:
|
| 111 |
-
logger.debug(f"Image received, shape: {image.shape}")
|
| 112 |
|
| 113 |
# Step 2: Detect brain tumor using grounding_dino
|
| 114 |
prompt = "detect brain tumor"
|
| 115 |
detections = grounding_dino(prompt, image)
|
| 116 |
-
if debug:
|
| 117 |
-
logger.debug(f"Raw detections: {detections}")
|
| 118 |
|
| 119 |
# Step 3: Overlay bounding boxes on the image
|
| 120 |
image_with_bboxes = overlay_bounding_boxes(image, detections)
|
| 121 |
-
if debug:
|
| 122 |
-
logger.debug("Bounding boxes overlaid on the image")
|
| 123 |
|
| 124 |
# Prepare annotations for AnnotatedImage output
|
| 125 |
annotations = []
|
|
@@ -133,9 +118,6 @@ def detect_brain_tumor_dino(image, seg_input, debug: bool = True):
|
|
| 133 |
x1, y1, x2, y2 = int(x1*width), int(y1*height), int(x2*width), int(y2*height)
|
| 134 |
annotations.append(((x1, y1, x2, y2), f"{label} {score:.2f}"))
|
| 135 |
|
| 136 |
-
if debug:
|
| 137 |
-
logger.debug(f"Annotations: {annotations}")
|
| 138 |
-
|
| 139 |
# Convert image to numpy array if it's not already
|
| 140 |
if isinstance(image_with_bboxes, Image.Image):
|
| 141 |
image_with_bboxes = np.array(image_with_bboxes)
|
|
@@ -155,19 +137,13 @@ def detect_brain_tumor_florence2(image, seg_input, debug: bool = True):
|
|
| 155 |
Returns:
|
| 156 |
tuple: (numpy array of image, list of (label, (x1, y1, x2, y2)) tuples)
|
| 157 |
"""
|
| 158 |
-
if debug:
|
| 159 |
-
logger.debug(f"Image received, shape: {image.shape}")
|
| 160 |
|
| 161 |
# Step 2: Detect brain tumor using florencev2 - NO PROMPT
|
| 162 |
prompt = "detect brain tumor"
|
| 163 |
detections = florencev2_object_detection(prompt)
|
| 164 |
-
if debug:
|
| 165 |
-
logger.debug(f"Raw detections: {detections}")
|
| 166 |
|
| 167 |
# Step 3: Overlay bounding boxes on the image
|
| 168 |
image_with_bboxes = overlay_bounding_boxes(image, detections)
|
| 169 |
-
if debug:
|
| 170 |
-
logger.debug("Bounding boxes overlaid on the image")
|
| 171 |
|
| 172 |
# Prepare annotations for AnnotatedImage output
|
| 173 |
annotations = []
|
|
@@ -181,9 +157,6 @@ def detect_brain_tumor_florence2(image, seg_input, debug: bool = True):
|
|
| 181 |
x1, y1, x2, y2 = int(x1*width), int(y1*height), int(x2*width), int(y2*height)
|
| 182 |
annotations.append(((x1, y1, x2, y2), f"{label} {score:.2f}"))
|
| 183 |
|
| 184 |
-
if debug:
|
| 185 |
-
logger.debug(f"Annotations: {annotations}")
|
| 186 |
-
|
| 187 |
# Convert image to numpy array if it's not already
|
| 188 |
if isinstance(image_with_bboxes, Image.Image):
|
| 189 |
image_with_bboxes = np.array(image_with_bboxes)
|
|
|
|
| 59 |
Returns:
|
| 60 |
tuple: (numpy array of image, list of (label, (x1, y1, x2, y2)) tuples)
|
| 61 |
"""
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Step 2: Detect brain tumor using owl_v2
|
| 64 |
prompt = "detect brain tumor"
|
| 65 |
detections = owl_v2(prompt, image)
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Step 3: Overlay bounding boxes on the image
|
| 68 |
image_with_bboxes = overlay_bounding_boxes(image, detections)
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# Prepare annotations for AnnotatedImage output
|
| 71 |
annotations = []
|
|
|
|
| 79 |
x1, y1, x2, y2 = int(x1*width), int(y1*height), int(x2*width), int(y2*height)
|
| 80 |
annotations.append(((x1, y1, x2, y2), f"{label} {score:.2f}"))
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
# Convert image to numpy array if it's not already
|
| 83 |
if isinstance(image_with_bboxes, Image.Image):
|
| 84 |
image_with_bboxes = np.array(image_with_bboxes)
|
|
|
|
| 98 |
Returns:
|
| 99 |
tuple: (numpy array of image, list of (label, (x1, y1, x2, y2)) tuples)
|
| 100 |
"""
|
|
|
|
|
|
|
| 101 |
|
| 102 |
# Step 2: Detect brain tumor using grounding_dino
|
| 103 |
prompt = "detect brain tumor"
|
| 104 |
detections = grounding_dino(prompt, image)
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Step 3: Overlay bounding boxes on the image
|
| 107 |
image_with_bboxes = overlay_bounding_boxes(image, detections)
|
|
|
|
|
|
|
| 108 |
|
| 109 |
# Prepare annotations for AnnotatedImage output
|
| 110 |
annotations = []
|
|
|
|
| 118 |
x1, y1, x2, y2 = int(x1*width), int(y1*height), int(x2*width), int(y2*height)
|
| 119 |
annotations.append(((x1, y1, x2, y2), f"{label} {score:.2f}"))
|
| 120 |
|
|
|
|
|
|
|
|
|
|
| 121 |
# Convert image to numpy array if it's not already
|
| 122 |
if isinstance(image_with_bboxes, Image.Image):
|
| 123 |
image_with_bboxes = np.array(image_with_bboxes)
|
|
|
|
| 137 |
Returns:
|
| 138 |
tuple: (numpy array of image, list of (label, (x1, y1, x2, y2)) tuples)
|
| 139 |
"""
|
|
|
|
|
|
|
| 140 |
|
| 141 |
# Step 2: Detect brain tumor using florencev2 - NO PROMPT
|
| 142 |
prompt = "detect brain tumor"
|
| 143 |
detections = florencev2_object_detection(prompt)
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# Step 3: Overlay bounding boxes on the image
|
| 146 |
image_with_bboxes = overlay_bounding_boxes(image, detections)
|
|
|
|
|
|
|
| 147 |
|
| 148 |
# Prepare annotations for AnnotatedImage output
|
| 149 |
annotations = []
|
|
|
|
| 157 |
x1, y1, x2, y2 = int(x1*width), int(y1*height), int(x2*width), int(y2*height)
|
| 158 |
annotations.append(((x1, y1, x2, y2), f"{label} {score:.2f}"))
|
| 159 |
|
|
|
|
|
|
|
|
|
|
| 160 |
# Convert image to numpy array if it's not already
|
| 161 |
if isinstance(image_with_bboxes, Image.Image):
|
| 162 |
image_with_bboxes = np.array(image_with_bboxes)
|