Spaces:
Sleeping
Sleeping
File size: 5,026 Bytes
5fffedf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | # π Deployment Guide: Hugging Face Spaces
## Quick Start (5 minutes)
### Step 1: Prepare Your Repository
1. **Create a GitHub repository** with your project files
2. **Upload all files** from this directory to your GitHub repo
3. **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
1. **Go to** [huggingface.co/spaces](https://huggingface.co/spaces)
2. **Click** "Create new Space"
3. **Fill in the details**:
- **Owner**: Your HF username
- **Space name**: `ai-programming-tutor`
- **License**: Choose appropriate license
- **SDK**: Select **Streamlit**
- **Python version**: 3.10
4. **Click** "Create Space"
### Step 3: Connect Your Repository
1. **In your Space settings**, go to "Repository" tab
2. **Select** "GitHub repository"
3. **Choose** your GitHub repository
4. **Set the main file** to `app.py`
5. **Click** "Save"
### Step 4: Upload Your Fine-tuned Model
1. **In your Space**, go to "Files" tab
2. **Create a folder** called `model`
3. **Upload your fine-tuned model files**:
- `model-00001-of-00006.safetensors`
- `model-00002-of-00006.safetensors`
- `model-00003-of-00006.safetensors`
- `model-00004-of-00006.safetensors`
- `model-00005-of-00006.safetensors`
- `model-00006-of-00006.safetensors`
- `config.json`
- `tokenizer.json`
- `tokenizer.model`
- `tokenizer_config.json`
- `special_tokens_map.json`
- `generation_config.json`
### Step 5: Update Model Path
1. **Edit** `app.py` in your Space
2. **Change the model path** to:
```python
model_path = "./model" # Path to uploaded model
```
3. **Save** the changes
### Step 6: Deploy
1. **Your Space will automatically build** and deploy
2. **Wait for the build to complete** (5-10 minutes)
3. **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)
1. **In Space settings**, go to "Settings" tab
2. **Enable** "Custom domain"
3. **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.txt` for missing dependencies
- **Debug**: Review build logs
### Performance Optimization
1. **Enable GPU** in Space settings
2. **Use model quantization** for faster inference
3. **Implement caching** for repeated requests
4. **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
1. **Set Space to public** in settings
2. **Share the URL** with users
3. **Add to HF Spaces showcase**
### Embedding
```html
<iframe
src="https://huggingface.co/spaces/YOUR_USERNAME/ai-programming-tutor"
width="100%"
height="800px"
frameborder="0"
></iframe>
```
## π Security Considerations
1. **Input validation** for code submissions
2. **Rate limiting** to prevent abuse
3. **Content filtering** for inappropriate code
4. **User authentication** (optional)
## π Scaling
### For High Traffic
1. **Upgrade to Pro tier** for unlimited GPU
2. **Implement caching** with Redis
3. **Use load balancing** for multiple instances
4. **Monitor performance** and optimize
### For Production Use
1. **Add user authentication**
2. **Implement logging** and analytics
3. **Set up monitoring** and alerts
4. **Create backup** and recovery procedures
## π Success!
Your AI Programming Tutor is now live and accessible to students worldwide!
**Next steps**:
1. **Test thoroughly** with different code examples
2. **Gather user feedback** and iterate
3. **Share with your target audience**
4. **Monitor usage** and improve based on data
## π Support
- **Hugging Face Docs**: [docs.huggingface.co](https://docs.huggingface.co)
- **Spaces Documentation**: [huggingface.co/docs/hub/spaces](https://huggingface.co/docs/hub/spaces)
- **Community Forum**: [discuss.huggingface.co](https://discuss.huggingface.co) |