CoolFace
Apppublic

GaneshArihanth/Vessel-Oil-Spill-Detection-API

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
App README

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

🚒 Vessel Anomaly Detection System

Empowering Maritime Intelligence with Real-Time Data & AI-Powered Surveillance

Vessel Anomaly Detection is a comprehensive maritime tracking and analysis platform designed to provide real-time insights into vessel movements, environmental conditions, and AI-driven Oil Spill Detection. By integrating multiple data sources (Satellite, Weather, AIS), it offers a holistic view of maritime activities, aiding in navigation, ecological monitoring, and decision-making.

The application features a modern React frontend with glowing interactive cards, a Node.js backend for data orchestration, and a Python/Flask Microservice for deep-learning-based oil spill analysis.

![License: ISC](https://opensource.org/licenses/ISC) ![React](https://react.dev/) ![PyTorch](https://pytorch.org/) ![Hugging Face](https://huggingface.co/) ![Node.js](https://nodejs.org/) ![MongoDB](https://www.mongodb.com/) ![Tailwind CSS](https://tailwindcss.com/)


🧐 What is this Project? (For Beginners)

Imagine Google Maps for ships, but with a superpower: it can automatically detect Oil Spills from space using Artificial Intelligence.

This application does three main things:

  1. 1.Tracks Ships: It finds out where a ship is right now using its unique ID (like a license plate).
  2. 2.Sees from Space: It captures a satellite photo of that exact location.
  3. 3.Detects Pollution: It uses a "Brain" (AI Model) to scan that photo. If it sees an oil spill, it highlights it in red and warns us.

πŸ“š Glossary: Key Terms Explained

Before you dive into the technical details, here are some terms you might see:

  • β€”MMSI (Maritime Mobile Service Identity):
  • β€”Think of it as: A Phone Number for a ship. Every ship has a unique 9-digit number. We use this to find them.
  • β€”AIS (Automatic Identification System):
  • β€”Think of it as: GPS for ships. Ships constantly broadcast "I am here!" signals. We listen to these to know their location.
  • β€”Semantic Segmentation (The AI Part):
  • β€”Think of it as: A Digital Highlighter. Instead of just saying "There is oil," our AI colors the exact pixels of the image where the oil is, separating it from the water.
  • β€”API (Application Programming Interface):
  • β€”Think of it as: A Waiter in a restaurant. We (the customer) ask the waiter (API) for data (food) from the kitchen (Server), and they bring it back to us.

🌟 Key Features

πŸ–₯️ Modern User Interface

  • β€”Interactive Dashboard: A sleek, dark-themed dashboard with glowing card effects (Aceternity UI).
  • β€”Visual Analytics: Real-time visualization of vessel status, weather, and AI analysis.

πŸ“ Core Functionality

  • β€”Real-Time Vessel Tracking: Track vessels globally by MMSI or Name (via RapidAPI/MarineTraffic).
  • β€”πŸ›°οΈ Satellite Visuals: Fetch high-res satellite imagery from Mapbox for the vessel's current coordinates.
  • β€”πŸŒ€οΈ Live Weather: Real-time environmental data (Wind, Temp, Pressure) from OpenWeatherMap.

🧠 AI Oil Spill Detection (New!)

  • β€”Deep Learning Model: Uses DeepLabV3+ (ResNet50 encoder) to segment oil spills from satellite imagery.
  • β€”Real-Time Inference: Analyzes satellite images on-the-fly to detect potential anomalies.
  • β€”Visual Overlay: Generates a grayscale analysis map with Red Highlights for detected spills.
  • β€”Risk Assessment: Calculates confidence score and percentage of oil coverage.

βš™οΈ Backend & Performance

  • β€”Smart Caching (MongoDB): Caches vessel data for 24 hours to minimize API costs and rate limits.
  • β€”Microservice Architecture: Decouples the heavy ML inference (Python) from the main application logic (Node.js).
  • β€”Mock Data Engine: Includes a resilient fallback system. If external APIs (AIS/Weather) are down or rate-limited, the system automatically serves realistic "Mock Data" to ensure the UI never breaks during demos.

πŸ“– User Manual: How to Use

Once the app is running (see Quick Start), here is how to play with it:

1. The Search Bar

  • β€”Search by Name: Type a ship name like COMPASS or EVER GIVEN.
  • β€”Search by ID: Type a 9-digit MMSI number (e.g., 244110352).
  • β€”Tip: If you don't know any ships, just click "Search" with the default example to see a demo.

2. The Dashboard Cards

  • β€”πŸš’ Vessel Details: Shows the static info (Flag, Dimensions, Type).
  • β€”πŸ“ Live Position: Shows coordinates. Updates every few seconds if the ship is moving.
  • β€”πŸŒ€οΈ Weather: Real-time wind and temperature at that exact spot in the ocean.
  • β€”πŸ›°οΈ Satellite View: The coolest part! It pulls the latest available satellite shot.

3. Interpreting the AI Analysis

The bottom card shows the Oil Spill Analysis.

  • β€”βœ… No Spill Detected:
  • β€”Status: Green Badge.
  • β€”Meaning: The AI looked at the water and saw only water.
  • β€”βš οΈ OIL SPILL DETECTED:
  • β€”Status: Red Flashing Badge.
  • β€”Visual: You will see a Red Heatmap overlaid on the satellite image.
  • β€”Action: This indicates a high probability of pollution.

πŸ—οΈ Architecture

The system uses a Microservices approach. Think of it as a team working together:

ComponentRoleAnalogyTech Stack
FrontendThe FaceThe Waiter who shows you the menu.React 19, Vite, Tailwind CSS
BackendThe ManagerThe Kitchen Manager who organizes orders.Node.js, Express, MongoDB
ML ServiceThe BrainThe Specialist Chef who cooks the AI dish.Python, Flask, PyTorch

πŸ“‚ Folder Structure

Vessel-Tracking/
β”œβ”€β”€ frontend/             # 🎨 React + Vite Frontend
β”‚   β”œβ”€β”€ src/components/   # UI Components (GlowingEffect, Boxes)
β”‚   └── src/App.jsx       # Main Dashboard UI
β”œβ”€β”€ final-version/        # πŸš€ Node.js Backend (API Gateway)
β”‚   β”œβ”€β”€ server.js         # Express Server & caching logic
β”‚   └── db.js             # MongoDB Schema & Connection
β”œβ”€β”€ hf_space/             # 🧠 Deployment Bundle (All-in-One)
β”‚   β”œβ”€β”€ app.py            # Combined Python Backend (ML + Logic)
β”‚   β”œβ”€β”€ Dockerfile        # Container config for Hugging Face
β”‚   β”œβ”€β”€ static/           # Built Frontend Assets
β”‚   └── templates/        # Frontend HTML
β”œβ”€β”€ Model/                # πŸ§ͺ Local ML Environment
β”‚   β”œβ”€β”€ api.py            # Local Flask Interface for Model
β”‚   └── deeplabv3p_best.pth # Trained Model Weights
β”œβ”€β”€ package.json          # Root configuration
└── vercel.json           # Vercel Configuration

πŸ§ͺ Technical Deep Dive

Why did we choose this specific tech stack?

1. The AI Model: DeepLabV3+

We didn't just pick any model; we chose DeepLabV3+ because oil spills have irregular shapes and sizes.

  • β€”Why?: It uses Atrous Spatial Pyramid Pooling (ASPP).
  • β€”Translation: It looks at the image with "different sized glasses" (zoom levels) simultaneously. This allows it to spot tiny oil leaks AND massive spills in the same image.

2. Frontend: React 19 + Vite

  • β€”Why?: Speed. Traditional React apps can be slow to load.
  • β€”Vite: Uses modern browser features to serve files instantly, making the dashboard feel "native" and snappy.
  • β€”Aceternity UI: We used this library to give the "Glowing Glass" effect, which looks futuristic and matches the maritime theme.

3. Database: MongoDB with TTL

  • β€”Problem: Storing every ship location forever would fill up the database in days.
  • β€”Solution: TTL (Time-To-Live) Indexes.
  • β€”How it works: We tell MongoDB, "Delete any record that is older than 24 hours". This keeps our database small, free, and fast, acting like a self-cleaning cache.

πŸš€ Deployment Options

You can deploy this project in two ways:

Option 1: Hugging Face Spaces (All-in-One) 🌟 Recommended

Host the Entire Application (Frontend + Backend + ML) in a single Docker container.

  1. 1.Create a Space: Go to Hugging Face and create a new Space with the Docker SDK.
  2. 2.Upload Files: Upload the contents of the hf_space/ directory.
  3. 3.Important: Ensure deeplabv3p_best.pth is included.
  4. 4.Environment Variables: Set the following secrets in your Space settings:
  5. 5.MONGO_URI, MAPBOX_ACCESS_TOKEN, WEATHER_API_KEY, RAPIDAPI_KEY
  6. 6.Run: The Space will build and serve your app on port 7860.

Option 2: Vercel + Hugging Face (Split)

Host Frontend/Backend on Vercel and ML Service on Hugging Face.

  1. 1.ML Service: Deploy hf_space/ to Hugging Face (Port 7860).
  2. 2.Frontend/Backend: Deploy the root repo to Vercel.
  3. 3.Set ML_SERVICE_URL in Vercel to your Hugging Face Space URL.

πŸ› οΈ Local Setup (Quick Start)

We will set this up using 3 separate terminals, because each part of the "Team" needs its own space to run.

Prerequisites

  • β€”Node.js (v18+) & npm
  • β€”Python (3.9+)
  • β€”MongoDB Atlas URI
  • β€”API Keys (Mapbox, OpenWeatherMap, RapidAPI)

1. Install Dependencies & Setup

Terminal 1: The Brain (ML Service)

bash
python -m venv venv
source venv/bin/activate   # (Windows: venv\Scripts\activate)
pip install -r hf_space/requirements.txt
# Run the ML API
python Model/api.py

Runs on Port 5001

Terminal 2: The Manager (Backend)

bash
cd final-version
npm install
# Create .env file here with your API Keys
node server.js

Runs on Port 3000

Terminal 3: The Face (Frontend)

bash
cd frontend
npm install
npm run dev

Runs on Port 5173. Click the link to view the app!


πŸ“‘ API Endpoints

GET /api/vessel-position

Returns vessel data + ML analysis.

Params: ?name=COMPASS or ?name=244110352 (MMSI)

Response:

json
{
  "name": "COMPASS",
  "mmsi": "244110352",
  "latitude": 53.259,
  "longitude": 6.497,
  "satelliteImage": "<base64>",
  "oilSpillData": {
    "is_spill": true,
    "confidence": 0.89,
    "analysisImage": "<base64_overlay>"
  }
}

❓ Troubleshooting

1. "Loading..." Forever / Black Screen

  • β€”Cause: The Frontend cannot talk to the Backend.
  • β€”Fix: Check Terminal 2. Is the server running? Did it crash?

2. 405 Method Not Allowed on Hugging Face

  • β€”Cause: The static file handler is catching the API request.
  • β€”Fix: Ensure app.route('/predict') is defined before app.route('/<path:path>') in app.py. (Fixed in V3).

3. Missing API Keys / Mock Data

  • β€”Symptoms: Weather says "N/A" or "Mock Data".
  • β€”Fix: The system automatically switches to Mock Data if keys are missing to prevent crashing. Double-check your .env file to see real data.

πŸ—ΊοΈ Future Roadmap

We are constantly improving! Here is what's coming next:

  • β€”[ ] πŸ”” SMS/Email Alerts: Automatically notify authorities when a spill > 50% confidence is detected.
  • β€”[ ] βͺ Historical Playback: A "Time Slider" to watch a ship's path over the last 30 days.
  • β€”[ ] πŸ›°οΈ Multi-Satellite Support: Integration with Sentinel-1 (Radar). Radar can see oil spills even through clouds and at night!
  • β€”[ ] πŸ“± Mobile App: A React Native version for Coast Guard officers on patrol.

πŸ‘€ Author

Ganesh Arihanth