Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,11 +35,30 @@ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50", config
|
|
| 35 |
image_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
| 36 |
od_pipe = pipeline(task='object-detection', model=model, image_processor=image_processor)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
def get_pipeline_prediction(pil_image):
|
| 39 |
try:
|
| 40 |
# Run the object detection pipeline
|
| 41 |
pipeline_output = od_pipe(pil_image)
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Draw the detection results on the image
|
| 44 |
processed_image = draw_detections(pil_image, pipeline_output)
|
| 45 |
|
|
@@ -50,7 +69,7 @@ def get_pipeline_prediction(pil_image):
|
|
| 50 |
print(f"An error occurred: {str(e)}")
|
| 51 |
# Return a message and an empty JSON
|
| 52 |
return pil_image, {"error": str(e)}
|
| 53 |
-
|
| 54 |
demo = gr.Interface(
|
| 55 |
fn=get_pipeline_prediction,
|
| 56 |
inputs=gr.Image(label="Input image", type="pil"),
|
|
|
|
| 35 |
image_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
| 36 |
od_pipe = pipeline(task='object-detection', model=model, image_processor=image_processor)
|
| 37 |
|
| 38 |
+
##def get_pipeline_prediction(pil_image):
|
| 39 |
+
## try:
|
| 40 |
+
# Run the object detection pipeline
|
| 41 |
+
## pipeline_output = od_pipe(pil_image)
|
| 42 |
+
|
| 43 |
+
# Draw the detection results on the image
|
| 44 |
+
## processed_image = draw_detections(pil_image, pipeline_output)
|
| 45 |
+
|
| 46 |
+
# Provide both the image and the JSON detection results
|
| 47 |
+
## return processed_image, pipeline_output
|
| 48 |
+
## except Exception as e:
|
| 49 |
+
# Log the error
|
| 50 |
+
## print(f"An error occurred: {str(e)}")
|
| 51 |
+
# Return a message and an empty JSON
|
| 52 |
+
## return pil_image, {"error": str(e)}
|
| 53 |
def get_pipeline_prediction(pil_image):
|
| 54 |
try:
|
| 55 |
# Run the object detection pipeline
|
| 56 |
pipeline_output = od_pipe(pil_image)
|
| 57 |
+
|
| 58 |
+
# Debugging: print the keys in the output dictionary
|
| 59 |
+
if pipeline_output:
|
| 60 |
+
print("Keys available in the detection output:", pipeline_output[0].keys())
|
| 61 |
+
|
| 62 |
# Draw the detection results on the image
|
| 63 |
processed_image = draw_detections(pil_image, pipeline_output)
|
| 64 |
|
|
|
|
| 69 |
print(f"An error occurred: {str(e)}")
|
| 70 |
# Return a message and an empty JSON
|
| 71 |
return pil_image, {"error": str(e)}
|
| 72 |
+
|
| 73 |
demo = gr.Interface(
|
| 74 |
fn=get_pipeline_prediction,
|
| 75 |
inputs=gr.Image(label="Input image", type="pil"),
|