mohammed-aljafry commited on
Commit
3d4e593
·
verified ·
1 Parent(s): 66b8e30

Upload health_check.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. health_check.py +127 -0
health_check.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # health_check.py - فحص صحة النظام قبل النشر
3
+
4
+ import os
5
+ import sys
6
+ import torch
7
+ import logging
8
+ from pathlib import Path
9
+
10
+ def check_python_version():
11
+ """فحص إصدار Python"""
12
+ version = sys.version_info
13
+ if version.major == 3 and version.minor >= 9:
14
+ print(f"✅ Python {version.major}.{version.minor}.{version.micro}")
15
+ return True
16
+ else:
17
+ print(f"❌ Python {version.major}.{version.minor}.{version.micro} - يتطلب Python 3.9+")
18
+ return False
19
+
20
+ def check_pytorch():
21
+ """فحص PyTorch"""
22
+ try:
23
+ print(f"✅ PyTorch {torch.__version__}")
24
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
25
+ print(f"✅ Device: {device}")
26
+ return True
27
+ except Exception as e:
28
+ print(f"❌ PyTorch Error: {e}")
29
+ return False
30
+
31
+ def check_required_files():
32
+ """فحص الملفات المطلوبة"""
33
+ required_files = [
34
+ "app.py",
35
+ "model_definition.py",
36
+ "simulation_modules.py",
37
+ "requirements.txt",
38
+ "Dockerfile",
39
+ "app_config.yaml",
40
+ "model/best_model.pth"
41
+ ]
42
+
43
+ missing_files = []
44
+ for file in required_files:
45
+ if Path(file).exists():
46
+ size = Path(file).stat().st_size
47
+ print(f"✅ {file} ({size:,} bytes)")
48
+ else:
49
+ print(f"❌ {file} - مفقود")
50
+ missing_files.append(file)
51
+
52
+ return len(missing_files) == 0
53
+
54
+ def check_model_loading():
55
+ """فحص تحميل النموذج"""
56
+ try:
57
+ from model_definition import InterfuserModel, create_model_config, load_and_prepare_model
58
+
59
+ # إنشاء إعدادات النموذج
60
+ config = create_model_config("model/best_model.pth")
61
+ print("✅ تم إنشاء إعدادات النموذج")
62
+
63
+ # تحميل النموذج
64
+ device = torch.device("cpu")
65
+ model = load_and_prepare_model(config, device)
66
+ print("✅ تم تحميل النموذج بنجاح")
67
+
68
+ return True
69
+
70
+ except Exception as e:
71
+ print(f"❌ خطأ في تحميل النموذج: {e}")
72
+ return False
73
+
74
+ def check_api_imports():
75
+ """فحص استيراد مكونات الـ API"""
76
+ try:
77
+ from app import app
78
+ print("✅ تم استيراد FastAPI app")
79
+
80
+ from simulation_modules import DisplayInterface, InterfuserController
81
+ print("✅ تم استيراد وحدات المحاكاة")
82
+
83
+ return True
84
+
85
+ except Exception as e:
86
+ print(f"❌ خطأ في استيراد الـ API: {e}")
87
+ return False
88
+
89
+ def main():
90
+ """الفحص الشامل للنظام"""
91
+ print("🔍 فحص صحة نظام Baseer Self-Driving API")
92
+ print("=" * 50)
93
+
94
+ checks = [
95
+ ("Python Version", check_python_version),
96
+ ("PyTorch", check_pytorch),
97
+ ("Required Files", check_required_files),
98
+ ("API Imports", check_api_imports),
99
+ ("Model Loading", check_model_loading),
100
+ ]
101
+
102
+ passed = 0
103
+ total = len(checks)
104
+
105
+ for name, check_func in checks:
106
+ print(f"\n🔍 {name}:")
107
+ try:
108
+ if check_func():
109
+ passed += 1
110
+ else:
111
+ print(f"❌ فشل في فحص {name}")
112
+ except Exception as e:
113
+ print(f"❌ خطأ في فحص {name}: {e}")
114
+
115
+ print("\n" + "=" * 50)
116
+ print(f"📊 النتيجة النهائية: {passed}/{total} فحوصات نجحت")
117
+
118
+ if passed == total:
119
+ print("🎉 النظام جاهز للنشر!")
120
+ return True
121
+ else:
122
+ print("⚠️ يجب إصلاح المشاكل قبل النشر")
123
+ return False
124
+
125
+ if __name__ == "__main__":
126
+ success = main()
127
+ sys.exit(0 if success else 1)