Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import numpy as np
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Charger le modèle localement pour éviter les problèmes SSL
|
| 10 |
+
def detect_objects(image):
|
| 11 |
+
model_path = "best.pt" # Assurez-vous que le modèle est bien téléchargé
|
| 12 |
+
model = YOLO(model_path) # Charger le modèle entraîné
|
| 13 |
+
results = model(image) # Exécuter la détection
|
| 14 |
+
|
| 15 |
+
result_image = results[0].plot() # Générer l'image annotée
|
| 16 |
+
return Image.fromarray(result_image)
|
| 17 |
+
|
| 18 |
+
# Interface Gradio
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=detect_objects,
|
| 21 |
+
inputs=gr.Image(type="pil"),
|
| 22 |
+
outputs=gr.Image(type="pil"),
|
| 23 |
+
title="Détection d'objets avec YOLOv8",
|
| 24 |
+
description="Uploader une image pour détecter les objets."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
demo.launch()
|