Spaces:
Sleeping
Deploying to Hugging Face Spaces
This guide will help you deploy Video Genesis Studio to Hugging Face Spaces.
Prerequisites
Hugging Face Account
- Sign up at https://huggingface.co/join
- Verify your email
API Keys
- KIE API Key (required): https://kie.ai/api-key
- Optional: Gemini, OpenAI, Replicate keys
GitHub Repository
- Your code should be in a GitHub repository
- Or you can upload directly to Hugging Face
Step-by-Step Deployment
Option 1: Deploy from GitHub (Recommended)
Prepare Your Repository:
# Make sure Dockerfile.hf is in the root # Make sure README_HF.md exists (or rename it to README.md) git add Dockerfile.hf README_HF.md git commit -m "Add Hugging Face deployment files" git pushCreate a New Space:
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Fill in:
- Space name:
video-genesis-studio(or your choice) - SDK: Select Docker
- Visibility: Public or Private
- Hardware: CPU Basic (free) or upgrade for better performance
- Space name:
- Click "Create Space"
Connect Repository:
- In Space settings, go to "Repository" tab
- Click "Connect to GitHub"
- Select your repository
- Set Dockerfile path:
Dockerfile.hf - Save
Set Environment Variables:
- Go to "Variables and secrets" tab
- Add the following required variables:
KIE_API_KEY=your_kie_api_key_here VITE_API_BASE_URL=https://your-username-video-genesis-studio.hf.space ENVIRONMENT=production ALLOWED_USERS=admin:your-secure-password,user1:password123 JWT_SECRET_KEY=your-very-secure-random-secret-key-minimum-32-chars - Authentication Setup (Required):
ALLOWED_USERS: Format isusername1:password1,username2:password2JWT_SECRET_KEY: Generate a secure random key (see AUTH_SETUP.md)
- Optional variables:
VITE_GEMINI_API_KEY=your_gemini_key OPENAI_API_KEY=your_openai_key REPLICATE_API_TOKEN=your_replicate_token - Click "Save" after adding each variable
Note: See
AUTH_SETUP.mdfor detailed authentication configuration.Build Arguments:
- Go to "Settings" β "Build arguments"
- Add:
VITE_API_BASE_URL=https://your-username-video-genesis-studio.hf.space - This ensures the frontend knows the correct API URL
Deploy:
- Hugging Face will automatically build and deploy
- Watch the build logs in the "Logs" tab
- Wait for "Your Space is live!" message
Option 2: Upload Directly to Hugging Face
Create Space:
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Select Docker SDK
- Create the Space
Clone and Upload:
# Clone your Hugging Face Space git clone https://huggingface.co/spaces/your-username/video-genesis-studio cd video-genesis-studio # Copy your files cp -r /path/to/your/project/* . # Make sure Dockerfile.hf is named correctly # Rename README_HF.md to README.md mv README_HF.md README.md # Commit and push git add . git commit -m "Initial deployment" git pushSet Environment Variables (same as Option 1, step 4)
Configuration
Space Settings
Hardware:
- CPU Basic (Free): Good for testing, limited resources
- CPU Upgrade ($0.60/hour): Better performance
- GPU (if needed): For heavy video processing
Storage:
- Default: 50GB
- Upgrade if you need more for video storage
Environment Variables:
- Set in "Variables and secrets" tab
- Required:
KIE_API_KEY - Recommended:
VITE_API_BASE_URL(your Space URL)
Build Configuration
The Dockerfile.hf is configured to:
- Build React frontend with correct API URL
- Install Python dependencies
- Install FFmpeg for video processing
- Serve on port 7860 (Hugging Face default)
Frontend Configuration
The frontend is built with VITE_API_BASE_URL pointing to your Space URL. This is set via:
- Build argument in Dockerfile
- Environment variable during build
Verifying Deployment
Check Build Logs:
- Go to "Logs" tab in your Space
- Look for successful build messages
- Check for any errors
Test Health Endpoint:
- Visit:
https://your-space.hf.space/health - Should return JSON with status "healthy"
- Visit:
Test Frontend:
- Visit:
https://your-space.hf.space - Should load the React application
- Visit:
Test API Docs:
- Visit:
https://your-space.hf.space/docs - Should show Swagger UI
- Visit:
Troubleshooting
Build Fails
Issue: Build fails with npm errors
- Solution: Check that
frontend/package.jsonexists and is valid - Check build logs for specific error messages
Issue: Frontend build fails
- Solution: Ensure
VITE_API_BASE_URLis set correctly - Check that all frontend dependencies are in
package.json
App Not Loading
Issue: Frontend shows blank page
- Solution:
- Check browser console for errors
- Verify
VITE_API_BASE_URLmatches your Space URL - Check that frontend was built successfully (check logs)
Issue: API calls fail
- Solution:
- Verify
KIE_API_KEYis set correctly - Check API logs in Space logs
- Ensure CORS is configured (already set to allow all)
- Verify
Port Issues
Issue: App doesn't start
- Solution:
- Hugging Face uses port 7860 by default
- The Dockerfile is configured to use
PORTenv var - Check logs for port binding errors
Storage Issues
Issue: Videos not saving
- Solution:
- Check storage directory permissions
- Verify storage path exists
- Check available disk space
Updating Your Space
Make Changes:
# Make your code changes git add . git commit -m "Update app" git pushHugging Face Auto-Rebuilds:
- Spaces automatically rebuild on push
- Watch the logs for build progress
Manual Rebuild:
- Go to Space settings
- Click "Rebuild" if needed
Environment Variables Reference
| Variable | Required | Description |
|---|---|---|
KIE_API_KEY |
Yes | KIE API key for video generation |
ALLOWED_USERS |
Yes | User credentials: username1:pass1,username2:pass2 |
JWT_SECRET_KEY |
Yes | Secure random key for JWT signing (min 32 chars) |
VITE_API_BASE_URL |
Recommended | Your Space URL (for frontend) |
ENVIRONMENT |
No | Set to production |
VITE_GEMINI_API_KEY |
No | Gemini API key |
OPENAI_API_KEY |
No | OpenAI API key |
REPLICATE_API_TOKEN |
No | Replicate API token |
PORT |
Auto | Set by Hugging Face (7860) |
Cost Considerations
- Free Tier: CPU Basic, 50GB storage
- Paid Tiers:
- CPU Upgrade: $0.60/hour
- GPU options available
- Storage: Additional storage can be purchased
Security Notes
API Keys:
- Never commit API keys to your repository
- Use Hugging Face's "Variables and secrets" feature
- Keys are encrypted and only accessible to your Space
CORS:
- Currently set to allow all origins
- For production, consider restricting to your domain
Rate Limiting:
- Consider implementing rate limiting for public Spaces
- Monitor API usage
Authentication
Your app now requires login! See AUTH_SETUP.md for:
- Setting up user credentials
- Configuring JWT secret key
- Managing multiple users
- Security best practices
Quick Setup:
- Set
ALLOWED_USERSenvironment variable:admin:your-password,user1:pass1 - Set
JWT_SECRET_KEYto a secure random string (32+ characters) - Users will see a login page before accessing the app
Support
- Hugging Face Docs: https://huggingface.co/docs/hub/spaces
- Space Community: https://huggingface.co/spaces
- Issues: Check Space logs for errors
- Authentication: See
AUTH_SETUP.mdfor auth configuration
Next Steps
- β Deploy your Space
- β
Set environment variables (including
ALLOWED_USERSandJWT_SECRET_KEY) - β Test login functionality
- β Test the deployment
- β Share credentials with authorized users only
- β Monitor usage and performance
Your Video Genesis Studio is now live and secured on Hugging Face! ππ