Skip to content

YeehawMcfly/SafeShip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐳 SafeShip - AI-Powered Marine Safety Platform

Real-time ship tracking + whale risk detection + Gemini AI insights to prevent ship-whale collisions.

πŸš€ Quick Setup (Windows)

Prerequisites

Step 1: Install Dependencies

Run the automated setup script to install all dependencies:

.\setup.bat

This will:

  • Install Node.js packages for backend & frontend
  • Install Python dependencies for ML service
  • Train the whale risk detection model

Step 2: Configure API Keys

  1. Navigate to backend folder
  2. Copy .env.template to .env:
    cd backend
    copy .env.template .env
  3. Edit .env and add your API keys:
    MST_API_KEY=your_myshiptracking_key_here
    GEMINI_API_KEY=your_gemini_api_key_here

Step 3: Start All Services

Run the startup script (uses fixed Python path for ML service):

.\start_fixed.ps1

This will launch:

  • 🐍 ML Service on http://localhost:5002 (Python Flask)
  • 🚒 Backend API on http://localhost:5001 (Node.js/Express)
  • 🌐 Frontend on http://localhost:5173 (React + Vite)

Step 4: Open the App

Navigate to http://localhost:5173 in your browser.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Frontend (React + Leaflet + Gemini UI)   β”‚  Port 5173
β”‚  - Interactive ship map                    β”‚
β”‚  - Real-time vessel tracking               β”‚
β”‚  - AI safety briefings                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Backend API     β”‚  β”‚  ML Service      β”‚
β”‚  (Node/TS)       β”‚  β”‚  (Python/Flask)  β”‚
β”‚  Port 5001       β”‚  β”‚  Port 5002       β”‚
β”‚                  β”‚  β”‚                  β”‚
β”‚ β€’ Ship tracking  β”‚  β”‚ β€’ Whale risk     β”‚
β”‚ β€’ Gemini AI      β”‚  β”‚   prediction     β”‚
β”‚ β€’ Route calc     β”‚  β”‚ β€’ GBM classifier β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                   β”‚
         β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ MyShipTracking   β”‚  β”‚ OBIS Whale Data  β”‚
β”‚ AIS API          β”‚  β”‚ (trained model)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Key Features

1. Real-Time Ship Tracking

  • Search vessels by name (e.g., "EVER GIVEN")
  • View ships near your location or in bounding box
  • Query ships in specific ports
  • Live AIS position updates

2. Whale Risk Detection (ML)

  • Predicts whale presence risk: HIGH / MEDIUM / LOW
  • Trained on OBIS-SEAMAP whale sighting dataset
  • Features: latitude, longitude, month (seasonal patterns)
  • ~85-90% accuracy

3. Gemini AI Safety Briefings (Multimodal)

  • Visual Analysis: AI sees the map screenshot (html2canvas)
  • Context-Aware: Integrates vessel data, track history, whale risk
  • Natural Language: Bridge crew briefings with actionable recommendations
  • Markdown Rendering: Beautiful formatted output

πŸ“‘ API Endpoints

Backend (Port 5001)

Ship Tracking:

  • GET /api/vessels/search/:name - Search vessels
  • GET /api/vessels/status/:mmsi - Current position (extended AIS data)
  • GET /api/vessels/track/:mmsi?days=1 - Historical track
  • GET /api/vessels/status/:mmsi/whale-risk - Position + risk

AI Insights:

  • POST /api/gemini/insight - Generate Gemini safety briefing
    {
      "ship": { "lat": 35.2, "lon": 139.5, "mmsi": "311918000", ... },
      "track": [...],
      "question": "What should the bridge team know?",
      "mapSnapshot": { "dataUrl": "data:image/png;base64,...", "mimeType": "image/png" }
    }

Whale Risk:

  • POST /api/whale-risk - Get risk for coordinates

ML Service (Port 5002)

  • POST /api/whale-risk - Risk prediction
    { "latitude": 40.7, "longitude": -74.0, "month": 11 }

🧠 Machine Learning Model

Algorithm: Gradient Boosting Classifier
Features: Latitude, Longitude, Month
Training Data: OBIS-SEAMAP whale sightings + synthetic migration patterns

Risk Thresholds:

  • πŸ”΄ HIGH (>60%): Reduce speed to <10 knots, post whale watch
  • 🟑 MEDIUM (30-60%): Exercise caution, brief crew
  • 🟒 LOW (<30%): Standard protocols

Model Files:

  • ml/whale_risk_model.pkl - Trained classifier
  • ml/train_whale_model.py - Training script
  • ml/whale_predictor.py - Standalone predictor

πŸ” Environment Variables

Backend (backend/.env)

PORT=5001
MST_API_KEY=your_myshiptracking_api_key
MST_CACHE_TTL_MS=30000
MST_DEFAULT_MINUTES_BACK=60
GEMINI_API_KEY=your_google_gemini_api_key
GEMINI_MODEL=gemini-2.0-flash-lite

ML Service

No configuration needed (port 5002 hardcoded).


πŸ“‚ Project Structure

/
β”œβ”€β”€ backend/                 # Node.js/TypeScript API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ classes/server.ts     # Express routes
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ mstClient.ts      # MyShipTracking client
β”‚   β”‚   β”‚   β”œβ”€β”€ whaleRiskService.ts
β”‚   β”‚   β”‚   └── geminiService.ts  # Gemini AI integration
β”‚   β”‚   └── index.ts
β”‚   β”œβ”€β”€ .env.template
β”‚   └── package.json
β”‚
β”œβ”€β”€ frontend/                # React + Vite
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/ShipMap.tsx  # Main map UI
β”‚   β”‚   β”œβ”€β”€ App.css                 # Styling
β”‚   β”‚   └── main.tsx
β”‚   └── package.json
β”‚
β”œβ”€β”€ ml/                      # Python Flask ML service
β”‚   β”œβ”€β”€ api.py                      # Flask server
β”‚   β”œβ”€β”€ train_whale_model.py        # Model training
β”‚   β”œβ”€β”€ whale_predictor.py          # Inference script
β”‚   β”œβ”€β”€ whale_risk_model.pkl        # Trained model
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ setup.bat                # Dependency installer
β”œβ”€β”€ start_fixed.ps1          # Startup script (all services)
└── README.md

πŸ› οΈ Development

Retrain ML Model

cd ml
python train_whale_model.py

Manual Service Startup

Backend:

cd backend
npm start

ML Service:

cd ml
python api.py

Frontend:

cd frontend
npm run dev

🎨 Tech Stack

  • Frontend: React, TypeScript, Leaflet, Vite, html2canvas, react-icons, marked
  • Backend: Node.js, Express, TypeScript, Axios, @google/generative-ai
  • ML: Python, Flask, scikit-learn, pandas, numpy
  • Data: MyShipTracking API (AIS), OBIS-SEAMAP (whale sightings)

πŸ† Hackathon Tracks

This project targets:

  • βœ… Best Use of Gemini API - Multimodal safety briefings with map visual analysis
  • βœ… Best UI/UX - Professional maritime dashboard with real-time updates
  • βœ… Most Creative Use of AI - Combining ML whale detection + Gemini contextual insights

πŸ“ License

MIT License - Hackathon project for marine conservation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors