Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
-
import cv2
|
| 4 |
import numpy as np
|
| 5 |
from ultralytics import YOLO
|
| 6 |
-
import io
|
| 7 |
|
| 8 |
def load_model():
|
| 9 |
-
|
| 10 |
-
return model
|
| 11 |
|
| 12 |
model = load_model()
|
| 13 |
|
| 14 |
def process_image(input_image):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
# Plot results on image
|
| 19 |
plotted_img = results[0].plot()
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
pil_image = Image.fromarray(
|
|
|
|
| 23 |
return pil_image
|
| 24 |
|
| 25 |
iface = gr.Interface(
|
|
@@ -29,4 +30,6 @@ iface = gr.Interface(
|
|
| 29 |
title="Object Detection with YOLO",
|
| 30 |
description="Upload an image and the model will detect objects."
|
| 31 |
)
|
| 32 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from ultralytics import YOLO
|
|
|
|
| 5 |
|
| 6 |
def load_model():
|
| 7 |
+
return YOLO('yolov8x.pt')
|
|
|
|
| 8 |
|
| 9 |
model = load_model()
|
| 10 |
|
| 11 |
def process_image(input_image):
|
| 12 |
+
# Convert PIL Image to numpy array
|
| 13 |
+
np_image = np.array(input_image)
|
| 14 |
+
|
| 15 |
+
# Run YOLO model
|
| 16 |
+
results = model(np_image)
|
| 17 |
+
|
| 18 |
# Plot results on image
|
| 19 |
plotted_img = results[0].plot()
|
| 20 |
+
|
| 21 |
+
# Convert numpy array back to PIL Image
|
| 22 |
+
pil_image = Image.fromarray(plotted_img)
|
| 23 |
+
|
| 24 |
return pil_image
|
| 25 |
|
| 26 |
iface = gr.Interface(
|
|
|
|
| 30 |
title="Object Detection with YOLO",
|
| 31 |
description="Upload an image and the model will detect objects."
|
| 32 |
)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
iface.launch(share=False)
|