|
import gradio as gr |
|
import cv2 |
|
import numpy as np |
|
from ultralytics import YOLO |
|
|
|
|
|
model = YOLO("best.pt") |
|
|
|
|
|
def predict(image): |
|
|
|
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) |
|
|
|
|
|
results = model(image_bgr) |
|
|
|
|
|
annotated_image = results[0].plot() |
|
|
|
|
|
annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB) |
|
|
|
return annotated_image_rgb |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(type="numpy", label="Upload an Image"), |
|
outputs=gr.Image(type="numpy", label="Detected Objects"), |
|
title="YOLOv8 Object Detection", |
|
description="Upload an image to detect objects with YOLOv8 model." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch(share=True) |
|
|