File size: 6,057 Bytes
ec4c5af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Hugging Face Space Setup Guide

## Understanding Your Repositories

You have **TWO** separate repositories:

### 1. Model Repository: `nitish-spz/ABTestPredictor`
- **Purpose**: Store the model files
- **Contains**: 
  - `multimodal_gated_model_2.7_GGG.pth` (789 MB)
  - `multimodal_cat_mappings_GGG.json`
- **Access**: Read-only, Space downloads from here

### 2. Space Repository: `SpiralyzeLLC/ABTestPredictor`
- **Purpose**: Run the Gradio application
- **Contains**: All application code + downloads model from repo #1
- **Access**: This is what deploys and runs

## Required Files in Space Repository

Your Space needs these files (but NOT the large model file):

```
βœ… app.py                          # Main application code
βœ… requirements.txt                # Python dependencies  
βœ… packages.txt                    # System dependencies (tesseract-ocr)
βœ… README.md                       # Project documentation
βœ… confidence_scores.json          # Confidence data (14KB)
βœ… .gitattributes                  # Git LFS config
βœ… .dockerignore                   # Build optimization
❌ model/ folder                   # NOT needed - downloads from model repo
❌ patterbs.json                   # NOT needed - removed feature
❌ metadata.js                     # NOT needed - removed feature
❌ confidence_scores.js            # NOT needed - use .json instead
```

## How the Model Loading Works

Your `app.py` is configured to:
1. Check if model exists locally in `model/` folder
2. If not, download from `nitish-spz/ABTestPredictor` model repository
3. Cache it for future use

```python
# In app.py lines 707-748
if os.path.exists(MODEL_SAVE_PATH):
    model_path = MODEL_SAVE_PATH
    print(f"βœ… Using local model")
else:
    print(f"πŸ“₯ Downloading from Model Hub...")
    model_path = download_model_from_hub()
```

## Deployment Steps

### Step 1: Verify Required Files Exist Locally
```bash
cd /Users/nitish/Spiralyze/HuggingFace/Spaces/ABTestPredictor

# Check essential files
ls -lh app.py requirements.txt packages.txt README.md confidence_scores.json

# Should all exist
```

### Step 2: Remove Large/Unnecessary Files
```bash
# Remove the local model folder (Space will download from model repo)
rm -rf model/

# Remove unused files from old version
rm -f patterbs.json metadata.js confidence_scores.js frontend.html index_v2.html
```

### Step 3: Verify Git Remote Points to Space
```bash
git remote -v
# Should show: https://huggingface.co/spaces/SpiralyzeLLC/ABTestPredictor
```

### Step 4: Commit and Push to Space
```bash
# Add all files
git add .

# Commit
git commit -m "Deploy: Add all application files, download model from hub"

# Push to Space
git push origin main
```

### Step 5: Monitor Build
1. Go to https://huggingface.co/spaces/SpiralyzeLLC/ABTestPredictor
2. Click "Logs" tab
3. Watch the build progress
4. First build takes 5-10 minutes (downloading model)

## If Build Fails

### Check These Files Exist in Space Repo:
```bash
# Essential files checklist
app.py                  βœ…
requirements.txt        βœ…
packages.txt           βœ…
README.md              βœ…
confidence_scores.json βœ…
.dockerignore          βœ…
.gitattributes         βœ…
```

### Verify Model Repo is Accessible
Your app downloads from `nitish-spz/ABTestPredictor`. Verify:
1. Go to https://huggingface.co/nitish-spz/ABTestPredictor
2. Check files are visible
3. Make sure it's **public** (not private)

### Check requirements.txt
```bash
cat requirements.txt
```
Should contain:
```
torch
transformers
pandas
scikit-learn
Pillow
gradio
pytesseract
spaces
huggingface_hub
python-dotenv
```

### Check packages.txt
```bash
cat packages.txt
```
Should contain:
```
tesseract-ocr
```

## Common Issues

### Issue 1: "Model file not found"
**Cause**: Model repo is private or inaccessible
**Fix**: Make `nitish-spz/ABTestPredictor` public

### Issue 2: "No module named X"
**Cause**: Missing dependency in requirements.txt
**Fix**: Add the missing package to requirements.txt

### Issue 3: "Tesseract not found"
**Cause**: Missing system dependency
**Fix**: Ensure packages.txt contains `tesseract-ocr`

### Issue 4: Build hangs at "Installing requirements"
**Cause**: PyTorch is large (~2GB)
**Fix**: Wait 5-10 minutes, this is normal

## Space Configuration

Your Space should have these settings:
- **SDK**: Gradio
- **SDK Version**: 4.44.0
- **Hardware**: GPU (recommended: T4 or better)
- **Python Version**: 3.10 (default)
- **Visibility**: Public or Private (your choice)

## File Size Limits

- **Space repo**: Each file < 50MB (except LFS)
- **Model repo**: Files > 10MB should use Git LFS
- **Total Space size**: No hard limit, but keep it reasonable

## Success Indicators

βœ… Build completes without errors
βœ… Space status shows "Running"  
βœ… Can access the Gradio interface
βœ… Making predictions returns results
βœ… Logs show "Successfully loaded model"

## Expected First-Run Behavior

```
πŸš€ Using device: cuda
πŸ”₯ GPU: Tesla T4
πŸ“₯ Model not found locally, downloading from Model Hub...
πŸ“₯ Downloading model from Hugging Face Model Hub: nitish-spz/ABTestPredictor
βœ… Model downloaded to: /home/user/.cache/huggingface/...
βœ… Successfully loaded GGG model weights
βœ… Model and processors loaded successfully.
Running on public URL: https://spiralyzellc-abtestpredictor.hf.space
```

## Testing After Deployment

### Test 1: Web Interface
1. Visit your Space URL
2. Upload test images
3. Select categories
4. Click predict
5. Should see results in ~3-5 seconds

### Test 2: API Client
```python
from gradio_client import Client

client = Client("SpiralyzeLLC/ABTestPredictor")
result = client.predict(
    "control.jpg",
    "variant.jpg", 
    "SaaS", "B2B", "High-Intent Lead Gen",
    "B2B Software & Tech", "Awareness & Discovery",
    api_name="/predict_with_categorical_data"
)
print(result)
```

## Need Help?

1. Check Space logs for errors
2. Review DEPLOYMENT_FIX.md for detailed troubleshooting
3. Verify all required files are in Space repo
4. Ensure model repo is public and accessible