Spaces:
Sleeping
Sleeping
π Hugging Face Spaces Deployment Guide
π Files Created for Docker Deployment:
Dockerfile- Main Docker configurationrequirements-docker.txt- Optimized dependencies for Docker.dockerignore- Excludes unnecessary files from buildstart-hf.sh- Startup script for Hugging Face SpacesREADME.md- Hugging Face Spaces metadata
π§ Deployment Steps:
1. Create New Hugging Face Space
- Go to Hugging Face Spaces
- Click "Create new Space"
- Choose:
- Space name:
marine-guard-api - License: MIT
- SDK: Docker
- Hardware: CPU basic (free tier)
- Space name:
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