Gabolozano commited on
Commit
d5aac08
·
verified ·
1 Parent(s): f6b7865

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -15,7 +15,7 @@ def draw_detections(image, detections):
15
  for detection in detections:
16
  # Extract scores, labels, and bounding boxes properly
17
  score = detection['score']
18
- label = detection['labels']
19
  box = detection['boxes'] # Make sure 'boxes' data structure matches expected in terms of naming and indexing
20
  x_min, y_min, x_max, y_max = map(int, [box[0], box[1], box[2], box[3]])
21
 
@@ -35,40 +35,41 @@ 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
 
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
 
65
  # Provide both the image and the JSON detection results
66
- return processed_image, pipeline_output
67
- except Exception as e:
68
  # Log the error
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,
 
15
  for detection in detections:
16
  # Extract scores, labels, and bounding boxes properly
17
  score = detection['score']
18
+ label = detection['label']
19
  box = detection['boxes'] # Make sure 'boxes' data structure matches expected in terms of naming and indexing
20
  x_min, y_min, x_max, y_max = map(int, [box[0], box[1], box[2], box[3]])
21
 
 
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
+
54
+ ##def get_pipeline_prediction(pil_image):
55
+ ## try:
56
  # Run the object detection pipeline
57
+ ## pipeline_output = od_pipe(pil_image)
58
 
59
  # Debugging: print the keys in the output dictionary
60
+ ## if pipeline_output:
61
+ ## print("Keys available in the detection output:", pipeline_output[0].keys())
62
 
63
  # Draw the detection results on the image
64
+ ## processed_image = draw_detections(pil_image, pipeline_output)
65
 
66
  # Provide both the image and the JSON detection results
67
+ ## return processed_image, pipeline_output
68
+ ## except Exception as e:
69
  # Log the error
70
+ #3 print(f"An error occurred: {str(e)}")
71
  # Return a message and an empty JSON
72
+ ## return pil_image, {"error": str(e)}
73
 
74
  demo = gr.Interface(
75
  fn=get_pipeline_prediction,