Spaces:
Sleeping
Hugging Face Deployment Report
1. Project Analysis & What Was Checked
I have comprehensively analyzed the project specifically targeting a deployment to Hugging Face Spaces (Docker Plan). The free tier of Hugging Face Spaces provides up to 16GB of RAM, which is excellent to handle the YOLOv8 ML models yolov8n-pose.pt and pose_landmarker.task without crashing.
I reviewed the files you had already created:
Dockerfile: The existing Dockerfile correctly used thepython:3.11-slimbase image and properly installed the OpenCV system dependencies (libgl1,libglib2.0-0), which was perfect!.dockerignore: Found that it correctly ignores virtual environments, caches,.envfile, etc.config/settings.py: The core of the Django settings.requirements.txt: The python dependencies.
2. What I Updated
To make the deployment strictly compliant with Hugging Face's Docker Spaces architecture, I updated the following files:
Dockerfile
- Added
useradd -m -u 1000 user: Hugging Face runs their containers natively as a non-root user (id 1000). To avoid "Permission Denied" errors when runningpython manage.py collectstatic, an exact user needed to be defined. - Added
--chown=user: Ensured that the newly created user specifically owns the copied files and installed directories.
requirements.txt
- Added
gunicorn==21.2.0: Your production server framework. - Added
whitenoise==6.6.0: Required so your Django app can seamlessly serve static files without requiring an external Nginx server.
config/settings.py
- Security & Hosts: Replaced
ALLOWED_HOSTS = []withALLOWED_HOSTS = ['*']so Hugging Face infrastructure can correctly host your domain. - Form Submissions: Added
CSRF_TRUSTED_ORIGINS = ['https://*.hf.space']so POST requests (like uploading images inside the HF IFrame) are not rejected with 403 Forbidden errors. - Static Files: Confirmed the integration of
whitenoise.middleware.WhiteNoiseMiddleware.
3. Hugging Face Deployment Steps
You are now fully ready to deploy. Follow these precise steps:
- Create the Space: Go to Hugging Face Spaces and click Create new Space.
- Space Settings:
- Name:
virtual-dressing(or similar). - License: Optional (e.g., MIT).
- Select the Space SDK: Choose Docker, then choose the Blank template.
- Space Hardware: Select standard Free tier (16GB RAM, 2 vCPU).
- Name:
- Upload Files: Connect your local repository to the Space using
git remote add huggingface <YOUR_HF_CLONE_URL>, or manually upload all the project files into the Space's Files tab. - Environment Secrets: Once the files are uploaded, go to the Space's Settings tab. Scroll down to the Variables and secrets section and create New Secrets:
SECRET_KEY: Enter a random hard-to-guess string.DEBUG:FalseGEMINI_API_KEY: Your Google AI API key.
- View Logs: Wait for the container to say "Building". You can click on the 'Logs' button on the top right to watch Gunicorn boot up on port 7860.
- Once it says "Running", your Virtual Dressing app is deployed and live!
Note regarding ephemeral storage: Any photos users upload or models saved to the SQLite DB will wipe when the Space goes to sleep (usually after 48h of user inactivity). To make the database persist, you'll want to configure Hugging Face Persistent Storage via the settings later.
4. Current Core Project Structure
Your project is tightly structured for Docker deployment:
virtual_dressing/
βββ Dockerfile <-- Orchestrates the production setup
βββ .dockerignore <-- Keeps Docker image small and secure
βββ requirements.txt <-- Specifies needed dependencies
βββ manage.py
βββ db.sqlite3 <-- Database
βββ yolov8n-pose.pt <-- Heavy YOLO Weights
βββ pose_landmarker.task <-- MediaPipe Task weights
βββ appDataDir/ <-- Optional AI context & configuration
βββ config/ <-- Core Django Settings
β βββ settings.py <-- Configured for HF / Whitenoise
βββ fitting_system/ <-- Main App Logic
β βββ ai_modules/ <-- Integration with Gemini and YOLO
β βββ templates/ <-- HTML views (scan.html, store.html)
β βββ static/ <-- CSS / JS styles & scripts
β βββ models.py
β βββ views.py
βββ locale/ <-- Translations (Arabic/English)