Spaces:
Sleeping
Sleeping
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 | |
description += r.print() # Obtener la descripci贸n de los objetos detectados | |
return im, description # Retornar la imagen y la descripci贸n | |
# Crear la interfaz de Gradio | |
gr.Interface(fn=detect_objects, inputs="image", outputs=["image", "text"]).launch() | |