Spaces:
Paused
Paused
File size: 2,530 Bytes
f66643d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import logging
import os
from pdf2zh.config import get_settings
from pdf2zh.e2e import get_parser
# Cấu hình log hiển thị ra terminal để xem quá trình load model
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
def test_loading_configuration():
print("=" * 60)
print(" STAGE 1: KIỂM TRA THÔNG TIN TỪ BIẾN MÔI TRƯỜNG / .ENV")
print("=" * 60)
# 1. Lấy thông số đang được load thông qua Pydantic Settings
settings = get_settings()
print(
f"📌 Trạng thái file .env: {'Có tồn tại' if os.path.exists('.env') else 'Không tồn tại (Đang dùng mặc định hệ thống)'}"
)
print(f"🔹 DEVICE: {settings.device}")
print(f"🔹 PAGE_BATCH_SIZE: {settings.page_batch_size}")
print(f"🔹 LAYOUT_BATCH_SIZE: {settings.layout_batch_size}")
print(f"🔹 DETECTION_BATCH_SIZE: {settings.detection_batch_size}")
print(f"🔹 OCR_BATCH_SIZE: {settings.ocr_batch_size}")
print(f"🔹 TABLE_BATCH_SIZE: {settings.table_batch_size}")
print(f"🔹 DETECTOR_TEXT_THRESHOLD: {settings.detector_text_threshold}")
print(f"🔹 DETECTOR_BLANK_THRESHOLD: {settings.detector_blank_threshold}")
print("-" * 60)
print("\n" + "=" * 60)
print(" STAGE 2: KIỂM TRA KHỞI TẠO SINGLETON PARSER")
print("=" * 60)
# 2. Gọi get_parser để xem hệ thống có map các config này vào phần cứng không
logger.info("Đang gọi get_parser()...")
parser = get_parser()
print("-" * 60)
print("✅ Kiểm tra thuộc tính bên trong StageAParser sau khi map:")
# Dump các giá trị phần cứng thực tế mà StageAParser đang nắm giữ sau khi qua hàm configure_settings
if hasattr(parser, "hardware"):
print(f"⚙️ Cấu hình phần cứng thực tế (parser.hardware): {parser.hardware}")
# Kiểm tra xem các threshold đã được đẩy vào OCR model chưa
if hasattr(parser, "ocr_model"):
ocr = parser.ocr_model
print(f"🔍 OCR Model Name: {getattr(ocr, 'model_name', 'Unknown')}")
print(
f"🎯 Ngưỡng Text thực tế trong instance: {getattr(ocr, 'detector_text_threshold', 'N/A')}"
)
print(
f"🎯 Ngưỡng Blank thực tế trong instance: {getattr(ocr, 'detector_blank_threshold', 'N/A')}"
)
print("=" * 60)
if __name__ == "__main__":
test_loading_configuration()
|