Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model = YOLO("best.pt") # assumes best.pt is in the same folder
|
| 7 |
+
|
| 8 |
+
# Inference function
|
| 9 |
+
def predict(image):
|
| 10 |
+
results = model(image)
|
| 11 |
+
annotated_frame = results[0].plot() # draw bounding boxes
|
| 12 |
+
return annotated_frame
|
| 13 |
+
|
| 14 |
+
# Gradio UI
|
| 15 |
+
demo = gr.Interface(
|
| 16 |
+
fn=predict,
|
| 17 |
+
inputs=gr.Image(type="pil"),
|
| 18 |
+
outputs=gr.Image(type="pil"),
|
| 19 |
+
title="YOLOv8 Object Detection",
|
| 20 |
+
description="Upload an image and see YOLOv8 detect objects using your custom-trained model."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Launch app
|
| 24 |
+
demo.launch()
|