File size: 8,788 Bytes
ab4e093
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# دليل التثبيت | Installation Guide

## 🚀 التثبيت السريع | Quick Installation

### المتطلبات الأساسية | Prerequisites

- **Python 3.9+** (يُفضل 3.10)
- **4GB RAM** (يُفضل 16GB)
- **10GB مساحة قرص** (يُفضل 50GB)
- **اتصال إنترنت** لتحميل النماذج

### الطريقة 1: التثبيت التلقائي | Method 1: Automatic Installation

```bash
# تحميل المشروع
git clone https://github.com/your-repo/ai-knowledge-distillation.git
cd ai-knowledge-distillation

# تشغيل سكريبت التثبيت
chmod +x start.sh
./start.sh
```

### الطريقة 2: التثبيت اليدوي | Method 2: Manual Installation

```bash
# 1. إنشاء بيئة افتراضية
python3 -m venv venv
source venv/bin/activate  # Linux/Mac
# أو
venv\Scripts\activate     # Windows

# 2. تحديث pip
pip install --upgrade pip

# 3. تثبيت التبعيات
pip install -r requirements.txt

# 4. إنشاء المجلدات المطلوبة
mkdir -p cache/datasets cache/transformers database logs models backups

# 5. نسخ ملف البيئة
cp .env.example .env

# 6. تشغيل التطبيق
python run_optimized.py
```

## 🔧 التكوين المتقدم | Advanced Configuration

### إعداد متغيرات البيئة | Environment Setup

```bash
# نسخ ملف البيئة
cp .env.example .env

# تحرير الإعدادات
nano .env  # أو محرر النصوص المفضل لديك
```

**الإعدادات المهمة | Important Settings:**

```bash
# رمز Hugging Face (مطلوب للنماذج الخاصة)
HF_TOKEN=your_token_here

# تحسين المعالج
OMP_NUM_THREADS=8
MKL_NUM_THREADS=8

# إدارة الذاكرة
MAX_MEMORY_GB=14.0
CHUNK_SIZE_MB=500.0

# تعطيل GPU (للتدريب على CPU فقط)
CUDA_VISIBLE_DEVICES=""
```

### تحسين الأداء | Performance Optimization

#### للأنظمة ذات الذاكرة المحدودة | For Limited Memory Systems

```bash
# تقليل استهلاك الذاكرة
export MAX_MEMORY_GB=6.0
export CHUNK_SIZE_MB=250.0
export BATCH_SIZE=2
```

#### لمعالجات Intel | For Intel CPUs

```bash
# تثبيت تحسينات Intel
pip install intel-extension-for-pytorch
pip install mkl

# تفعيل التحسينات
export USE_INTEL_EXTENSION=true
export MKL_NUM_THREADS=8
```

## 🐳 التثبيت باستخدام Docker | Docker Installation

### بناء الصورة | Build Image

```bash
# بناء الصورة المحسنة
docker build -f Dockerfile.optimized -t ai-distillation:latest .

# أو استخدام الصورة العادية
docker build -t ai-distillation:standard .
```

### تشغيل الحاوية | Run Container

```bash
# تشغيل مع متغيرات البيئة
docker run -d \
  --name ai-distillation \
  -p 8000:8000 \
  --env-file .env \
  -v $(pwd)/models:/app/models \
  -v $(pwd)/cache:/app/cache \
  ai-distillation:latest

# فحص السجلات
docker logs ai-distillation

# دخول الحاوية
docker exec -it ai-distillation /bin/bash
```

### Docker Compose

```yaml
# docker-compose.yml
version: '3.8'
services:
  ai-distillation:
    build:
      context: .
      dockerfile: Dockerfile.optimized
    ports:
      - "8000:8000"
    env_file:
      - .env
    volumes:
      - ./models:/app/models
      - ./cache:/app/cache
      - ./database:/app/database
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
```

```bash
# تشغيل مع Docker Compose
docker-compose up -d

# إيقاف الخدمة
docker-compose down
```

## 🏥 تثبيت المكونات الطبية | Medical Components Installation

### مكتبات DICOM | DICOM Libraries

```bash
# تثبيت مكتبات معالجة DICOM
pip install pydicom SimpleITK nibabel

# مكتبات إضافية للصور الطبية
pip install monai scikit-image imageio
```

### قواعد البيانات الطبية | Medical Datasets

```bash
# تحضير مجلدات البيانات الطبية
mkdir -p cache/medical_datasets

# تعيين متغيرات البيئة
export MEDICAL_DATASETS_CACHE=./cache/medical_datasets
export DICOM_MEMORY_LIMIT_MB=1000
```

## 🔐 إعداد الأمان | Security Setup

### تشفير الرموز المميزة | Token Encryption

```bash
# سيتم إنشاء مفتاح التشفير تلقائياً عند أول تشغيل
# The encryption key will be created automatically on first run

# للتحقق من وجود المفتاح
ls -la .token_key

# لإعادة إنشاء المفتاح (سيحذف الرموز الموجودة)
rm .token_key
python -c "from src.core.token_manager import TokenManager; TokenManager()"
```

### إعدادات الجدار الناري | Firewall Settings

```bash
# السماح للمنفذ 8000
sudo ufw allow 8000

# أو للوصول المحلي فقط
sudo ufw allow from 127.0.0.1 to any port 8000
```

## 🧪 اختبار التثبيت | Testing Installation

### الاختبار الأساسي | Basic Test

```bash
# تشغيل فحص الاستيرادات
python fix_imports.py

# تشغيل النسخة المبسطة
python app_minimal.py

# في نافذة أخرى، اختبار الاتصال
curl http://localhost:8000/health
```

### اختبار الميزات | Feature Testing

```bash
# اختبار إدارة الذاكرة
curl http://localhost:8000/api/system/memory

# اختبار إدارة الرموز
curl http://localhost:8000/api/tokens

# اختبار البيانات الطبية
curl http://localhost:8000/api/medical-datasets
```

## 🔄 التحديث | Updates

### تحديث التبعيات | Update Dependencies

```bash
# تحديث pip
pip install --upgrade pip

# تحديث التبعيات
pip install --upgrade -r requirements.txt

# تحديث PyTorch (CPU)
pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
```

### تحديث التطبيق | Update Application

```bash
# سحب آخر التحديثات
git pull origin main

# تحديث التبعيات
pip install -r requirements.txt

# إعادة تشغيل التطبيق
./start.sh --skip-install
```

## 🐛 استكشاف أخطاء التثبيت | Installation Troubleshooting

### مشاكل شائعة | Common Issues

#### خطأ في تثبيت PyTorch | PyTorch Installation Error

```bash
# تثبيت PyTorch CPU صراحة
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
```

#### خطأ في مكتبات النظام | System Libraries Error

```bash
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install build-essential python3-dev libffi-dev libssl-dev

# CentOS/RHEL
sudo yum groupinstall "Development Tools"
sudo yum install python3-devel libffi-devel openssl-devel

# macOS
xcode-select --install
brew install openssl libffi
```

#### مشكلة الأذونات | Permissions Issue

```bash
# إصلاح أذونات الملفات
chmod +x start.sh
chmod +x run_optimized.py

# إصلاح أذونات المجلدات
chmod -R 755 src/ templates/ static/
```

### فحص التثبيت | Installation Verification

```bash
# فحص شامل للتثبيت
python -c "
import sys
print(f'Python: {sys.version}')

try:
    import torch
    print(f'PyTorch: {torch.__version__}')
except ImportError:
    print('PyTorch: Not installed')

try:
    import transformers
    print(f'Transformers: {transformers.__version__}')
except ImportError:
    print('Transformers: Not installed')

try:
    import fastapi
    print(f'FastAPI: {fastapi.__version__}')
except ImportError:
    print('FastAPI: Not installed')
"
```

## 📚 الخطوات التالية | Next Steps

بعد التثبيت الناجح:

1. **قم بزيارة التطبيق:** http://localhost:8000
2. **أضف رمز Hugging Face:** http://localhost:8000/tokens
3. **استكشف البيانات الطبية:** http://localhost:8000/medical-datasets
4. **ابدأ أول تدريب:** اتبع الدليل في الواجهة الرئيسية

## 🆘 الحصول على المساعدة | Getting Help

إذا واجهت مشاكل في التثبيت:

1. **راجع دليل استكشاف الأخطاء:** TROUBLESHOOTING.md
2. **تحقق من السجلات:** `tail -f logs/app.log`
3. **استخدم النسخة المبسطة:** `python app_minimal.py`
4. **اجمع معلومات التصحيح:** `curl http://localhost:8000/debug`

---

🎉 **مبروك!** أنت الآن جاهز لاستخدام منصة تقطير المعرفة للذكاء الاصطناعي!