File size: 1,008 Bytes
3df11f7
 
 
 
 
edbf701
3df11f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
import gradio as gr
from ultralytics import YOLO

# Load your trained YOLOv8n model
# Ensure 'yolov8n.pt' is in the repository or provide the correct path.
model = YOLO("best (1).pt")

def detect(image):
    """
    Runs object detection on the input image.
    
    Args:
        image: A numpy array representing the input image.
    
    Returns:
        Annotated image as a numpy array.
    """
    # Run inference
    results = model(image)
    
    # Use the first result and plot detections on the image
    annotated_image = results[0].plot()  
    return annotated_image

# Build Gradio Interface
iface = gr.Interface(
    fn=detect,
    inputs=gr.Image(type="numpy", label="Input Image"),
    outputs=gr.Image(type="numpy", label="Detection Output"),
    title="YOLOv8n Object Detection",
    description="Upload an image and the model will detect objects using YOLOv8n."
)

# Launch the interface (Hugging Face Spaces will automatically run the app)
if __name__ == "__main__":
    iface.launch()