Spaces:
Running on Zero
Running on Zero
Olivier commited on
Upload 2 files
Browse files- game_engine.py +2 -2
- image_processing.py +6 -5
game_engine.py
CHANGED
|
@@ -508,9 +508,9 @@ def export_to_clean_dataset(session_data: list[dict], dataset_name: str = DATASE
|
|
| 508 |
if not DATASET_AVAILABLE:
|
| 509 |
return "❌ Modules dataset non disponibles"
|
| 510 |
|
| 511 |
-
hf_token = os.getenv("HF_TOKEN")
|
| 512 |
if not hf_token:
|
| 513 |
-
return "❌ Token HuggingFace manquant"
|
| 514 |
|
| 515 |
try:
|
| 516 |
print(f"\n🚀 === EXPORT VERS DATASET CALCUL OCR ===")
|
|
|
|
| 508 |
if not DATASET_AVAILABLE:
|
| 509 |
return "❌ Modules dataset non disponibles"
|
| 510 |
|
| 511 |
+
hf_token = os.getenv("HF_TOKEN") or os.getenv("tk_calcul_ocr") # Support des deux noms
|
| 512 |
if not hf_token:
|
| 513 |
+
return "❌ Token HuggingFace manquant (HF_TOKEN ou tk_calcul_ocr)"
|
| 514 |
|
| 515 |
try:
|
| 516 |
print(f"\n🚀 === EXPORT VERS DATASET CALCUL OCR ===")
|
image_processing.py
CHANGED
|
@@ -80,8 +80,9 @@ def optimize_image_for_ocr(image_dict: dict | np.ndarray | Image.Image | None) -
|
|
| 80 |
else:
|
| 81 |
pil_image = image.convert('RGB')
|
| 82 |
|
| 83 |
-
# Redimensionner
|
| 84 |
-
|
|
|
|
| 85 |
if pil_image.size[0] > max_size or pil_image.size[1] > max_size:
|
| 86 |
pil_image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 87 |
|
|
@@ -139,13 +140,13 @@ def recognize_number_fast_with_image(image_dict: dict | np.ndarray | Image.Image
|
|
| 139 |
if optimized_image is None:
|
| 140 |
return "0", None, None
|
| 141 |
|
| 142 |
-
# OCR rapide - optimisé pour
|
| 143 |
pixel_values = processor(images=optimized_image, return_tensors="pt").pixel_values
|
| 144 |
|
| 145 |
generated_ids = model.generate(
|
| 146 |
pixel_values,
|
| 147 |
-
max_length=
|
| 148 |
-
num_beams=1,
|
| 149 |
do_sample=False,
|
| 150 |
pad_token_id=processor.tokenizer.pad_token_id
|
| 151 |
)
|
|
|
|
| 80 |
else:
|
| 81 |
pil_image = image.convert('RGB')
|
| 82 |
|
| 83 |
+
# Redimensionner AGRESSIVEMENT pour optimiser OCR (16x16 patches)
|
| 84 |
+
# 128x128 = 64 patches vs 300x300 = 351 patches (5.5x plus rapide !)
|
| 85 |
+
max_size = 128 # Optimisé pour TrOCR
|
| 86 |
if pil_image.size[0] > max_size or pil_image.size[1] > max_size:
|
| 87 |
pil_image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 88 |
|
|
|
|
| 140 |
if optimized_image is None:
|
| 141 |
return "0", None, None
|
| 142 |
|
| 143 |
+
# OCR rapide - optimisé pour TrOCR (moins de patches, plus rapide)
|
| 144 |
pixel_values = processor(images=optimized_image, return_tensors="pt").pixel_values
|
| 145 |
|
| 146 |
generated_ids = model.generate(
|
| 147 |
pixel_values,
|
| 148 |
+
max_length=4, # Retour à 4 pour les calculs (plus rapide)
|
| 149 |
+
num_beams=1, # Pas de beam search (plus rapide)
|
| 150 |
do_sample=False,
|
| 151 |
pad_token_id=processor.tokenizer.pad_token_id
|
| 152 |
)
|