Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -160,6 +160,7 @@ iface = gr.Interface(
|
|
| 160 |
iface.launch()"""
|
| 161 |
|
| 162 |
from PIL import Image
|
|
|
|
| 163 |
import gradio as gr
|
| 164 |
from ultralytics import YOLO
|
| 165 |
|
|
@@ -170,19 +171,30 @@ model = YOLO(MODEL_URL)
|
|
| 170 |
# Define the prediction function
|
| 171 |
def predict(image):
|
| 172 |
try:
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
#
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
return output_image
|
|
|
|
| 184 |
except Exception as e:
|
| 185 |
-
print("Error during prediction:", e)
|
| 186 |
return None
|
| 187 |
|
| 188 |
# Create the Gradio interface
|
|
|
|
| 160 |
iface.launch()"""
|
| 161 |
|
| 162 |
from PIL import Image
|
| 163 |
+
import numpy as np
|
| 164 |
import gradio as gr
|
| 165 |
from ultralytics import YOLO
|
| 166 |
|
|
|
|
| 171 |
# Define the prediction function
|
| 172 |
def predict(image):
|
| 173 |
try:
|
| 174 |
+
# Debugging: Check image type
|
| 175 |
+
print("Input image type:", type(image))
|
| 176 |
+
|
| 177 |
+
# Ensure input is converted to a format the YOLO model supports
|
| 178 |
+
if isinstance(image, Image.Image): # If PIL image, convert to NumPy
|
| 179 |
+
image = np.array(image) # Convert to NumPy array
|
| 180 |
+
print("Converted image to NumPy array.")
|
| 181 |
+
|
| 182 |
+
# Perform prediction
|
| 183 |
+
results = model.predict(image) # Perform object detection
|
| 184 |
+
print("YOLO prediction completed.")
|
| 185 |
+
|
| 186 |
+
# Render bounding boxes on the image
|
| 187 |
+
results.render()
|
| 188 |
+
print("Bounding boxes rendered.")
|
| 189 |
+
|
| 190 |
+
# Convert back to PIL for output
|
| 191 |
+
output_image = Image.fromarray(results.imgs[0])
|
| 192 |
+
print("Output image type:", type(output_image))
|
| 193 |
+
|
| 194 |
return output_image
|
| 195 |
+
|
| 196 |
except Exception as e:
|
| 197 |
+
print("Error during prediction:", str(e))
|
| 198 |
return None
|
| 199 |
|
| 200 |
# Create the Gradio interface
|