Spaces:
Sleeping
Sleeping
altawil
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -477,9 +477,9 @@ def prepare_model_input(image: np.ndarray, measurements: Measurements) -> Dict[s
|
|
| 477 |
'target_point': target_point_tensor,
|
| 478 |
'lidar': torch.zeros_like(image_tensor)
|
| 479 |
}
|
| 480 |
-
model_config = create_model_config(
|
| 481 |
-
|
| 482 |
-
)
|
| 483 |
# ==============================================================================
|
| 484 |
# 5. أحداث دورة حياة التطبيق (Startup/Shutdown)
|
| 485 |
# ==============================================================================
|
|
@@ -488,8 +488,8 @@ async def startup_event():
|
|
| 488 |
global MODEL
|
| 489 |
logging.info("🚗 Server starting up...")
|
| 490 |
logging.info(f"Using device: {DEVICE}")
|
| 491 |
-
MODEL = load_and_prepare_model(model_config, DEVICE)
|
| 492 |
-
|
| 493 |
if MODEL:
|
| 494 |
logging.info("✅ Model loaded successfully. Server is ready!")
|
| 495 |
else:
|
|
@@ -531,19 +531,41 @@ async def root():
|
|
| 531 |
</body>
|
| 532 |
</html>
|
| 533 |
"""
|
|
|
|
| 534 |
|
| 535 |
@app.post("/start_session", summary="Start a new driving session", tags=["Session Management"])
|
| 536 |
def start_session():
|
| 537 |
session_id = str(uuid.uuid4())
|
| 538 |
-
config = create_model_config()
|
| 539 |
-
controller_params = config.get('controller_params', {})
|
| 540 |
-
controller_params.update({'frequency': 10.0}) # Set default frequency
|
| 541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
SESSIONS[session_id] = {
|
| 543 |
-
'tracker':
|
| 544 |
-
'controller':
|
| 545 |
'frame_num': 0
|
| 546 |
}
|
|
|
|
| 547 |
logging.info(f"New session started: {session_id}")
|
| 548 |
return {"session_id": session_id}
|
| 549 |
|
|
|
|
| 477 |
'target_point': target_point_tensor,
|
| 478 |
'lidar': torch.zeros_like(image_tensor)
|
| 479 |
}
|
| 480 |
+
# model_config = create_model_config(
|
| 481 |
+
# model_path="model/best_model.pth"
|
| 482 |
+
# )
|
| 483 |
# ==============================================================================
|
| 484 |
# 5. أحداث دورة حياة التطبيق (Startup/Shutdown)
|
| 485 |
# ==============================================================================
|
|
|
|
| 488 |
global MODEL
|
| 489 |
logging.info("🚗 Server starting up...")
|
| 490 |
logging.info(f"Using device: {DEVICE}")
|
| 491 |
+
# MODEL = load_and_prepare_model(model_config, DEVICE)
|
| 492 |
+
MODEL = load_and_prepare_model(DEVICE)
|
| 493 |
if MODEL:
|
| 494 |
logging.info("✅ Model loaded successfully. Server is ready!")
|
| 495 |
else:
|
|
|
|
| 531 |
</body>
|
| 532 |
</html>
|
| 533 |
"""
|
| 534 |
+
# في ملف app.py
|
| 535 |
|
| 536 |
@app.post("/start_session", summary="Start a new driving session", tags=["Session Management"])
|
| 537 |
def start_session():
|
| 538 |
session_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
| 539 |
|
| 540 |
+
# 1. الحصول على الإعدادات الكاملة من المصدر الوحيد
|
| 541 |
+
config = get_master_config()
|
| 542 |
+
|
| 543 |
+
# 2. استخراج الإعدادات المطلوبة لكل مكون بشكل صريح
|
| 544 |
+
grid_conf = config['grid_conf']
|
| 545 |
+
controller_params = config['controller_params']
|
| 546 |
+
simulation_freq = config['simulation']['frequency']
|
| 547 |
+
|
| 548 |
+
# 3. تهيئة المتتبع (Tracker) بمعلماته المحددة
|
| 549 |
+
tracker = Tracker(
|
| 550 |
+
grid_conf=grid_conf,
|
| 551 |
+
match_threshold=controller_params.get('tracker_match_thresh', 2.5),
|
| 552 |
+
prune_age=controller_params.get('tracker_prune_age', 5)
|
| 553 |
+
)
|
| 554 |
+
|
| 555 |
+
# 4. تهيئة المتحكم (Controller)
|
| 556 |
+
controller = InterfuserController({
|
| 557 |
+
'controller_params': controller_params,
|
| 558 |
+
'grid_conf': grid_conf,
|
| 559 |
+
'frequency': simulation_freq
|
| 560 |
+
})
|
| 561 |
+
|
| 562 |
+
# 5. إنشاء الجلسة بالكائنات المهيأة
|
| 563 |
SESSIONS[session_id] = {
|
| 564 |
+
'tracker': tracker,
|
| 565 |
+
'controller': controller,
|
| 566 |
'frame_num': 0
|
| 567 |
}
|
| 568 |
+
|
| 569 |
logging.info(f"New session started: {session_id}")
|
| 570 |
return {"session_id": session_id}
|
| 571 |
|