An experimental safety dashboard for open-pit mining. The system accepts a site image and location, stores the image in Cloudinary, retrieves the latest upload from MongoDB, and combines slope, weather, and machine-learning features to estimate rockfall risk.
Status: This is a prototype for research and demonstration. It is not a certified mine-safety system and must not be used as the sole basis for operational decisions or emergency response.
- React + Vite dashboard for image upload, location search, map display, and risk visualization.
- Express API for Cloudinary uploads, MongoDB persistence, location search, and prediction orchestration.
- Python prediction service that loads a trained scikit-learn model, estimates slope from an image when available, retrieves weather data, and returns a risk level.
- Leaflet map integration for displaying the selected location and prediction result.
Browser (Vite / React)
|
| upload, search, latest-info requests
v
Express API (server/)
| | |
v v v
MongoDB Cloudinary Python process
|
v
model.pkl + WeatherAPI
- Node.js 18 or newer and npm
- Python 3.10 or newer
- MongoDB
- A Cloudinary account
- A WeatherAPI key
- Jupyter and the packages listed in
ml_training/requirements.txtfor model training
The model artifact is intentionally not committed. Generate it from the training notebook or provide it locally at the path expected by the Python service.
The training workflow lives in ml_training/train_model.ipynb. Run it when the model needs to be rebuilt or when the training data or feature preparation changes.
The notebook follows this process:
- It loads
yosemodiFinal_with_rockfall.csvinto a pandas DataFrame and inspects the columns, categories, and missing values. - It standardizes combined season labels such as
Winter - SpringandFall - Winterinto the season categories used by the application. - It fills missing season values, removes
Day,Month,Time (PST), andYear, and keeps the rock-unit categories represented in the current training selection. - It separates the target (
Rockfall) from the input features. The feature set includes slope movement type, season, volume statistics, relative size, rock unit, slope angle, and trigger. - It splits the records into training and test sets using a 20% test split and
random_state=10. - It builds a scikit-learn preprocessing and Random Forest pipeline. Categorical columns are one-hot encoded so the trained pipeline can accept the same string values used by the Python service.
- It evaluates the test predictions with accuracy, a classification report, and a confusion matrix.
- It serializes the complete pipeline to
model.pklwithpickle.
To reproduce the model locally:
cd ml_training
python -m venv .venv
.\\.venv\\Scripts\\Activate.ps1
pip install -r requirements.txt
jupyter notebook train_model.ipynbRun the notebook cells in order. The notebook saves model.pkl in the notebook's working directory. Keep that file at ml_training/model.pkl; the Python service loads it with the relative path ../ml_training/model.pkl when started from python_service. The generated model is ignored by Git because it is a build artifact rather than source data.
The notebook's reported accuracy is useful as a development signal, but it is not a safety guarantee. The dataset size, class balance, feature quality, geographic coverage, and validation strategy should be reviewed before relying on the model.
Create these files locally. They are ignored by Git and must never be committed:
PORT=4000
MONGODB_URI=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=WEATHER_API_KEY=The Python process receives the key from its environment. Do not put API keys in predict_rockfall.py, request payloads, frontend code, or browser-exposed VITE_* variables.
VITE_API_URL=http://localhost:4000Only non-secret values should use the VITE_ prefix because Vite exposes them to browser code.
Install each service independently:
cd server
npm install
cd ..\vite-project
npm install
cd ..\python_service
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtOn macOS or Linux, activate the environment with source .venv/bin/activate.
Start the API first:
cd server
npm startIn a second terminal, start the frontend:
cd vite-project
npm run devOpen the Vite URL shown in the terminal, normally http://localhost:5173.
The API normally listens on http://localhost:4000 and exposes:
| Method | Route | Purpose |
|---|---|---|
GET |
/ |
Health response |
POST |
/api/upload-image |
Upload one image using multipart field image |
GET |
/location/search-location?q=... |
Search locations through Nominatim |
GET |
/location/locate?q=... |
Resolve a location |
GET |
/location/get-latest-info |
Run prediction for the latest stored image |
The backend sends the latest image location to Python through standard input as JSON. The predictor returns coordinates, slope angle, weather values, trigger, risk probability, risk level, and a timestamp.
Risk levels are currently mapped as follows:
| Probability | Level |
|---|---|
< 0.20 |
MINIMAL |
0.20-0.39 |
LOW |
0.40-0.59 |
MEDIUM |
0.60-0.79 |
HIGH |
>= 0.80 |
CRITICAL |
- Training data and the notebook are under
ml_training/. - The runtime expects
ml_training/model.pkl; this generated model is not included in the repository. - The live model receives fixed values for several fields, including volume, relative size, rock unit, and slope movement type. These defaults limit how much a prediction reflects the selected site.
- DEM processing currently treats grayscale image values as elevation and uses fixed geographic bounds in the Python script. Replace these assumptions with calibrated DEM metadata before scientific or operational use.
- If DEM or weather retrieval fails, the predictor uses fallback estimates. These fallbacks are useful for development but are not reliable measurements.
- Keep
.envfiles, credentials, model artifacts, virtual environments,node_modules, caches, and generated outputs out of Git. - Use least-privilege MongoDB and Cloudinary credentials, restrict allowed origins in production, and add authentication and rate limiting before deployment.
- Review uploaded-file type, size, and content validation before exposing the API publicly.
cd vite-project
npm run lint
npm run build
cd ..\server
node --check server.jsThere is currently no automated test suite. Prediction, upload, database failure, missing model, invalid image, and malformed-location cases should be covered before production use.
No project license has been specified yet. Add a license file before accepting external contributions or publishing the project for reuse.