Spaces:
Sleeping
Sleeping
File size: 735 Bytes
3170420 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from pathlib import Path
import gradio as gr
from ultralytics import YOLO
# Load models
MODEL_PATH = "weights/mbari_315k_yolov8.pt"
MODEL = YOLO(MODEL_PATH)
PREDICT_KWARGS = {
"conf": 0.15,
}
# Get example images
EXAMPLES_DIR = Path("examples")
EXAMPLES = list(EXAMPLES_DIR.glob("*.png")) if EXAMPLES_DIR.exists() else []
def detect_objects(image):
results = MODEL.predict(image, **PREDICT_KWARGS)
return results[0].plot()
# Gradio interface with gr.Interface instead of gr.Blocks
demo = gr.Interface(
fn=detect_objects,
inputs=gr.Image(type="numpy"),
outputs=gr.Image(type="numpy"),
title="MBARI 315k",
examples=EXAMPLES if EXAMPLES else None,
cache_examples=True,
)
demo.queue().launch()
|