Sanjay / HUGGINGFACE_DEPLOYMENT.md
TheDeepDas's picture
Docker
6c9c901

πŸš€ Hugging Face Spaces Deployment Guide

πŸ“ Files Created for Docker Deployment:

  • Dockerfile - Main Docker configuration
  • requirements-docker.txt - Optimized dependencies for Docker
  • .dockerignore - Excludes unnecessary files from build
  • start-hf.sh - Startup script for Hugging Face Spaces
  • README.md - Hugging Face Spaces metadata

πŸ”§ Deployment Steps:

1. Create New Hugging Face Space

  1. Go to Hugging Face Spaces
  2. Click "Create new Space"
  3. Choose:
    • Space name: marine-guard-api
    • License: MIT
    • SDK: Docker
    • Hardware: CPU basic (free tier)

2. Upload Backend Files

Upload these files to your Hugging Face Space:

Dockerfile
requirements-docker.txt
start-hf.sh
README.md
app/
β”œβ”€β”€ __init__.py
β”œβ”€β”€ main.py
β”œβ”€β”€ config.py
β”œβ”€β”€ database.py
β”œβ”€β”€ dependencies.py
β”œβ”€β”€ schemas.py
β”œβ”€β”€ core_security.py
β”œβ”€β”€ routers/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ auth.py
β”‚   └── incidents.py
└── services/
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ incidents.py
    β”œβ”€β”€ ml_model.py
    β”œβ”€β”€ nlp.py
    └── users.py
models/
β”œβ”€β”€ threat_model.pkl
└── severity_model.pkl

3. Set Environment Variables in Hugging Face

In your Space settings, add these environment variables:

MONGODB_URI=mongodb+srv://deepdblm_db_user:IqLKnKhwLLSOP1Ka@cluster0.0u1vpow.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
JWT_SECRET_KEY=your-secure-secret-key-here
ALLOWED_ORIGINS=https://marine-pollution-detection.vercel.app,http://localhost:3000

4. Update Frontend Configuration

Once deployed, update your frontend .env file:

VITE_API_BASE_URL=https://your-username-marine-guard-api.hf.space/api

🎯 Expected URLs:

  • API Base: https://your-username-marine-guard-api.hf.space
  • Health Check: https://your-username-marine-guard-api.hf.space/health
  • Auth Endpoint: https://your-username-marine-guard-api.hf.space/api/auth/login

πŸ” Troubleshooting:

  • Check the Logs tab in your Hugging Face Space for any errors
  • Ensure all environment variables are set correctly
  • The space will take 2-3 minutes to build and start
  • Models will be loaded automatically on startup

πŸ“Š Features Included:

  • βœ… FastAPI backend with all endpoints
  • βœ… MongoDB Atlas connection
  • βœ… JWT authentication
  • βœ… ML model inference (threat & severity classification)
  • βœ… CORS configured for Vercel frontend
  • βœ… Health check endpoint
  • βœ… Automatic model loading on startup