Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,22 @@ def draw_detections(image, detections):
|
|
| 33 |
final_pil_image = Image.fromarray(final_image)
|
| 34 |
return final_pil_image
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=get_pipeline_prediction,
|
| 38 |
inputs=gr.Image(label="Input image", type="pil"),
|
|
|
|
| 33 |
final_pil_image = Image.fromarray(final_image)
|
| 34 |
return final_pil_image
|
| 35 |
|
| 36 |
+
def get_pipeline_prediction(pil_image):
|
| 37 |
+
try:
|
| 38 |
+
# Run the object detection pipeline
|
| 39 |
+
pipeline_output = od_pipe(pil_image)
|
| 40 |
+
|
| 41 |
+
# Draw the detection results on the image
|
| 42 |
+
processed_image = draw_detections(pil_image, pipeline_output)
|
| 43 |
+
|
| 44 |
+
# Provide both the image and the JSON detection results
|
| 45 |
+
return processed_image, pipeline_output
|
| 46 |
+
except Exception as e:
|
| 47 |
+
# Log the error
|
| 48 |
+
print(f"An error occurred: {str(e)}")
|
| 49 |
+
# Return a message and an empty JSON
|
| 50 |
+
return pil_image, {"error": str(e)}
|
| 51 |
+
|
| 52 |
demo = gr.Interface(
|
| 53 |
fn=get_pipeline_prediction,
|
| 54 |
inputs=gr.Image(label="Input image", type="pil"),
|