ayoubsa commited on
Commit
a3a6473
·
verified ·
1 Parent(s): be1f96e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -77,7 +77,7 @@ iface = gr.Interface(
77
  )
78
 
79
  # Launch the Gradio app
80
- iface.launch()"""
81
 
82
  import gradio as gr
83
  import torch
@@ -127,5 +127,31 @@ iface = gr.Interface(
127
  examples=example_images # Link the example images
128
  )
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  # Launch the Gradio app
131
  iface.launch()
 
77
  )
78
 
79
  # Launch the Gradio app
80
+ iface.launch()
81
 
82
  import gradio as gr
83
  import torch
 
127
  examples=example_images # Link the example images
128
  )
129
 
130
+ # Launch the Gradio app
131
+ iface.launch()"""
132
+
133
+ import gradio as gr
134
+ import torch
135
+ from PIL import Image
136
+
137
+ # Load the YOLO model
138
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='model.pt') # Replace with your uploaded model's path
139
+
140
+ # Define the prediction function
141
+ def predict(image):
142
+ results = model(image) # Perform object detection using YOLO
143
+ results.render() # Render bounding boxes on the image
144
+ output_image = Image.fromarray(results.imgs[0]) # Convert to PIL image
145
+ return output_image
146
+
147
+ # Create the Gradio interface
148
+ iface = gr.Interface(
149
+ fn=predict,
150
+ inputs=gr.inputs.Image(type="pil", label="Upload an Image"), # Upload input as PIL Image
151
+ outputs=gr.outputs.Image(type="pil", label="Predicted Image with Bounding Boxes"), # Output image
152
+ title="Object Detection App",
153
+ description="Upload an image, and the YOLO model will detect objects in it."
154
+ )
155
+
156
  # Launch the Gradio app
157
  iface.launch()