File size: 3,856 Bytes
7b0dd2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/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)