ayoubsa commited on
Commit
3c36fab
·
verified ·
1 Parent(s): 8f970ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -43,6 +43,7 @@ gradio_app = gr.Interface(
43
  if __name__ == "__main__":
44
  gradio_app.launch()"""
45
 
 
46
  import gradio as gr
47
  from ultralytics import YOLO
48
  from PIL import Image
@@ -61,12 +62,23 @@ def predict(input_img):
61
  # Perform inference
62
  results = model(image_array)
63
 
 
 
 
64
  # Extract detected class names
65
  detected_classes = [model.names[int(cls)] for cls in results[0].boxes.cls]
 
66
 
67
  # Render results on the image
68
- rendered_image = results[0].plot() # This method returns the image with bounding boxes
69
- output_image = Image.fromarray(rendered_image) # Convert the rendered image to a PIL Image
 
 
 
 
 
 
 
70
 
71
  return output_image, {cls: 1.0 for cls in detected_classes} # Dummy scores for simplicity
72
  except Exception as e:
@@ -75,7 +87,7 @@ def predict(input_img):
75
 
76
  # Gradio app configuration
77
  gradio_app = gr.Interface(
78
- predict,
79
  inputs=gr.Image(label="Upload an Image", type="pil"),
80
  outputs=[
81
  gr.Image(label="Predicted Image with Bounding Boxes"), # Rendered image with bounding boxes
@@ -88,3 +100,4 @@ gradio_app = gr.Interface(
88
  if __name__ == "__main__":
89
  gradio_app.launch()
90
 
 
 
43
  if __name__ == "__main__":
44
  gradio_app.launch()"""
45
 
46
+
47
  import gradio as gr
48
  from ultralytics import YOLO
49
  from PIL import Image
 
62
  # Perform inference
63
  results = model(image_array)
64
 
65
+ # Debug: Log the results
66
+ print(f"Detection results: {results}")
67
+
68
  # Extract detected class names
69
  detected_classes = [model.names[int(cls)] for cls in results[0].boxes.cls]
70
+ print(f"Detected classes: {detected_classes}")
71
 
72
  # Render results on the image
73
+ rendered_image = results[0].plot() # Render bounding boxes
74
+ if rendered_image is None:
75
+ print("Rendered image is None. Something went wrong in the plot() method.")
76
+
77
+ # Debug: Log image shape after rendering
78
+ print(f"Rendered image shape: {rendered_image.shape}")
79
+
80
+ # Convert the rendered image to a PIL image for output
81
+ output_image = Image.fromarray(rendered_image)
82
 
83
  return output_image, {cls: 1.0 for cls in detected_classes} # Dummy scores for simplicity
84
  except Exception as e:
 
87
 
88
  # Gradio app configuration
89
  gradio_app = gr.Interface(
90
+ fn=predict,
91
  inputs=gr.Image(label="Upload an Image", type="pil"),
92
  outputs=[
93
  gr.Image(label="Predicted Image with Bounding Boxes"), # Rendered image with bounding boxes
 
100
  if __name__ == "__main__":
101
  gradio_app.launch()
102
 
103
+