Spaces:
Sleeping
Sleeping
Commit Β·
95b078e
1
Parent(s): 6c9c901
Docker
Browse files- Dockerfile +1 -1
- README.md +84 -1
Dockerfile
CHANGED
|
@@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
# Copy requirements first for better caching
|
| 19 |
-
COPY requirements
|
| 20 |
|
| 21 |
# Install Python dependencies
|
| 22 |
RUN pip install --no-cache-dir --upgrade pip
|
|
|
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
# Copy requirements first for better caching
|
| 19 |
+
COPY requirements.txt .
|
| 20 |
|
| 21 |
# Install Python dependencies
|
| 22 |
RUN pip install --no-cache-dir --upgrade pip
|
README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
title: Marine Guard API
|
| 2 |
emoji: π
|
| 3 |
colorFrom: blue
|
|
@@ -5,4 +6,86 @@ colorTo: green
|
|
| 5 |
sdk: docker
|
| 6 |
pinned: false
|
| 7 |
license: mit
|
| 8 |
-
app_port: 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
title: Marine Guard API
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
+
app_port: 7860
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Marine Guard API π
|
| 13 |
+
|
| 14 |
+
FastAPI backend for the Marine Pollution Detection and Incident Management System.
|
| 15 |
+
|
| 16 |
+
## π Features
|
| 17 |
+
|
| 18 |
+
- π **JWT Authentication** - Secure user registration and login
|
| 19 |
+
- π€ **ML-Powered Classification** - AI incident analysis with 87.8% threat accuracy, 81.0% severity accuracy
|
| 20 |
+
- ποΈ **MongoDB Atlas Integration** - Cloud database with graceful fallback
|
| 21 |
+
- π **CORS-Enabled** - Ready for frontend integration
|
| 22 |
+
- π₯ **Health Monitoring** - Built-in health checks and monitoring
|
| 23 |
+
- π **Interactive API Docs** - Swagger UI available at `/docs`
|
| 24 |
+
|
| 25 |
+
## π― API Endpoints
|
| 26 |
+
|
| 27 |
+
### Authentication
|
| 28 |
+
- `POST /api/auth/register` - User registration
|
| 29 |
+
- `POST /api/auth/login` - User login
|
| 30 |
+
|
| 31 |
+
### Incidents
|
| 32 |
+
- `GET /api/incidents` - Get user incidents (requires auth)
|
| 33 |
+
- `POST /api/incidents` - Create new incident (requires auth)
|
| 34 |
+
- `POST /api/incidents/classify` - Classify incident text using ML
|
| 35 |
+
|
| 36 |
+
### Monitoring
|
| 37 |
+
- `GET /health` - Health check endpoint
|
| 38 |
+
- `GET /` - API status
|
| 39 |
+
|
| 40 |
+
## π§ Environment Variables
|
| 41 |
+
|
| 42 |
+
Set these in your Hugging Face Spaces environment:
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
MONGODB_URI=your_mongodb_atlas_connection_string
|
| 46 |
+
JWT_SECRET_KEY=your_secure_secret_key
|
| 47 |
+
ALLOWED_ORIGINS=https://your-frontend-domain.com
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## π€ ML Model Details
|
| 51 |
+
|
| 52 |
+
### Threat Classification Model
|
| 53 |
+
- **Accuracy**: 87.8%
|
| 54 |
+
- **Classes**: Oil, Chemical, Other
|
| 55 |
+
- **Algorithm**: TF-IDF + Random Forest
|
| 56 |
+
|
| 57 |
+
### Severity Classification Model
|
| 58 |
+
- **Accuracy**: 81.0%
|
| 59 |
+
- **Classes**: high, medium, low
|
| 60 |
+
- **Algorithm**: TF-IDF + Random Forest
|
| 61 |
+
|
| 62 |
+
### Fallback System
|
| 63 |
+
- Automatic rule-based classification if ML models unavailable
|
| 64 |
+
- Confidence scores provided for all predictions
|
| 65 |
+
|
| 66 |
+
## π± Frontend Integration
|
| 67 |
+
|
| 68 |
+
This API is designed to work with the Marine Pollution Detection frontend. Set your frontend's API base URL to:
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
VITE_API_BASE_URL=https://your-space-name.hf.space/api
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## π οΈ Development
|
| 75 |
+
|
| 76 |
+
Built with:
|
| 77 |
+
- **FastAPI** 0.115.2 - Modern Python web framework
|
| 78 |
+
- **Motor** - Async MongoDB driver
|
| 79 |
+
- **scikit-learn** - Machine learning models
|
| 80 |
+
- **Pydantic** - Data validation
|
| 81 |
+
- **Passlib** - Password hashing
|
| 82 |
+
- **PyJWT** - JSON Web Token handling
|
| 83 |
+
|
| 84 |
+
## π Health & Monitoring
|
| 85 |
+
|
| 86 |
+
The API includes comprehensive health checking:
|
| 87 |
+
- Database connectivity testing
|
| 88 |
+
- Model loading verification
|
| 89 |
+
- Graceful degradation for service issues
|
| 90 |
+
|
| 91 |
+
Visit `/health` for real-time status information.
|