# 🚀 Hugging Face Spaces Deployment Guide This guide will help you deploy your Dubsway Video AI system to Hugging Face Spaces via GitHub. ## 📋 Prerequisites 1. **GitHub Repository**: Your code should be pushed to a GitHub repository 2. **Hugging Face Account**: Create an account at [huggingface.co](https://huggingface.co) 3. **Environment Variables**: Set up your API keys and configuration ## 🔧 Step-by-Step Deployment ### 1. Prepare Your Repository Your repository should already have the necessary files: - `.huggingface.yaml` - Hugging Face Spaces configuration - `Dockerfile` - Container configuration - `requirements-hf.txt` - Optimized dependencies - `app/main.py` - FastAPI application ### 2. Set Up Environment Variables In your Hugging Face Space settings, add these environment variables: ```bash # Required for Groq LLM GROQ_API_KEY=your_groq_api_key_here # Database (use SQLite for simplicity) DATABASE_URL=sqlite+aiosqlite:///./dubsway_hf.db # AWS S3 (optional - for file storage) AWS_ACCESS_KEY_ID=your_aws_access_key AWS_SECRET_ACCESS_KEY=your_aws_secret_key AWS_REGION=us-east-1 S3_BUCKET_NAME=your_s3_bucket_name # Application SECRET_KEY=your_secret_key_here ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 # Environment ENVIRONMENT=production ``` ### 3. Create Hugging Face Space 1. Go to [huggingface.co/spaces](https://huggingface.co/spaces) 2. Click "Create new Space" 3. Choose settings: - **Owner**: Your username - **Space name**: `dubsway-video-ai` (or your preferred name) - **License**: MIT - **SDK**: Docker - **Visibility**: Public or Private ### 4. Connect GitHub Repository 1. In your Space settings, go to "Repository" tab 2. Select "Connect to existing repository" 3. Choose your GitHub repository 4. Set the branch (usually `main` or `master`) ### 5. Configure Build Settings The Space will automatically use: - `.huggingface.yaml` for configuration - `Dockerfile` for container build - `requirements-hf.txt` for dependencies ### 6. Deploy 1. Push your changes to GitHub 2. Hugging Face will automatically build and deploy 3. Monitor the build logs in your Space ## 🔍 Verification Once deployed, you can: 1. **Check the API**: Visit `https://your-username-dubsway-video-ai.hf.space/` 2. **View Documentation**: Visit `https://your-username-dubsway-video-ai.hf.space/docs` 3. **Health Check**: Visit `https://your-username-dubsway-video-ai.hf.space/health` ## 🛠️ API Endpoints Your deployed API will have these endpoints: - `GET /` - Root endpoint with API info - `GET /health` - Health check - `GET /docs` - Interactive API documentation - `POST /api/auth/register` - User registration - `POST /api/auth/login` - User login - `POST /api/upload/video` - Video upload and analysis - `GET /api/dashboard/videos` - Get user videos - `POST /api/custom-chatbot/chat` - Chat with video content ## 🔧 Troubleshooting ### Common Issues 1. **Build Failures**: - Check the build logs in your Space - Ensure all dependencies are in `requirements-hf.txt` - Verify Dockerfile syntax 2. **Environment Variables**: - Make sure all required env vars are set in Space settings - Check for typos in variable names 3. **Memory Issues**: - The Space uses CPU-only PyTorch to save memory - Consider using smaller models for production 4. **Database Issues**: - Use SQLite for simplicity in Spaces - Ensure database directory is writable ### Monitoring - Check Space logs for errors - Monitor resource usage - Test API endpoints regularly ## 🔄 Continuous Deployment Once connected to GitHub: 1. Push changes to your repository 2. Hugging Face automatically rebuilds and deploys 3. Monitor deployment status in your Space ## 📊 Performance Optimization For better performance in Hugging Face Spaces: 1. **Use CPU-only PyTorch**: Already configured in Dockerfile 2. **Optimize model loading**: Models are loaded on first request 3. **Use SQLite**: Lighter than PostgreSQL for Spaces 4. **Cache results**: Implement caching for repeated requests ## 🔐 Security Considerations 1. **API Keys**: Store sensitive keys in Space environment variables 2. **CORS**: Configure allowed origins for production 3. **Rate Limiting**: Implement rate limiting for public APIs 4. **Input Validation**: Validate all user inputs ## 📞 Support If you encounter issues: 1. Check the build logs in your Space 2. Review the troubleshooting section 3. Check Hugging Face Spaces documentation 4. Monitor your application logs --- **Happy Deploying! 🎉** Your Dubsway Video AI system will be accessible at: `https://your-username-dubsway-video-ai.hf.space/`