hoololi commited on
Commit
da34dd9
·
verified ·
1 Parent(s): 15be5a8

Upload game_engine.py

Browse files
Files changed (1) hide show
  1. game_engine.py +38 -56
game_engine.py CHANGED
@@ -38,63 +38,45 @@ print(f" SPACE_HARDWARE: {space_hardware}")
38
  print(f" HF_SPACE: {hf_space}")
39
  print(f" SPACE_AUTHOR_NAME: {space_author}")
40
 
41
- # Forcer GPU si on est sur HF Spaces (peu importe la config détectée)
 
42
  try:
43
- # Essayer GPU d'abord si des variables HF sont détectées
44
- if space_id or hf_space:
45
- print("🎯 HF Spaces détecté - Tentative mode TrOCR forcé")
46
- from image_processing_gpu import (
47
- recognize_number_fast_with_image,
48
- create_thumbnail_fast,
49
- create_white_canvas,
50
- cleanup_memory,
51
- log_memory_usage,
52
- get_ocr_model_info
53
- )
54
- ocr_module = "gpu"
55
- print("✅ Game Engine: Mode GPU - TrOCR forcé sur HF Spaces")
56
- else:
57
- raise ImportError("Pas sur HF Spaces")
58
-
59
- except (ImportError, Exception) as e:
60
- print(f"⚠️ Mode GPU forcé échoué: {e}")
61
- # Fallback détection normale
62
- try:
63
- import torch
64
- if torch.cuda.is_available():
65
- from image_processing_gpu import (
66
- recognize_number_fast_with_image,
67
- create_thumbnail_fast,
68
- create_white_canvas,
69
- cleanup_memory,
70
- log_memory_usage,
71
- get_ocr_model_info
72
- )
73
- ocr_module = "gpu"
74
- print("✅ Game Engine: Mode GPU - TrOCR activé")
75
- else:
76
- from image_processing_cpu import (
77
- recognize_number_fast_with_image,
78
- create_thumbnail_fast,
79
- create_white_canvas,
80
- cleanup_memory,
81
- log_memory_usage,
82
- get_ocr_model_info
83
- )
84
- ocr_module = "cpu"
85
- print("✅ Game Engine: Mode CPU - EasyOCR activé")
86
-
87
- except ImportError:
88
- from image_processing_cpu import (
89
- recognize_number_fast_with_image,
90
- create_thumbnail_fast,
91
- create_white_canvas,
92
- cleanup_memory,
93
- log_memory_usage,
94
- get_ocr_model_info
95
- )
96
- ocr_module = "cpu"
97
- print("✅ Game Engine: Mode CPU - EasyOCR activé")
98
 
99
  # Récupérer les infos du modèle sélectionné
100
  try:
 
38
  print(f" HF_SPACE: {hf_space}")
39
  print(f" SPACE_AUTHOR_NAME: {space_author}")
40
 
41
+ # Test direct de l'import GPU avec debugging
42
+ print("🧪 Test import image_processing_gpu...")
43
  try:
44
+ import image_processing_gpu
45
+ print("✅ Import image_processing_gpu réussi")
46
+
47
+ # Test de la fonction spécifique
48
+ print("🧪 Test fonction get_ocr_model_info...")
49
+ info = image_processing_gpu.get_ocr_model_info()
50
+ print(f"✅ OCR info: {info}")
51
+
52
+ # Si on arrive ici, l'import fonctionne
53
+ from image_processing_gpu import (
54
+ recognize_number_fast_with_image,
55
+ create_thumbnail_fast,
56
+ create_white_canvas,
57
+ cleanup_memory,
58
+ log_memory_usage,
59
+ get_ocr_model_info
60
+ )
61
+ ocr_module = "gpu"
62
+ print("✅ Game Engine: Mode GPU - TrOCR réussi !")
63
+
64
+ except Exception as e:
65
+ print(f"❌ Erreur import GPU: {e}")
66
+ import traceback
67
+ traceback.print_exc()
68
+
69
+ # Fallback CPU
70
+ from image_processing_cpu import (
71
+ recognize_number_fast_with_image,
72
+ create_thumbnail_fast,
73
+ create_white_canvas,
74
+ cleanup_memory,
75
+ log_memory_usage,
76
+ get_ocr_model_info
77
+ )
78
+ ocr_module = "cpu"
79
+ print("✅ Game Engine: Mode CPU - EasyOCR (fallback)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  # Récupérer les infos du modèle sélectionné
82
  try: