import gradio as gr import torch from ultralytics import YOLO from PIL import Image import numpy as np import os # Charger le modèle localement pour éviter les problèmes SSL def detect_objects(image): model_path = "best.pt" # Assurez-vous que le modèle est bien téléchargé model = YOLO(model_path) # Charger le modèle entraîné results = model(image) # Exécuter la détection result_image = results[0].plot() # Générer l'image annotée return Image.fromarray(result_image) # Interface Gradio demo = gr.Interface( fn=detect_objects, inputs=gr.Image(type="pil"), outputs=gr.Image(type="pil"), title="Détection d'objets avec YOLOv8", description="Uploader une image pour détecter les objets." ) if __name__ == "__main__": demo.launch()