Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,7 @@
|
|
| 1 |
#3333333333333333333333333333
|
| 2 |
-
def init_environment():
|
| 3 |
-
import os
|
| 4 |
-
os.makedirs('/tmp/ultralytics_config', exist_ok=True)
|
| 5 |
-
os.environ['YOLO_CONFIG_DIR'] = '/tmp/ultralytics_config'
|
| 6 |
-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 7 |
-
|
| 8 |
-
print("Environnement initialisé avec succès")
|
| 9 |
|
| 10 |
-
init_environment()
|
| 11 |
import gradio as gr
|
| 12 |
from ultralytics import YOLO
|
| 13 |
-
# Configurer le dossier de configuration Ultralytics
|
| 14 |
-
os.environ['YOLO_CONFIG_DIR'] = '/tmp/ultralytics_config' # Dossier accessible en écriture
|
| 15 |
-
os.makedirs(os.environ['YOLO_CONFIG_DIR'], exist_ok=True)
|
| 16 |
import cv2
|
| 17 |
import numpy as np
|
| 18 |
from PIL import Image
|
|
@@ -25,16 +14,33 @@ import sqlite3
|
|
| 25 |
from sqlite3 import Error
|
| 26 |
import re # Module pour les expressions régulières
|
| 27 |
import warnings
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
# ------------------------------
|
| 32 |
# 1. CHARGEMENT DES MODÈLES
|
| 33 |
# ------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
# Chargement des modèles
|
| 36 |
-
from tensorflow.keras.models import load_model
|
| 37 |
-
|
| 38 |
try:
|
| 39 |
cnn_logo_model = load_model('logo_model_cnn.h5')
|
| 40 |
print("Modèle CNN chargé avec succès")
|
|
|
|
| 1 |
#3333333333333333333333333333
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from ultralytics import YOLO
|
|
|
|
|
|
|
|
|
|
| 5 |
import cv2
|
| 6 |
import numpy as np
|
| 7 |
from PIL import Image
|
|
|
|
| 14 |
from sqlite3 import Error
|
| 15 |
import re # Module pour les expressions régulières
|
| 16 |
import warnings
|
| 17 |
+
import os
|
| 18 |
+
from tensorflow.keras.models import load_model
|
|
|
|
| 19 |
# ------------------------------
|
| 20 |
# 1. CHARGEMENT DES MODÈLES
|
| 21 |
# ------------------------------
|
| 22 |
+
def init_environment():
|
| 23 |
+
"""Configure l'environnement pour Ultralytics et TensorFlow"""
|
| 24 |
+
# Dossier de configuration
|
| 25 |
+
config_dir = '/tmp/ultralytics_config'
|
| 26 |
+
os.makedirs(config_dir, exist_ok=True)
|
| 27 |
+
os.environ['YOLO_CONFIG_DIR'] = config_dir
|
| 28 |
+
|
| 29 |
+
# Suppression des warnings
|
| 30 |
+
warnings.filterwarnings('ignore')
|
| 31 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 32 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # Désactive GPU si non disponible
|
| 33 |
+
|
| 34 |
+
# Configuration Ultralytics
|
| 35 |
+
settings.update({
|
| 36 |
+
'runs_dir': os.path.join(config_dir, 'runs'),
|
| 37 |
+
'weights_dir': os.path.join(config_dir, 'weights')
|
| 38 |
+
})
|
| 39 |
|
| 40 |
+
# Initialisation
|
| 41 |
+
init_environment()
|
| 42 |
+
print("Environnement configuré avec succès")
|
| 43 |
# Chargement des modèles
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
cnn_logo_model = load_model('logo_model_cnn.h5')
|
| 46 |
print("Modèle CNN chargé avec succès")
|