Spaces:
Sleeping
Sleeping
π Deployment Guide: Hugging Face Spaces
Quick Start (5 minutes)
Step 1: Prepare Your Repository
- Create a GitHub repository with your project files
- Upload all files from this directory to your GitHub repo
- Make sure you have:
app.py(main Streamlit app)fine.py(AI tutor implementation)requirements.txt(dependencies)README.md(documentation)
Step 2: Create Hugging Face Space
- Go to huggingface.co/spaces
- Click "Create new Space"
- Fill in the details:
- Owner: Your HF username
- Space name:
ai-programming-tutor - License: Choose appropriate license
- SDK: Select Streamlit
- Python version: 3.10
- Click "Create Space"
Step 3: Connect Your Repository
- In your Space settings, go to "Repository" tab
- Select "GitHub repository"
- Choose your GitHub repository
- Set the main file to
app.py - Click "Save"
Step 4: Upload Your Fine-tuned Model
- In your Space, go to "Files" tab
- Create a folder called
model - Upload your fine-tuned model files:
model-00001-of-00006.safetensorsmodel-00002-of-00006.safetensorsmodel-00003-of-00006.safetensorsmodel-00004-of-00006.safetensorsmodel-00005-of-00006.safetensorsmodel-00006-of-00006.safetensorsconfig.jsontokenizer.jsontokenizer.modeltokenizer_config.jsonspecial_tokens_map.jsongeneration_config.json
Step 5: Update Model Path
- Edit
app.pyin your Space - Change the model path to:
model_path = "./model" # Path to uploaded model - Save the changes
Step 6: Deploy
- Your Space will automatically build and deploy
- Wait for the build to complete (5-10 minutes)
- Your app will be live at:
https://huggingface.co/spaces/YOUR_USERNAME/ai-programming-tutor
π― Advanced Configuration
Hardware Settings
- CPU: Default (sufficient for inference)
- GPU: T4 (recommended for faster inference)
- Memory: 16GB+ (required for 7B model)
Environment Variables
Add these in your Space settings:
TOKENIZERS_PARALLELISM=false
DATASETS_DISABLE_MULTIPROCESSING=1
Custom Domain (Optional)
- In Space settings, go to "Settings" tab
- Enable "Custom domain"
- Add your domain (e.g.,
tutor.yourdomain.com)
π§ Troubleshooting
Common Issues
Issue: Model not loading
- Solution: Check model path and file structure
- Debug: Look at Space logs in "Settings" β "Logs"
Issue: Out of memory
- Solution: Upgrade to GPU hardware
- Alternative: Use demo mode
Issue: Build fails
- Solution: Check
requirements.txtfor missing dependencies - Debug: Review build logs
Performance Optimization
- Enable GPU in Space settings
- Use model quantization for faster inference
- Implement caching for repeated requests
- Add rate limiting to prevent abuse
π Monitoring
Usage Analytics
- View usage in Space settings
- Monitor performance with built-in metrics
- Track user engagement through logs
Cost Management
- Free tier: 16 hours/month GPU time
- Pro tier: $9/month for unlimited GPU
- Enterprise: Custom pricing
π Sharing Your App
Public Access
- Set Space to public in settings
- Share the URL with users
- Add to HF Spaces showcase
Embedding
<iframe
src="https://huggingface.co/spaces/YOUR_USERNAME/ai-programming-tutor"
width="100%"
height="800px"
frameborder="0"
></iframe>
π Security Considerations
- Input validation for code submissions
- Rate limiting to prevent abuse
- Content filtering for inappropriate code
- User authentication (optional)
π Scaling
For High Traffic
- Upgrade to Pro tier for unlimited GPU
- Implement caching with Redis
- Use load balancing for multiple instances
- Monitor performance and optimize
For Production Use
- Add user authentication
- Implement logging and analytics
- Set up monitoring and alerts
- Create backup and recovery procedures
π Success!
Your AI Programming Tutor is now live and accessible to students worldwide!
Next steps:
- Test thoroughly with different code examples
- Gather user feedback and iterate
- Share with your target audience
- Monitor usage and improve based on data
π Support
- Hugging Face Docs: docs.huggingface.co
- Spaces Documentation: huggingface.co/docs/hub/spaces
- Community Forum: discuss.huggingface.co