Spaces:
Sleeping
Sleeping
Upload game_engine.py
Browse files- game_engine.py +26 -4
game_engine.py
CHANGED
|
@@ -498,10 +498,15 @@ class MathGame:
|
|
| 498 |
if row_data['is_correct']:
|
| 499 |
correct_answers += 1
|
| 500 |
|
| 501 |
-
# Structure pour dataset
|
| 502 |
a, b, operation, correct_result = self.operations_history[i] if i < len(self.operations_history) else (0, 0, "×", 0)
|
| 503 |
|
| 504 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
|
| 506 |
entry = {
|
| 507 |
"session_id": session_id,
|
|
@@ -523,6 +528,9 @@ class MathGame:
|
|
| 523 |
"app_version": "3.0_calcul_ocr_parallel"
|
| 524 |
}
|
| 525 |
|
|
|
|
|
|
|
|
|
|
| 526 |
if row_data['dataset_image_data']:
|
| 527 |
entry["handwriting_image"] = row_data['dataset_image_data']["image_base64"]
|
| 528 |
entry["image_width"] = int(row_data['dataset_image_data']["compressed_size"][0])
|
|
@@ -653,12 +661,26 @@ def export_to_clean_dataset(session_data: list[dict], dataset_name: str = DATASE
|
|
| 653 |
print(f"\n🚀 === EXPORT VERS DATASET CALCUL OCR ===")
|
| 654 |
print(f"📊 Dataset: {dataset_name}")
|
| 655 |
|
| 656 |
-
# Filtrer les entrées avec images
|
| 657 |
clean_entries = []
|
| 658 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
for entry in session_data:
|
| 660 |
if entry.get('has_image', False):
|
| 661 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
|
| 663 |
print(f"✅ {len(clean_entries)} entrées avec images converties")
|
| 664 |
|
|
|
|
| 498 |
if row_data['is_correct']:
|
| 499 |
correct_answers += 1
|
| 500 |
|
| 501 |
+
# Structure pour dataset avec debug OCR
|
| 502 |
a, b, operation, correct_result = self.operations_history[i] if i < len(self.operations_history) else (0, 0, "×", 0)
|
| 503 |
|
| 504 |
+
try:
|
| 505 |
+
ocr_info_data = get_ocr_model_info()
|
| 506 |
+
print(f"🔍 Debug OCR info: {ocr_info_data}")
|
| 507 |
+
except Exception as e:
|
| 508 |
+
print(f"❌ Erreur get_ocr_model_info: {e}")
|
| 509 |
+
ocr_info_data = {"model_name": "Error", "device": "Unknown"}
|
| 510 |
|
| 511 |
entry = {
|
| 512 |
"session_id": session_id,
|
|
|
|
| 528 |
"app_version": "3.0_calcul_ocr_parallel"
|
| 529 |
}
|
| 530 |
|
| 531 |
+
print(f"🔍 Debug entry OCR fields: ocr_model={entry['ocr_model']}, ocr_device={entry['ocr_device']}")
|
| 532 |
+
|
| 533 |
+
|
| 534 |
if row_data['dataset_image_data']:
|
| 535 |
entry["handwriting_image"] = row_data['dataset_image_data']["image_base64"]
|
| 536 |
entry["image_width"] = int(row_data['dataset_image_data']["compressed_size"][0])
|
|
|
|
| 661 |
print(f"\n🚀 === EXPORT VERS DATASET CALCUL OCR ===")
|
| 662 |
print(f"📊 Dataset: {dataset_name}")
|
| 663 |
|
| 664 |
+
# Filtrer les entrées avec images et ajouter les infos OCR globalement
|
| 665 |
clean_entries = []
|
| 666 |
|
| 667 |
+
# Récupérer une seule fois les infos OCR pour toute la session
|
| 668 |
+
try:
|
| 669 |
+
global_ocr_info = get_ocr_model_info()
|
| 670 |
+
print(f"🔍 Infos OCR globales: {global_ocr_info}")
|
| 671 |
+
except Exception as e:
|
| 672 |
+
print(f"❌ Erreur infos OCR globales: {e}")
|
| 673 |
+
global_ocr_info = {"model_name": "Unknown", "device": "Unknown"}
|
| 674 |
+
|
| 675 |
for entry in session_data:
|
| 676 |
if entry.get('has_image', False):
|
| 677 |
+
# Ajouter explicitement les champs OCR manquants
|
| 678 |
+
entry_with_ocr = entry.copy()
|
| 679 |
+
entry_with_ocr["ocr_model"] = global_ocr_info.get("model_name", "Unknown")
|
| 680 |
+
entry_with_ocr["ocr_device"] = global_ocr_info.get("device", "Unknown")
|
| 681 |
+
|
| 682 |
+
print(f"🔍 Entry avec OCR: ocr_model={entry_with_ocr['ocr_model']}, ocr_device={entry_with_ocr['ocr_device']}")
|
| 683 |
+
clean_entries.append(entry_with_ocr)
|
| 684 |
|
| 685 |
print(f"✅ {len(clean_entries)} entrées avec images converties")
|
| 686 |
|