File size: 607 Bytes
8d96f41
 
092313a
0d85e45
8d96f41
30146e4
0d85e45
8d96f41
 
 
 
 
 
 
 
 
0d85e45
8d96f41
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from PIL import Image
from ultralytics import YOLO
import gradio as gr

# Cargar un modelo YOLOv8n preentrenado
model = YOLO('best.pt')

def detect_objects(image: Image.Image):
    # Realizar la inferencia
    results = model(image)
    
    # Obtener y mostrar los resultados
    for r in results:
        im_array = r.plot()  # plot a BGR numpy array of predictions
        im = Image.fromarray(im_array[..., ::-1])  # RGB PIL image
        return im  # retornar la imagen con los objetos detectados

# Crear la interfaz de Gradio
gr.Interface(fn=detect_objects, inputs="image", outputs="image").launch()