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.predict(image) # Obtener los resultados y el texto de descripciĆ³n description = "" for r in results: im_array = r.plot() # plot a BGR numpy array of predictions im = Image.fromarray(im_array[..., ::-1]) # Convertir a imagen RGB return im # Crear la interfaz de Gradio gr.Interface(fn=detect_objects, inputs="image", outputs="image").launch()