File size: 4,384 Bytes
02c6351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Diamond CSGO AI Player - Deployment Guide

## ๐Ÿš€ Deploying to Hugging Face Spaces

### Prerequisites
1. Hugging Face account
2. Model checkpoint files (`agent_epoch_00206.pt` or similar)
3. Git and Git LFS installed

### Step 1: Prepare Repository

1. **Clone/Fork this repository**
2. **Install Git LFS** (for large model files):
   ```bash
   git lfs install
   git lfs track "*.pt"
   git add .gitattributes
   ```

3. **Add your model checkpoint**:
   ```bash
   # Copy your trained model to the project root
   cp /path/to/your/agent_epoch_00206.pt .
   git add agent_epoch_00206.pt
   git commit -m "Add trained model checkpoint"
   ```

### Step 2: Create Hugging Face Space

1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
2. Click "Create new Space"
3. Configure:
   - **Space name**: `diamond-csgo-ai` (or your choice)
   - **License**: Your preferred license
   - **Space SDK**: `Docker` 
   - **Space hardware**: 
     - `CPU basic` (free) - for demo/testing
     - `GPU T4 small` (paid) - for better performance

### Step 3: Upload Code

```bash
# Clone your new space
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME

# Copy all project files
cp -r /path/to/diamond/* .

# Commit and push
git add .
git commit -m "Initial Diamond CSGO AI deployment"
git push
```

### Step 4: Configuration Files

Ensure these files are in your space root:

- `app.py` - Main FastAPI application
- `requirements.txt` - Python dependencies  
- `Dockerfile` - Container configuration
- `README.md` - Space description
- `packages.txt` - System packages (if needed)

### Step 5: Model Setup

If your model is too large for Git (>100MB), use Git LFS or download from Hub:

```python
# In your app.py, add model downloading:
from huggingface_hub import hf_hub_download

def download_model():
    return hf_hub_download(
        repo_id="YOUR_USERNAME/YOUR_MODEL_REPO",
        filename="agent_epoch_00206.pt"
    )
```

## ๐Ÿ”ง Local Testing

Before deploying, test locally:

```bash
# Install dependencies
pip install -r requirements.txt

# Run tests
python test_web_app.py

# Start local server
python run_web_demo.py
```

Visit `http://localhost:7860` to test the interface.

## โš™๏ธ Configuration Options

### Hardware Requirements

| Tier | CPU | RAM | GPU | Performance |
|------|-----|-----|-----|-------------|
| Free | 2 vCPU | 16GB | None | Basic demo |
| Basic GPU | 4 vCPU | 16GB | T4 | Good performance |
| Premium | 8 vCPU | 32GB | A10G | Best experience |

### Environment Variables

Add these in your Space settings:
- `CUDA_VISIBLE_DEVICES=""` (for CPU-only)
- `PYTHONPATH="/app/src:/app"`

## ๐ŸŽฎ Usage Instructions

Once deployed, users can:

1. Visit your Space URL
2. Click on the game canvas
3. Use keyboard controls:
   - **WASD** - Movement
   - **Space** - Jump  
   - **Arrow keys** - Camera
   - **1,2,3** - Weapons
   - **R** - Reload
   - **M** - Switch Human/AI mode

## ๐Ÿ› Troubleshooting

### Common Issues

1. **Model not loading**:
   - Check checkpoint file exists
   - Verify file size (<5GB for Spaces)
   - Use Git LFS for large files

2. **Import errors**:
   - Check `requirements.txt` is complete
   - Verify Python path in `Dockerfile`

3. **Performance issues**:
   - Use GPU hardware tier
   - Reduce model complexity
   - Lower frame rate

4. **WebSocket connection failed**:
   - Check firewall settings
   - Verify port 7860 is accessible
   - Try different browser

### Debug Mode

Enable debug logging:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

## ๐Ÿ“Š Monitoring

Monitor your Space:
- View logs in HF Spaces interface
- Check GPU utilization
- Monitor user sessions

## ๐Ÿ”„ Updates

To update your deployed Space:
```bash
git pull  # Get latest changes
git add .
git commit -m "Update to latest version"
git push  # Automatically redeploys
```

## ๐Ÿ’ก Tips for Success

1. **Start with CPU tier** to test basic functionality
2. **Use smaller models** for faster loading
3. **Test thoroughly locally** before deploying
4. **Monitor resource usage** to optimize costs
5. **Add usage instructions** in your Space README

## ๐ŸŽฏ Next Steps

After successful deployment:
- Share your Space with the community
- Collect user feedback
- Iterate on the interface
- Add new features like replay saving
- Consider multi-user support

Happy deploying! ๐Ÿš€