Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -160,9 +160,8 @@ iface = gr.Interface(
|
|
160 |
iface.launch()"""
|
161 |
|
162 |
from PIL import Image
|
163 |
-
import numpy as np
|
164 |
-
from ultralytics import YOLO
|
165 |
import gradio as gr
|
|
|
166 |
|
167 |
# Load the YOLO model
|
168 |
MODEL_URL = 'https://huggingface.co/ayoubsa/yolo_model/resolve/main/best.pt'
|
@@ -171,13 +170,16 @@ model = YOLO(MODEL_URL)
|
|
171 |
# Define the prediction function
|
172 |
def predict(image):
|
173 |
try:
|
174 |
-
print("Received image:", type(image)) # Check the type of the received image
|
175 |
results = model(image) # Perform object detection using YOLO
|
|
|
|
|
|
|
|
|
176 |
results.render() # Render bounding boxes on the image
|
177 |
|
178 |
output_image = Image.fromarray(results.imgs[0]) # Convert to PIL image
|
179 |
-
|
180 |
-
print("Predicted image:", type(output_image)) # Ensure output is PIL Image
|
181 |
return output_image
|
182 |
except Exception as e:
|
183 |
print("Error during prediction:", e)
|
@@ -194,3 +196,4 @@ iface = gr.Interface(
|
|
194 |
|
195 |
# Launch the Gradio app
|
196 |
iface.launch()
|
|
|
|
160 |
iface.launch()"""
|
161 |
|
162 |
from PIL import Image
|
|
|
|
|
163 |
import gradio as gr
|
164 |
+
from ultralytics import YOLO
|
165 |
|
166 |
# Load the YOLO model
|
167 |
MODEL_URL = 'https://huggingface.co/ayoubsa/yolo_model/resolve/main/best.pt'
|
|
|
170 |
# Define the prediction function
|
171 |
def predict(image):
|
172 |
try:
|
173 |
+
print("Received image:", type(image)) # Check the type of the received image (should be PIL)
|
174 |
results = model(image) # Perform object detection using YOLO
|
175 |
+
|
176 |
+
# Print details of the results object
|
177 |
+
print("Results:", results) # Check the contents of results
|
178 |
+
|
179 |
results.render() # Render bounding boxes on the image
|
180 |
|
181 |
output_image = Image.fromarray(results.imgs[0]) # Convert to PIL image
|
182 |
+
print("Predicted image type:", type(output_image)) # Ensure output is PIL Image
|
|
|
183 |
return output_image
|
184 |
except Exception as e:
|
185 |
print("Error during prediction:", e)
|
|
|
196 |
|
197 |
# Launch the Gradio app
|
198 |
iface.launch()
|
199 |
+
|