Baseer_api_server / health_check.py
mohammed-aljafry's picture
Upload health_check.py with huggingface_hub
3d4e593 verified
#!/usr/bin/env python3
# health_check.py - فحص صحة النظام قبل النشر
import os
import sys
import torch
import logging
from pathlib import Path
def check_python_version():
"""فحص إصدار Python"""
version = sys.version_info
if version.major == 3 and version.minor >= 9:
print(f"✅ Python {version.major}.{version.minor}.{version.micro}")
return True
else:
print(f"❌ Python {version.major}.{version.minor}.{version.micro} - يتطلب Python 3.9+")
return False
def check_pytorch():
"""فحص PyTorch"""
try:
print(f"✅ PyTorch {torch.__version__}")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(f"✅ Device: {device}")
return True
except Exception as e:
print(f"❌ PyTorch Error: {e}")
return False
def check_required_files():
"""فحص الملفات المطلوبة"""
required_files = [
"app.py",
"model_definition.py",
"simulation_modules.py",
"requirements.txt",
"Dockerfile",
"app_config.yaml",
"model/best_model.pth"
]
missing_files = []
for file in required_files:
if Path(file).exists():
size = Path(file).stat().st_size
print(f"✅ {file} ({size:,} bytes)")
else:
print(f"❌ {file} - مفقود")
missing_files.append(file)
return len(missing_files) == 0
def check_model_loading():
"""فحص تحميل النموذج"""
try:
from model_definition import InterfuserModel, create_model_config, load_and_prepare_model
# إنشاء إعدادات النموذج
config = create_model_config("model/best_model.pth")
print("✅ تم إنشاء إعدادات النموذج")
# تحميل النموذج
device = torch.device("cpu")
model = load_and_prepare_model(config, device)
print("✅ تم تحميل النموذج بنجاح")
return True
except Exception as e:
print(f"❌ خطأ في تحميل النموذج: {e}")
return False
def check_api_imports():
"""فحص استيراد مكونات الـ API"""
try:
from app import app
print("✅ تم استيراد FastAPI app")
from simulation_modules import DisplayInterface, InterfuserController
print("✅ تم استيراد وحدات المحاكاة")
return True
except Exception as e:
print(f"❌ خطأ في استيراد الـ API: {e}")
return False
def main():
"""الفحص الشامل للنظام"""
print("🔍 فحص صحة نظام Baseer Self-Driving API")
print("=" * 50)
checks = [
("Python Version", check_python_version),
("PyTorch", check_pytorch),
("Required Files", check_required_files),
("API Imports", check_api_imports),
("Model Loading", check_model_loading),
]
passed = 0
total = len(checks)
for name, check_func in checks:
print(f"\n🔍 {name}:")
try:
if check_func():
passed += 1
else:
print(f"❌ فشل في فحص {name}")
except Exception as e:
print(f"❌ خطأ في فحص {name}: {e}")
print("\n" + "=" * 50)
print(f"📊 النتيجة النهائية: {passed}/{total} فحوصات نجحت")
if passed == total:
print("🎉 النظام جاهز للنشر!")
return True
else:
print("⚠️ يجب إصلاح المشاكل قبل النشر")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)