Spaces:
Sleeping
Sleeping
Fix: Amélioration diagnostic et gestion erreurs Hugging Face - Suppression configurations obsolètes upload dans config.toml - Ajout diagnostic système complet (mémoire, dépendances, environnement) - Gestion robuste téléchargement processeur avec fallback cache - Messages d'erreur détaillés pour debugging Hugging Face
Browse files- .streamlit/config.toml +1 -1
- .streamlit/config_hf.toml +2 -4
- src/streamlit_app_multilingual.py +65 -4
.streamlit/config.toml
CHANGED
|
@@ -6,7 +6,7 @@ headless = true
|
|
| 6 |
enableCORS = false
|
| 7 |
enableXsrfProtection = false
|
| 8 |
port = 7860
|
| 9 |
-
maxUploadSize
|
| 10 |
fileWatcherType = "none"
|
| 11 |
|
| 12 |
[browser]
|
|
|
|
| 6 |
enableCORS = false
|
| 7 |
enableXsrfProtection = false
|
| 8 |
port = 7860
|
| 9 |
+
# maxUploadSize supprimé car peut causer des problèmes
|
| 10 |
fileWatcherType = "none"
|
| 11 |
|
| 12 |
[browser]
|
.streamlit/config_hf.toml
CHANGED
|
@@ -28,7 +28,5 @@ textColor = "#262730"
|
|
| 28 |
showErrorDetails = true
|
| 29 |
toolbarMode = "minimal"
|
| 30 |
|
| 31 |
-
# Configuration pour les uploads
|
| 32 |
-
|
| 33 |
-
maxFileSize = 200
|
| 34 |
-
allowedExtensions = ["png", "jpg", "jpeg"]
|
|
|
|
| 28 |
showErrorDetails = true
|
| 29 |
toolbarMode = "minimal"
|
| 30 |
|
| 31 |
+
# Configuration pour les uploads (supprimée car obsolète)
|
| 32 |
+
# Les uploads sont maintenant gérés directement par Streamlit
|
|
|
|
|
|
src/streamlit_app_multilingual.py
CHANGED
|
@@ -7,6 +7,7 @@ import torch
|
|
| 7 |
import google.generativeai as genai
|
| 8 |
import gc
|
| 9 |
import time
|
|
|
|
| 10 |
|
| 11 |
# Cache global pour le modèle (persiste entre les reruns)
|
| 12 |
if 'global_model_cache' not in st.session_state:
|
|
@@ -59,6 +60,43 @@ def restore_model_from_cache():
|
|
| 59 |
except Exception:
|
| 60 |
return False
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def resize_image_if_needed(image, max_size=(800, 800)):
|
| 63 |
"""
|
| 64 |
Redimensionne l'image si elle dépasse la taille maximale spécifiée
|
|
@@ -218,6 +256,13 @@ def load_model():
|
|
| 218 |
try:
|
| 219 |
from transformers import AutoProcessor, Gemma3nForConditionalGeneration
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
# Nettoyer la mémoire avant le chargement
|
| 222 |
gc.collect()
|
| 223 |
if torch.cuda.is_available():
|
|
@@ -296,10 +341,26 @@ def load_model():
|
|
| 296 |
model_id = "google/gemma-3n-E4B-it"
|
| 297 |
|
| 298 |
# Charger le processeur
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
# Stratégie 1: Chargement ultra-conservateur (CPU uniquement, sans device_map)
|
| 305 |
def load_ultra_conservative():
|
|
|
|
| 7 |
import google.generativeai as genai
|
| 8 |
import gc
|
| 9 |
import time
|
| 10 |
+
import sys
|
| 11 |
|
| 12 |
# Cache global pour le modèle (persiste entre les reruns)
|
| 13 |
if 'global_model_cache' not in st.session_state:
|
|
|
|
| 60 |
except Exception:
|
| 61 |
return False
|
| 62 |
|
| 63 |
+
def diagnose_loading_issues():
|
| 64 |
+
"""Diagnostique les problèmes potentiels de chargement"""
|
| 65 |
+
issues = []
|
| 66 |
+
|
| 67 |
+
# Vérifier l'environnement
|
| 68 |
+
if os.path.exists("D:/Dev/model_gemma"):
|
| 69 |
+
issues.append("✅ Modèle local détecté")
|
| 70 |
+
else:
|
| 71 |
+
issues.append("🌐 Mode Hugging Face détecté")
|
| 72 |
+
|
| 73 |
+
# Vérifier les dépendances
|
| 74 |
+
try:
|
| 75 |
+
import transformers
|
| 76 |
+
issues.append(f"✅ Transformers version: {transformers.__version__}")
|
| 77 |
+
except ImportError:
|
| 78 |
+
issues.append("❌ Transformers non installé")
|
| 79 |
+
|
| 80 |
+
try:
|
| 81 |
+
import torch
|
| 82 |
+
issues.append(f"✅ PyTorch version: {torch.__version__}")
|
| 83 |
+
if torch.cuda.is_available():
|
| 84 |
+
issues.append(f"✅ CUDA disponible: {torch.cuda.get_device_name(0)}")
|
| 85 |
+
else:
|
| 86 |
+
issues.append("⚠️ CUDA non disponible - utilisation CPU")
|
| 87 |
+
except ImportError:
|
| 88 |
+
issues.append("❌ PyTorch non installé")
|
| 89 |
+
|
| 90 |
+
# Vérifier la mémoire disponible
|
| 91 |
+
try:
|
| 92 |
+
import psutil
|
| 93 |
+
memory = psutil.virtual_memory()
|
| 94 |
+
issues.append(f"💾 Mémoire disponible: {memory.available // (1024**3)} GB")
|
| 95 |
+
except ImportError:
|
| 96 |
+
issues.append("⚠️ Impossible de vérifier la mémoire")
|
| 97 |
+
|
| 98 |
+
return issues
|
| 99 |
+
|
| 100 |
def resize_image_if_needed(image, max_size=(800, 800)):
|
| 101 |
"""
|
| 102 |
Redimensionne l'image si elle dépasse la taille maximale spécifiée
|
|
|
|
| 256 |
try:
|
| 257 |
from transformers import AutoProcessor, Gemma3nForConditionalGeneration
|
| 258 |
|
| 259 |
+
# Diagnostic initial
|
| 260 |
+
st.info("🔍 Diagnostic de l'environnement...")
|
| 261 |
+
issues = diagnose_loading_issues()
|
| 262 |
+
with st.expander("📊 Diagnostic système", expanded=False):
|
| 263 |
+
for issue in issues:
|
| 264 |
+
st.write(issue)
|
| 265 |
+
|
| 266 |
# Nettoyer la mémoire avant le chargement
|
| 267 |
gc.collect()
|
| 268 |
if torch.cuda.is_available():
|
|
|
|
| 341 |
model_id = "google/gemma-3n-E4B-it"
|
| 342 |
|
| 343 |
# Charger le processeur
|
| 344 |
+
try:
|
| 345 |
+
st.info("Téléchargement du processeur depuis Hugging Face...")
|
| 346 |
+
processor = AutoProcessor.from_pretrained(
|
| 347 |
+
model_id,
|
| 348 |
+
trust_remote_code=True
|
| 349 |
+
)
|
| 350 |
+
st.success("Processeur téléchargé avec succès !")
|
| 351 |
+
except Exception as e:
|
| 352 |
+
st.error(f"Erreur lors du téléchargement du processeur : {e}")
|
| 353 |
+
st.info("Tentative de téléchargement avec cache...")
|
| 354 |
+
try:
|
| 355 |
+
processor = AutoProcessor.from_pretrained(
|
| 356 |
+
model_id,
|
| 357 |
+
trust_remote_code=True,
|
| 358 |
+
cache_dir="./cache"
|
| 359 |
+
)
|
| 360 |
+
st.success("Processeur téléchargé avec cache !")
|
| 361 |
+
except Exception as e2:
|
| 362 |
+
st.error(f"Erreur fatale lors du téléchargement du processeur : {e2}")
|
| 363 |
+
return None, None
|
| 364 |
|
| 365 |
# Stratégie 1: Chargement ultra-conservateur (CPU uniquement, sans device_map)
|
| 366 |
def load_ultra_conservative():
|