Spaces:
Runtime error
Runtime error
Martin Tomov
commited on
testing
Browse files
app.py
CHANGED
|
@@ -43,7 +43,8 @@ class DetectionResult:
|
|
| 43 |
ymin=detection_dict['box']['ymin'],
|
| 44 |
xmax=detection_dict['box']['xmax'],
|
| 45 |
ymax=detection_dict['box']['ymax']
|
| 46 |
-
)
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[DetectionResult]) -> np.ndarray:
|
|
@@ -186,26 +187,26 @@ def detections_to_json(detections):
|
|
| 186 |
return detections_list
|
| 187 |
|
| 188 |
def process_image(image, include_json):
|
| 189 |
-
labels = [
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
|
| 201 |
examples = [
|
| 202 |
-
|
| 203 |
]
|
| 204 |
|
| 205 |
gr.Interface(
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
).launch()
|
|
|
|
| 43 |
ymin=detection_dict['box']['ymin'],
|
| 44 |
xmax=detection_dict['box']['xmax'],
|
| 45 |
ymax=detection_dict['box']['ymax']
|
| 46 |
+
),
|
| 47 |
+
mask=detection_dict.get('mask')
|
| 48 |
)
|
| 49 |
|
| 50 |
def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[DetectionResult]) -> np.ndarray:
|
|
|
|
| 187 |
return detections_list
|
| 188 |
|
| 189 |
def process_image(image, include_json):
|
| 190 |
+
labels = [βinsectβ]
|
| 191 |
+
original_image, detections = grounded_segmentation(image, labels, threshold=0.3, polygon_refinement=True)
|
| 192 |
+
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
| 193 |
+
if include_json:
|
| 194 |
+
detections_json = detections_to_json(detections)
|
| 195 |
+
json_output_path = βinsect_detections.jsonβ
|
| 196 |
+
with open(json_output_path, βwβ) as json_file:
|
| 197 |
+
json.dump(detections_json, json_file, indent=4)
|
| 198 |
+
return yellow_background_with_insects, json.dumps(detections_json, separators=(β,β, β:β))
|
| 199 |
+
else:
|
| 200 |
+
return yellow_background_with_insects, None
|
| 201 |
|
| 202 |
examples = [
|
| 203 |
+
[βflower-night.jpgβ]
|
| 204 |
]
|
| 205 |
|
| 206 |
gr.Interface(
|
| 207 |
+
fn=process_image,
|
| 208 |
+
inputs=[gr.Image(type=βpilβ), gr.Checkbox(label=βInclude JSONβ, value=False)],
|
| 209 |
+
outputs=[gr.Image(type=βnumpyβ), gr.Textbox()],
|
| 210 |
+
title=βInsectSAM πβ,
|
| 211 |
+
examples=examples
|
| 212 |
).launch()
|