Spaces:
Running
Running
altawil
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -477,7 +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 |
-
|
|
|
|
|
481 |
# ==============================================================================
|
482 |
# 5. أحداث دورة حياة التطبيق (Startup/Shutdown)
|
483 |
# ==============================================================================
|
@@ -486,11 +488,32 @@ async def startup_event():
|
|
486 |
global MODEL
|
487 |
logging.info("🚗 Server starting up...")
|
488 |
logging.info(f"Using device: {DEVICE}")
|
489 |
-
MODEL = load_and_prepare_model(DEVICE)
|
|
|
490 |
if MODEL:
|
491 |
logging.info("✅ Model loaded successfully. Server is ready!")
|
492 |
else:
|
493 |
logging.error("❌ CRITICAL: Model could not be loaded. The API will not function correctly.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
|
495 |
# ==============================================================================
|
496 |
# 6. نقاط النهاية الرئيسية (API Endpoints)
|
|
|
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:
|
496 |
logging.error("❌ CRITICAL: Model could not be loaded. The API will not function correctly.")
|
497 |
+
# # تحميل النموذج باستخدام الدالة المحسنة
|
498 |
+
# try:
|
499 |
+
# # إنشاء إعدادات النموذج باستخدام الإعدادات الصحيحة من التدريب
|
500 |
+
|
501 |
+
|
502 |
+
# # تحميل النموذج مع الأوزان
|
503 |
+
#
|
504 |
+
# logger.info("✅ تم تحميل النموذج بنجاح")
|
505 |
+
|
506 |
+
# except Exception as e:
|
507 |
+
# logger.error(f"❌ خطأ في تحميل النموذج: {e}")
|
508 |
+
# logger.info("🔄 محاولة إنشاء نموذج بأوزان عشوائية...")
|
509 |
+
# try:
|
510 |
+
# model = InterfuserModel()
|
511 |
+
# model.to(device)
|
512 |
+
# model.eval()
|
513 |
+
# logger.warning("⚠️ تم إنشاء النموذج بأوزان عشوائية")
|
514 |
+
# except Exception as e2:
|
515 |
+
# logger.error(f"❌ فشل في إنشاء النموذج: {e2}")
|
516 |
+
# model = None
|
517 |
|
518 |
# ==============================================================================
|
519 |
# 6. نقاط النهاية الرئيسية (API Endpoints)
|