An interactive web application for predicting shark foraging behavior using NASA satellite data and machine learning models.
- Dashboard: https://shark-habitat-frontend.onrender.com/
This project is an active work-in-progress. The current model can produce poor / unrealistic predictions (e.g., predicting high shark presence on land). We expect to correct this with improved feature engineering, stricter geospatial constraints, and better validation.
Planned improvements include experimenting with alternative modeling approaches, potentially including physics-based methods and more specialized domain models, in addition to further ML iteration.
- Interactive Map: Real-time habitat prediction with Mapbox integration
- AI-Powered Insights: OpenAI integration for natural language queries and analysis
- Analytics Dashboard: Comprehensive data visualization and model performance metrics
- Temporal Analysis: Time-based patterns in shark behavior
- Feature Importance: Understanding which environmental factors matter most
- Species Distribution: Analysis across different shark species
- Docker and Docker Compose
- Node.js 16+ (for local development)
- Python 3.9+ (for local development)
- Copy the environment template:
cp .env.example .env- Fill in your API keys in
.env:
OPENAI_API_KEY=your_openai_api_key_here
MAPBOX_PUBLIC_TOKEN=your_mapbox_token_here
EARTHDATA_TOKEN=your_earthdata_token_here
EARTHDATA_USERNAME=your_email@example.com
EARTHDATA_PASSWORD=your_password_here- Data files for Docker / the API: put
integrated_data_full.csvandsharks_cleaned.csvin thedata/folder (seedata/README.md). The backend still sees them as/app/integrated_data_full.csvinside the container.
# Build and start all services (from repository root; needs Docker Compose v2.20+ for `include`)
docker compose up --build
# Older Compose: use the file under deploy/ directly
docker compose -f deploy/docker-compose.yml up --build
# Access the application
open http://localhost:80cd backend
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000 --reloadcd frontend
npm install
npm startFrom the repository root:
./scripts/start.sh # macOS / Linux
scripts\start.bat # WindowsAlso from the repository root, after pip install -r requirements.txt:
python -m ml.main # integration + modeling demo
python -m ml.run_data_preprocessing # full preprocessing orchestration
python -m ml.scale_full_dataset # scale to full dataset (example)Other runnable modules live under ml/ and support the same python -m ml.<module> pattern.
- Best Model: GradientBoosting Classifier
- AUC Score: 0.983 (Excellent)
- Accuracy: 94.8%
- Training Samples: 64,942 shark tracking records
- Features: 28 environmental and temporal features
- Framework: FastAPI with Pydantic models
- ML Models: Scikit-learn (GradientBoosting, RandomForest, LogisticRegression)
- Data Processing: Pandas, NumPy
- AI Integration: OpenAI GPT-4 for insights and Q&A
- Framework: React 18 with Hooks
- Styling: Tailwind CSS with custom ocean theme
- Maps: Mapbox GL JS with React Map GL
- Charts: Plotly.js with React Plotly
- Animations: Framer Motion
- State Management: React Context API
- Shark Tracking: Tagged shark movement data
- Satellite Data: NASA MODIS-Aqua (SST, Chlorophyll-a)
- Environmental: Sea surface height, primary productivity
- Backend: FastAPI application on port 8000
- Frontend: React app served by Nginx on port 80
- Nginx: Reverse proxy for production deployment
βββ backend/ # FastAPI API (Docker / production)
βββ frontend/ # React app (Mapbox, dashboard, charts)
βββ ml/ # Offline NASA integration, preprocessing, training scripts
βββ tests/ # Smoke / setup checks (e.g. test_setup.py)
βββ scripts/ # start.sh, start.bat, production helpers
βββ deploy/ # Docker Compose stacks + prod nginx (canonical definitions)
βββ docs/ # Extra deployment and data notes (WEBAPP_README, Railway, etc.)
βββ data/ # Large CSVs (integrated + shark tracks); see data/README.md
βββ outputs/ # Plots (outputs/figures) and submission PDFs (outputs/submission)
βββ docker-compose.yml # Thin wrapper: includes deploy/docker-compose.yml (Compose 2.20+)
βββ docker-compose.prod.yml # Thin wrapper: includes deploy/docker-compose.prod.yml
βββ requirements.txt # Python deps for the ml/ pipeline
βββ results_retrained/ # Trained models + metrics (used by deployed API)
GET /- API informationGET /health- Health checkPOST /predict- Habitat predictionGET /shark-tracks- Shark tracking dataGET /model-performance- Model metricsGET /species- Available speciesGET /stats- Dataset statistics
POST /generate-insights- AI-powered insightsPOST /ask-question- Natural language Q&APOST /generate-report- Comprehensive analysis
- Map Interaction: Click anywhere on the map to get habitat predictions
- Species Filtering: Use the controls panel to filter by shark species
- Analytics: Switch to the dashboard for detailed analysis
- AI Assistant: Ask questions about the data and predictions
- Temporal Analysis: Explore time-based patterns in shark behavior
- Environment variables for sensitive API keys
- CORS configuration for cross-origin requests
- Input validation with Pydantic models
- Non-root user in Docker containers
- Backend: FastAPI with async/await for high concurrency
- Frontend: React with optimized re-renders
- Caching: Model and data caching for faster predictions
- Lazy Loading: Components loaded on demand
# Build for production (root file includes deploy/docker-compose.prod.yml)
docker compose -f docker-compose.prod.yml up --build
# Or call the canonical file
docker compose -f deploy/docker-compose.prod.yml up --build
# Scale services
docker compose up --scale backend=3- Set
REACT_APP_API_URLto your production API URL - Configure proper CORS origins
- Use production-grade API keys
- Set up SSL/TLS certificates
This project is React + FastAPI. It is not a Streamlit app; Streamlit would mean rebuilding the whole UI.
| Piece | Good options | Notes |
|---|---|---|
| API + model | Render, Railway, Fly.io | Longβrunning Python process, load results_retrained/ and data/integrated_data_full.csv (or attach storage). Repo hints: render.yaml, railway.json, Procfile, nixpacks.toml. |
| Static React app | Netlify, Vercel | Build frontend/ β publish frontend/build. Set REACT_APP_API_URL to your public API base URL and REACT_APP_MAPBOX_TOKEN. Repo hint: netlify.toml. |
Vercel alone is a weak fit for this backend (big model + pandas in one process). Typical pattern: Vercel or Netlify for the site, Render/Railway/Fly for the API.
Checklist
- Deploy backend: e.g.
cd backend && pip install -r requirements.txtthenuvicorn app:app --host 0.0.0.0 --port $PORT. - Provide env vars on the host:
OPENAI_API_KEY,MAPBOX_PUBLIC_TOKEN, Earthdata vars if used, and CORS allowing your frontend origin (seebackend/app.py). - Ship model + metrics (
results_full/orresults_retrained/, matching whatapp.pyexpects) anddata/integrated_data_full.csvon the server or volume. - Deploy frontend with
npm install && npm run build(you need a validfrontend/package.jsonin the repo for CI). - Point
REACT_APP_API_URLat the deployed API (HTTPS). Mapbox token in build env for the map tiles.
See also docs/DEPLOYMENT.md and docs/RAILWAY_DEPLOYMENT_GUIDE.md for host-specific steps.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- NASA for satellite data access
- Shark researchers for tracking data
- OpenAI for AI capabilities
- Mapbox for mapping services
For questions or issues, please open a GitHub issue or contact the development team.
π¦ Built with β€οΈ for marine conservation and shark research