Spaces:
Running
Running
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() | |