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

Upload game_engine.py

Browse files
Files changed (1) hide show
  1. game_engine.py +20 -10
game_engine.py CHANGED
@@ -25,14 +25,24 @@ from typing import Dict, Tuple, Optional
25
  ocr_module = None
26
  ocr_info = {"model_name": "Unknown", "device": "Unknown"}
27
 
28
- # Forcer GPU en mode HF Spaces avec hardware GPU
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  try:
30
- # Détecter si on est sur HF Spaces avec GPU allocé
31
- import os
32
- is_hf_gpu_space = os.getenv("SPACE_ID") and os.getenv("SPACE_HARDWARE") == "gpu"
33
-
34
- if is_hf_gpu_space:
35
- print("🎯 HF Spaces GPU détecté - Force mode TrOCR")
36
  from image_processing_gpu import (
37
  recognize_number_fast_with_image,
38
  create_thumbnail_fast,
@@ -44,11 +54,11 @@ try:
44
  ocr_module = "gpu"
45
  print("✅ Game Engine: Mode GPU - TrOCR forcé sur HF Spaces")
46
  else:
47
- raise ImportError("Pas en mode HF GPU")
48
 
49
  except (ImportError, Exception) as e:
50
- print(f"⚠️ Mode GPU non disponible: {e}")
51
- # Fallback CPU normal
52
  try:
53
  import torch
54
  if torch.cuda.is_available():
 
25
  ocr_module = None
26
  ocr_info = {"model_name": "Unknown", "device": "Unknown"}
27
 
28
+ # Debug des variables d'environnement HF
29
+ import os
30
+ space_id = os.getenv("SPACE_ID")
31
+ space_hardware = os.getenv("SPACE_HARDWARE")
32
+ hf_space = os.getenv("HF_SPACE")
33
+ space_author = os.getenv("SPACE_AUTHOR_NAME")
34
+
35
+ print(f"🔍 Debug HF Env:")
36
+ print(f" SPACE_ID: {space_id}")
37
+ 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,
 
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():