Muhammad commited on
Update src/predict.py
Browse files123 unmodified lines124125126127128129130131132133134135136137138139140141142143144123 unmodified linesdef load_model_and_classes() -> tuple[Any, dict[str, str]]:global _model, _idx_to_classif not MODEL_PATH.exists():raise Exception("Model file missing")if not CLASS_MAP_PATH.exists():raise Exception("Class map file missing")if _model is None:if not Path(MODEL_PATH).exists():raise FileNotFoundError(f"Model not found at {MODEL_PATH}")_model = tf.keras.models.load_model(MODEL_PATH)if _idx_to_class is None:if not Path(CLASS_MAP_PATH).exists():raise FileNotFoundError(f"class_map not found at {CLASS_MAP_PATH}")with open(CLASS_MAP_PATH, "r", encoding="utf-8") as f:_idx_to_class = json.load(f)return _model, _idx_to_class123 unmodified lines124125126127128129130131132133134135136137138139140141142143144145146147148149150151123 unmodified linesdef load_model_and_classes() -> tuple[Any, dict[str, str]]:global _model, _idx_to_class# Dynamic path resolution# This looks for the folder GardCom starting from the /app roothf_model_path = Path("/app/GardCom/saved_models_run2/best_model.keras")hf_class_path = Path("/app/GardCom/saved_models_run2/class_map.json")# Fallback to config paths if HF paths don't existfinal_model_path = hf_model_path if hf_model_path.exists() else MODEL_PATHfinal_class_path = hf_class_path if hf_class_path.exists() else CLASS_MAP_PATHif not final_model_path.exists():raise Exception(f"Model file missing at {final_model_path}")if not final_class_path.exists():raise Exception(f"Class map file missing at {final_class_path}")if _model is None:_model = tf.keras.models.load_model(final_model_path)if _idx_to_class is None:with open(final_class_path, "r", encoding="utf-8") as f:_idx_to_class = json.load(f)return _model, _idx_to_class
src/predict.py+17-10