nitish-spz commited on
Commit
5b49b49
·
1 Parent(s): ec4c5af

Mapping of grouped metadata

Browse files
API_DOCUMENTATION.md ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A/B Test Predictor API Documentation
2
+
3
+ Welcome! This API predicts A/B test outcomes using multimodal AI analysis of your control and variant images combined with business context data.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ### Installation
8
+
9
+ ```bash
10
+ pip install gradio-client pillow
11
+ ```
12
+
13
+ ### Basic Example
14
+
15
+ ```python
16
+ from gradio_client import Client
17
+
18
+ # Connect to the API
19
+ client = Client("SpiralyzeLLC/ABTestPredictor")
20
+
21
+ # Make a prediction
22
+ result = client.predict(
23
+ "path/to/control.jpg",
24
+ "path/to/variant.jpg",
25
+ "SaaS", # Business Model
26
+ "B2B", # Customer Type
27
+ "High-Intent Lead Gen", # Conversion Type
28
+ "B2B Software & Tech", # Industry
29
+ "Awareness & Discovery", # Page Type
30
+ api_name="/predict_with_categorical_data"
31
+ )
32
+
33
+ print(f"Win Probability: {result['predictionResults']['probability']}")
34
+ print(f"Confidence: {result['predictionResults']['modelConfidence']}%")
35
+ ```
36
+
37
+ ## 📋 API Reference
38
+
39
+ ### Endpoint
40
+
41
+ ```
42
+ /predict_with_categorical_data
43
+ ```
44
+
45
+ ### Input Parameters
46
+
47
+ | Parameter | Type | Required | Description |
48
+ |-----------|------|----------|-------------|
49
+ | `control_image` | Image File | Yes | Control version image (JPG, PNG) |
50
+ | `variant_image` | Image File | Yes | Variant version image (JPG, PNG) |
51
+ | `business_model` | String | Yes | Business model type |
52
+ | `customer_type` | String | Yes | Target customer type |
53
+ | `conversion_type` | String | Yes | Type of conversion |
54
+ | `industry` | String | Yes | Business industry |
55
+ | `page_type` | String | Yes | Type of page being tested |
56
+
57
+ ### Valid Category Values
58
+
59
+ #### Business Model
60
+ - `E-Commerce`
61
+ - `Lead Generation`
62
+ - `Other*`
63
+ - `SaaS`
64
+
65
+ #### Customer Type
66
+ - `B2B`
67
+ - `B2C`
68
+ - `Both`
69
+ - `Other*`
70
+
71
+ #### Conversion Type
72
+
73
+ **🎯 New Feature**: The API now accepts both **parent group values** (listed below) AND **specific values** (e.g., "Request Demo/Contact Sales"). Specific values are automatically converted to their parent groups.
74
+
75
+ **Parent Groups** (model uses these internally):
76
+ - `Direct Purchase`
77
+ - `High-Intent Lead Gen`
78
+ - `Info/Content Lead Gen`
79
+ - `Location Search`
80
+ - `Non-Profit/Community`
81
+ - `Other Conversion`
82
+
83
+ **Example Specific Values** (automatically mapped):
84
+ - `Request Demo/Contact Sales` → `High-Intent Lead Gen`
85
+ - `Buy Now` → `Direct Purchase`
86
+ - `Download Asset / App` → `Info/Content Lead Gen`
87
+ - See `mapping.json` for complete list
88
+
89
+ #### Industry
90
+
91
+ **🎯 New Feature**: The API now accepts both **parent group values** (listed below) AND **specific values** (e.g., "Accounting Services"). Specific values are automatically converted to their parent groups.
92
+
93
+ **Parent Groups** (model uses these internally):
94
+ - `Automotive & Transportation`
95
+ - `B2B Services`
96
+ - `B2B Software & Tech`
97
+ - `Consumer Services`
98
+ - `Consumer Software & Apps`
99
+ - `Education`
100
+ - `Finance, Insurance & Real Estate`
101
+ - `Food, Hospitality & Travel`
102
+ - `Health & Wellness`
103
+ - `Industrial & Manufacturing`
104
+ - `Media & Entertainment`
105
+ - `Non-Profit & Government`
106
+ - `Other`
107
+ - `Retail & E-commerce`
108
+
109
+ **Example Specific Values** (automatically mapped):
110
+ - `Accounting Services` → `B2B Services`
111
+ - `Marketing Agency` → `B2B Services`
112
+ - `Cybersecurity` → `B2B Software & Tech`
113
+ - `Healthcare Software` → `B2B Software & Tech`
114
+ - See `mapping.json` for complete list (200+ specific industries supported)
115
+
116
+ #### Page Type
117
+
118
+ **🎯 New Feature**: The API now accepts both **parent group values** (listed below) AND **specific values** (e.g., "Homepage"). Specific values are automatically converted to their parent groups.
119
+
120
+ **Parent Groups** (model uses these internally):
121
+ - `Awareness & Discovery`
122
+ - `Consideration & Evaluation`
123
+ - `Conversion`
124
+ - `Internal & Navigation`
125
+ - `Post-Conversion & Other`
126
+
127
+ **Example Specific Values** (automatically mapped):
128
+ - `Homepage` → `Awareness & Discovery`
129
+ - `Pricing Page` → `Consideration & Evaluation`
130
+ - `Checkout` → `Conversion`
131
+ - `Login` → `Internal & Navigation`
132
+ - See `mapping.json` for complete list
133
+
134
+ ### Response Format
135
+
136
+ ```json
137
+ {
138
+ "predictionResults": {
139
+ "probability": "0.682",
140
+ "modelConfidence": "66.1",
141
+ "trainingDataSamples": 14634,
142
+ "totalPredictions": 1626,
143
+ "correctPredictions": 1074,
144
+ "totalWinPrediction": 667,
145
+ "totalLosePrediction": 959
146
+ },
147
+ "providedCategories": {
148
+ "businessModel": "SaaS",
149
+ "customerType": "B2B",
150
+ "conversionType": "Request Demo/Contact Sales",
151
+ "industry": "Cybersecurity",
152
+ "pageType": "Homepage"
153
+ },
154
+ "groupedCategories": {
155
+ "businessModel": "SaaS",
156
+ "customerType": "B2B",
157
+ "conversionType": "High-Intent Lead Gen",
158
+ "industry": "B2B Software & Tech",
159
+ "pageType": "Awareness & Discovery"
160
+ },
161
+ "processingInfo": {
162
+ "totalProcessingTime": "2.34s",
163
+ "confidenceSource": "B2B Software & Tech | Awareness & Discovery"
164
+ }
165
+ }
166
+ ```
167
+
168
+ #### Response Fields
169
+
170
+ **predictionResults**
171
+ - `probability`: Win probability for variant (0-1 scale, >0.5 means variant wins)
172
+ - `modelConfidence`: Model accuracy percentage for this category combination
173
+ - `trainingDataSamples`: Training samples used for this category
174
+ - `totalPredictions`: Total test predictions for this category
175
+ - `correctPredictions`: Correct predictions for this category
176
+ - `totalWinPrediction`: Actual wins in historical data
177
+ - `totalLosePrediction`: Actual losses in historical data
178
+
179
+ **providedCategories**
180
+ - Echo of input categorical data (as provided by you)
181
+
182
+ **groupedCategories** *(New!)*
183
+ - The parent group values used by the model for prediction
184
+ - Shows how specific values were mapped to parent groups
185
+ - This is what the model actually uses internally
186
+
187
+ **processingInfo**
188
+ - `totalProcessingTime`: API processing time
189
+ - `confidenceSource`: Category combination used for confidence scoring
190
+
191
+ ## 🔄 Automatic Value Mapping
192
+
193
+ ### How It Works
194
+
195
+ The API now automatically converts specific categorical values to their parent groups using the `mapping.json` file. This means you can send more specific data (e.g., "Accounting Services", "Homepage", "Request Demo/Contact Sales") and the API will handle the conversion automatically.
196
+
197
+ **Benefits:**
198
+ - ✅ More flexibility in input data
199
+ - ✅ No need to pre-process your data
200
+ - ✅ API handles the conversion automatically
201
+ - ✅ Both original and grouped values returned in response
202
+
203
+ ### Mapping Examples
204
+
205
+ #### Industry Mapping
206
+ ```
207
+ "Accounting Services" → "B2B Services"
208
+ "Marketing Agency" → "B2B Services"
209
+ "Cybersecurity" → "B2B Software & Tech"
210
+ "CRM Software" → "B2B Software & Tech"
211
+ "Healthcare" → "Health & Wellness"
212
+ "Hotels" → "Food, Hospitality & Travel"
213
+ ```
214
+
215
+ #### Page Type Mapping
216
+ ```
217
+ "Homepage" → "Awareness & Discovery"
218
+ "Blog / Content" → "Awareness & Discovery"
219
+ "Pricing Page" → "Consideration & Evaluation"
220
+ "Demo Squeeze" → "Consideration & Evaluation"
221
+ "Checkout" → "Conversion"
222
+ "Contact Sales" → "Conversion"
223
+ "Login" → "Internal & Navigation"
224
+ ```
225
+
226
+ #### Conversion Type Mapping
227
+ ```
228
+ "Request Demo/Contact Sales" → "High-Intent Lead Gen"
229
+ "Start Free Trial/Signup" → "High-Intent Lead Gen"
230
+ "Buy Now" → "Direct Purchase"
231
+ "Subscription (No Free Trial)" → "Direct Purchase"
232
+ "Download Asset / App" → "Info/Content Lead Gen"
233
+ "Register for Webinar/Event" → "Info/Content Lead Gen"
234
+ ```
235
+
236
+ ### Using Specific Values in API Calls
237
+
238
+ **Example with specific values:**
239
+ ```python
240
+ result = client.predict(
241
+ "control.jpg",
242
+ "variant.jpg",
243
+ "SaaS", # Business Model (no mapping needed)
244
+ "B2B", # Customer Type (no mapping needed)
245
+ "Request Demo/Contact Sales", # Will be mapped to "High-Intent Lead Gen"
246
+ "Cybersecurity", # Will be mapped to "B2B Software & Tech"
247
+ "Homepage", # Will be mapped to "Awareness & Discovery"
248
+ api_name="/predict_with_categorical_data"
249
+ )
250
+ ```
251
+
252
+ **Response will include both:**
253
+ ```json
254
+ {
255
+ "providedCategories": {
256
+ "conversionType": "Request Demo/Contact Sales",
257
+ "industry": "Cybersecurity",
258
+ "pageType": "Homepage"
259
+ },
260
+ "groupedCategories": {
261
+ "conversionType": "High-Intent Lead Gen",
262
+ "industry": "B2B Software & Tech",
263
+ "pageType": "Awareness & Discovery"
264
+ }
265
+ }
266
+ ```
267
+
268
+ ## 💻 Code Examples
269
+
270
+ ### Python
271
+
272
+ #### Complete Example with Error Handling
273
+
274
+ ```python
275
+ from gradio_client import Client
276
+ from PIL import Image
277
+ import json
278
+
279
+ def predict_abtest(control_path, variant_path, categories):
280
+ """
281
+ Predict A/B test outcome
282
+
283
+ Args:
284
+ control_path: Path to control image
285
+ variant_path: Path to variant image
286
+ categories: Dict with business_model, customer_type, etc.
287
+
288
+ Returns:
289
+ dict: Prediction results
290
+ """
291
+ try:
292
+ # Initialize client
293
+ client = Client("SpiralyzeLLC/ABTestPredictor")
294
+
295
+ # Make prediction
296
+ result = client.predict(
297
+ control_path,
298
+ variant_path,
299
+ categories['business_model'],
300
+ categories['customer_type'],
301
+ categories['conversion_type'],
302
+ categories['industry'],
303
+ categories['page_type'],
304
+ api_name="/predict_with_categorical_data"
305
+ )
306
+
307
+ return {
308
+ 'success': True,
309
+ 'data': result
310
+ }
311
+
312
+ except Exception as e:
313
+ return {
314
+ 'success': False,
315
+ 'error': str(e)
316
+ }
317
+
318
+ # Usage
319
+ categories = {
320
+ 'business_model': 'SaaS',
321
+ 'customer_type': 'B2B',
322
+ 'conversion_type': 'High-Intent Lead Gen',
323
+ 'industry': 'B2B Software & Tech',
324
+ 'page_type': 'Awareness & Discovery'
325
+ }
326
+
327
+ result = predict_abtest('control.jpg', 'variant.jpg', categories)
328
+
329
+ if result['success']:
330
+ prob = result['data']['predictionResults']['probability']
331
+ conf = result['data']['predictionResults']['modelConfidence']
332
+
333
+ print(f"✅ Prediction: {prob}")
334
+ print(f"📊 Confidence: {conf}%")
335
+
336
+ if float(prob) > 0.5:
337
+ print("🎉 Variant is predicted to WIN")
338
+ else:
339
+ print("⚠️ Control is predicted to win")
340
+ else:
341
+ print(f"❌ Error: {result['error']}")
342
+ ```
343
+
344
+ #### Batch Processing Multiple Tests
345
+
346
+ ```python
347
+ from gradio_client import Client
348
+ import time
349
+
350
+ def batch_predict(test_cases):
351
+ """Process multiple A/B tests"""
352
+ client = Client("SpiralyzeLLC/ABTestPredictor")
353
+ results = []
354
+
355
+ for i, test in enumerate(test_cases):
356
+ print(f"Processing test {i+1}/{len(test_cases)}...")
357
+
358
+ try:
359
+ result = client.predict(
360
+ test['control_image'],
361
+ test['variant_image'],
362
+ test['business_model'],
363
+ test['customer_type'],
364
+ test['conversion_type'],
365
+ test['industry'],
366
+ test['page_type'],
367
+ api_name="/predict_with_categorical_data"
368
+ )
369
+
370
+ results.append({
371
+ 'test_id': i + 1,
372
+ 'status': 'success',
373
+ 'result': result
374
+ })
375
+
376
+ except Exception as e:
377
+ results.append({
378
+ 'test_id': i + 1,
379
+ 'status': 'failed',
380
+ 'error': str(e)
381
+ })
382
+
383
+ # Rate limiting
384
+ time.sleep(1)
385
+
386
+ return results
387
+
388
+ # Usage
389
+ tests = [
390
+ {
391
+ 'control_image': 'test1_control.jpg',
392
+ 'variant_image': 'test1_variant.jpg',
393
+ 'business_model': 'SaaS',
394
+ 'customer_type': 'B2B',
395
+ 'conversion_type': 'High-Intent Lead Gen',
396
+ 'industry': 'B2B Software & Tech',
397
+ 'page_type': 'Awareness & Discovery'
398
+ },
399
+ # Add more tests...
400
+ ]
401
+
402
+ results = batch_predict(tests)
403
+ print(f"Completed {len(results)} predictions")
404
+ ```
405
+
406
+ ### JavaScript/Node.js
407
+
408
+ ```javascript
409
+ const axios = require('axios');
410
+ const fs = require('fs');
411
+
412
+ async function predictABTest(controlPath, variantPath, categories) {
413
+ const apiUrl = 'https://spiralyzellc-abtestpredictor.hf.space/api/predict';
414
+
415
+ // Read and encode images
416
+ const controlImage = fs.readFileSync(controlPath);
417
+ const variantImage = fs.readFileSync(variantPath);
418
+
419
+ const controlB64 = `data:image/jpeg;base64,${controlImage.toString('base64')}`;
420
+ const variantB64 = `data:image/jpeg;base64,${variantImage.toString('base64')}`;
421
+
422
+ // Prepare payload
423
+ const payload = {
424
+ data: [
425
+ controlB64,
426
+ variantB64,
427
+ categories.businessModel,
428
+ categories.customerType,
429
+ categories.conversionType,
430
+ categories.industry,
431
+ categories.pageType
432
+ ]
433
+ };
434
+
435
+ try {
436
+ const response = await axios.post(apiUrl, payload, {
437
+ headers: { 'Content-Type': 'application/json' },
438
+ timeout: 30000
439
+ });
440
+
441
+ return {
442
+ success: true,
443
+ data: response.data.data[0]
444
+ };
445
+ } catch (error) {
446
+ return {
447
+ success: false,
448
+ error: error.message
449
+ };
450
+ }
451
+ }
452
+
453
+ // Usage
454
+ const categories = {
455
+ businessModel: 'SaaS',
456
+ customerType: 'B2B',
457
+ conversionType: 'High-Intent Lead Gen',
458
+ industry: 'B2B Software & Tech',
459
+ pageType: 'Awareness & Discovery'
460
+ };
461
+
462
+ predictABTest('control.jpg', 'variant.jpg', categories)
463
+ .then(result => {
464
+ if (result.success) {
465
+ console.log('Win Probability:', result.data.predictionResults.probability);
466
+ console.log('Confidence:', result.data.predictionResults.modelConfidence + '%');
467
+ } else {
468
+ console.error('Error:', result.error);
469
+ }
470
+ });
471
+ ```
472
+
473
+ ### cURL
474
+
475
+ ```bash
476
+ #!/bin/bash
477
+
478
+ # Encode images to base64
479
+ CONTROL_B64=$(base64 -i control.jpg)
480
+ VARIANT_B64=$(base64 -i variant.jpg)
481
+
482
+ # Make API request
483
+ curl -X POST "https://spiralyzellc-abtestpredictor.hf.space/api/predict" \
484
+ -H "Content-Type: application/json" \
485
+ -d '{
486
+ "data": [
487
+ "data:image/jpeg;base64,'"${CONTROL_B64}"'",
488
+ "data:image/jpeg;base64,'"${VARIANT_B64}"'",
489
+ "SaaS",
490
+ "B2B",
491
+ "High-Intent Lead Gen",
492
+ "B2B Software & Tech",
493
+ "Awareness & Discovery"
494
+ ]
495
+ }' | jq '.'
496
+ ```
497
+
498
+ ## 🔧 Best Practices
499
+
500
+ ### Image Requirements
501
+
502
+ - **Format**: JPG, PNG, or JPEG
503
+ - **Size**: Recommended < 5MB per image
504
+ - **Resolution**: Minimum 800x600px recommended
505
+ - **Content**: Should show the actual page/element being tested
506
+
507
+ ### Rate Limiting
508
+
509
+ - **Recommended**: 1 request per second
510
+ - **Maximum**: No hard limit, but please be respectful
511
+ - Add delays between batch requests
512
+
513
+ ### Error Handling
514
+
515
+ Always wrap API calls in try-catch blocks:
516
+
517
+ ```python
518
+ try:
519
+ result = client.predict(...)
520
+ except Exception as e:
521
+ # Handle timeout, network errors, invalid inputs
522
+ print(f"API Error: {e}")
523
+ ```
524
+
525
+ ### Interpreting Results
526
+
527
+ **Win Probability**
528
+ - `> 0.5`: Variant predicted to win
529
+ - `< 0.5`: Control predicted to win
530
+ - `~ 0.5`: Too close to call
531
+
532
+ **Model Confidence**
533
+ - `> 70%`: High confidence
534
+ - `60-70%`: Moderate confidence
535
+ - `< 60%`: Lower confidence (less historical data for this category)
536
+
537
+ **Training Data Samples**
538
+ - `> 1000`: Robust category with lots of data
539
+ - `100-1000`: Moderate data available
540
+ - `< 100`: Limited data, prediction may be less reliable
541
+
542
+ ## 🐛 Common Issues
543
+
544
+ ### Issue: "Connection timeout"
545
+ **Solution**: Increase timeout to 30-60 seconds for first request (model loads)
546
+
547
+ ```python
548
+ client = Client("SpiralyzeLLC/ABTestPredictor")
549
+ # First call might be slower due to model loading
550
+ ```
551
+
552
+ ### Issue: "Invalid category value"
553
+ **Solution**: Ensure exact match with valid values (case-sensitive)
554
+
555
+ ```python
556
+ # ✅ Correct
557
+ business_model = "SaaS"
558
+
559
+ # ❌ Wrong
560
+ business_model = "saas" # Wrong case
561
+ business_model = "Software as a Service" # Not in valid list
562
+ ```
563
+
564
+ ### Issue: "Image file not found"
565
+ **Solution**: Use absolute paths or verify file exists
566
+
567
+ ```python
568
+ import os
569
+
570
+ control_path = os.path.abspath("control.jpg")
571
+ if not os.path.exists(control_path):
572
+ print(f"File not found: {control_path}")
573
+ ```
574
+
575
+ ## 📊 Understanding Confidence Scores
576
+
577
+ Confidence scores are based on **Industry + Page Type** combinations from historical A/B test data:
578
+
579
+ - **High Sample Count** (>1000 samples): More reliable predictions
580
+ - **Low Sample Count** (<100 samples): Less reliable, use with caution
581
+ - **Accuracy**: Historical accuracy for this specific category combination
582
+
583
+ The model has been trained on thousands of real A/B tests, so confidence scores reflect actual performance on similar tests.
584
+
585
+ ## 🌐 Web Interface
586
+
587
+ You can also use the web interface:
588
+
589
+ **URL**: https://huggingface.co/spaces/SpiralyzeLLC/ABTestPredictor
590
+
591
+ 1. Upload control and variant images
592
+ 2. Select categories from dropdowns
593
+ 3. Click "Predict"
594
+ 4. View results in JSON format
595
+
596
+ ## 📝 Example Use Cases
597
+
598
+ ### 1. Pre-Test Analysis
599
+ Predict outcome before running expensive A/B tests
600
+
601
+ ### 2. Batch Analysis
602
+ Analyze multiple test variations to pick the best candidate
603
+
604
+ ### 3. Historical Analysis
605
+ Compare predictions with actual results to calibrate decisions
606
+
607
+ ### 4. Integration
608
+ Embed in your testing platform or analytics dashboard
609
+
610
+ ## 🆘 Support
611
+
612
+ **Issues?**
613
+ - Check the [Common Issues](#-common-issues) section
614
+ - Verify your inputs match the [Valid Category Values](#valid-category-values)
615
+ - Ensure images are valid and readable
616
+
617
+ **Questions?**
618
+ - Open an issue on the Hugging Face Space
619
+ - Check the example code for reference implementations
620
+
621
+ ## 📜 License
622
+
623
+ This API is provided for research and commercial use. Please use responsibly.
624
+
625
+ ---
626
+
627
+ **API Version**: 1.0
628
+ **Last Updated**: October 31, 2025
629
+ **Model**: Multimodal Siamese Network (GGG Enhanced)
630
+ **Hosted on**: Hugging Face Spaces
631
+
COMPLETE_EXAMPLE_WITH_MAPPING.py ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Complete Example: Using the A/B Test Predictor API with Automatic Mapping
3
+
4
+ This example demonstrates how to use the updated API that accepts both
5
+ specific and parent group values for Industry, Page Type, and Conversion Type.
6
+
7
+ The API now automatically converts specific values to parent groups using
8
+ mapping.json before feeding them to the model.
9
+ """
10
+
11
+ from gradio_client import Client
12
+
13
+ def predict_ab_test_with_specific_values():
14
+ """
15
+ Example showing how to use SPECIFIC values.
16
+ The API will automatically map them to parent groups.
17
+ """
18
+ print("=" * 80)
19
+ print("EXAMPLE 1: Using Specific Values (NEW FEATURE)")
20
+ print("=" * 80)
21
+ print()
22
+
23
+ # Initialize the client
24
+ client = Client("SpiralyzeLLC/ABTestPredictor")
25
+
26
+ # Make prediction with SPECIFIC values
27
+ # These will be automatically converted to parent groups
28
+ result = client.predict(
29
+ "path/to/control.jpg",
30
+ "path/to/variant.jpg",
31
+ "SaaS", # Business Model (no mapping needed)
32
+ "B2B", # Customer Type (no mapping needed)
33
+ "Request Demo/Contact Sales", # Will map to: High-Intent Lead Gen
34
+ "Cybersecurity", # Will map to: B2B Software & Tech
35
+ "Homepage", # Will map to: Awareness & Discovery
36
+ api_name="/predict_with_categorical_data"
37
+ )
38
+
39
+ print("📥 INPUT:")
40
+ print(f" Industry: {result['providedCategories']['industry']}")
41
+ print(f" Page Type: {result['providedCategories']['pageType']}")
42
+ print(f" Conversion Type: {result['providedCategories']['conversionType']}")
43
+ print()
44
+
45
+ print("🔄 AUTO-MAPPED TO:")
46
+ print(f" Industry: {result['groupedCategories']['industry']}")
47
+ print(f" Page Type: {result['groupedCategories']['pageType']}")
48
+ print(f" Conversion Type: {result['groupedCategories']['conversionType']}")
49
+ print()
50
+
51
+ print("🎯 PREDICTION RESULTS:")
52
+ print(f" Win Probability: {result['predictionResults']['probability']}")
53
+ print(f" Model Confidence: {result['predictionResults']['modelConfidence']}%")
54
+ print(f" Training Samples: {result['predictionResults']['trainingDataSamples']}")
55
+ print()
56
+
57
+ return result
58
+
59
+
60
+ def predict_ab_test_with_parent_groups():
61
+ """
62
+ Example showing traditional usage with parent groups.
63
+ This still works exactly as before (backward compatible).
64
+ """
65
+ print("=" * 80)
66
+ print("EXAMPLE 2: Using Parent Groups (TRADITIONAL METHOD)")
67
+ print("=" * 80)
68
+ print()
69
+
70
+ client = Client("SpiralyzeLLC/ABTestPredictor")
71
+
72
+ # Make prediction with PARENT GROUP values
73
+ result = client.predict(
74
+ "path/to/control.jpg",
75
+ "path/to/variant.jpg",
76
+ "SaaS",
77
+ "B2B",
78
+ "High-Intent Lead Gen", # Parent group value
79
+ "B2B Software & Tech", # Parent group value
80
+ "Awareness & Discovery", # Parent group value
81
+ api_name="/predict_with_categorical_data"
82
+ )
83
+
84
+ print("📥 INPUT (Parent Groups):")
85
+ print(f" Industry: {result['providedCategories']['industry']}")
86
+ print(f" Page Type: {result['providedCategories']['pageType']}")
87
+ print(f" Conversion Type: {result['providedCategories']['conversionType']}")
88
+ print()
89
+
90
+ print("🎯 PREDICTION RESULTS:")
91
+ print(f" Win Probability: {result['predictionResults']['probability']}")
92
+ print(f" Model Confidence: {result['predictionResults']['modelConfidence']}%")
93
+ print()
94
+
95
+ return result
96
+
97
+
98
+ def batch_predictions_with_mixed_values():
99
+ """
100
+ Example showing batch processing with mixed values
101
+ (some specific, some parent groups).
102
+ """
103
+ print("=" * 80)
104
+ print("EXAMPLE 3: Batch Processing with Mixed Values")
105
+ print("=" * 80)
106
+ print()
107
+
108
+ client = Client("SpiralyzeLLC/ABTestPredictor")
109
+
110
+ test_cases = [
111
+ {
112
+ "name": "E-commerce Checkout Test",
113
+ "business_model": "E-Commerce",
114
+ "customer_type": "B2C",
115
+ "conversion_type": "Buy Now", # Specific → Direct Purchase
116
+ "industry": "Apparel & Accessories ", # Specific → Retail & E-commerce
117
+ "page_type": "Checkout" # Specific → Conversion
118
+ },
119
+ {
120
+ "name": "SaaS Pricing Page Test",
121
+ "business_model": "SaaS",
122
+ "customer_type": "B2B",
123
+ "conversion_type": "High-Intent Lead Gen", # Parent group
124
+ "industry": "B2B Software & Tech", # Parent group
125
+ "page_type": "Pricing Page" # Specific → Consideration & Evaluation
126
+ },
127
+ {
128
+ "name": "Healthcare Portal Test",
129
+ "business_model": "Lead Generation",
130
+ "customer_type": "B2C",
131
+ "conversion_type": "Request Information", # Specific → Info/Content Lead Gen
132
+ "industry": "Healthcare", # Specific → Health & Wellness
133
+ "page_type": "Contact Us" # Specific → Conversion
134
+ }
135
+ ]
136
+
137
+ results = []
138
+
139
+ for i, test in enumerate(test_cases):
140
+ print(f"📊 Test {i+1}: {test['name']}")
141
+ print(f" Input: {test['industry']} | {test['page_type']} | {test['conversion_type']}")
142
+
143
+ # Note: In a real scenario, you'd provide actual image paths
144
+ result = client.predict(
145
+ f"control_{i}.jpg",
146
+ f"variant_{i}.jpg",
147
+ test['business_model'],
148
+ test['customer_type'],
149
+ test['conversion_type'],
150
+ test['industry'],
151
+ test['page_type'],
152
+ api_name="/predict_with_categorical_data"
153
+ )
154
+
155
+ print(f" Mapped: {result['groupedCategories']['industry']} | "
156
+ f"{result['groupedCategories']['pageType']} | "
157
+ f"{result['groupedCategories']['conversionType']}")
158
+ print(f" Probability: {result['predictionResults']['probability']}")
159
+ print()
160
+
161
+ results.append(result)
162
+
163
+ return results
164
+
165
+
166
+ def mapping_reference_guide():
167
+ """
168
+ Quick reference guide showing common mappings.
169
+ """
170
+ print("=" * 80)
171
+ print("MAPPING REFERENCE GUIDE")
172
+ print("=" * 80)
173
+ print()
174
+
175
+ print("📌 COMMON INDUSTRY MAPPINGS:")
176
+ industry_mappings = {
177
+ "Accounting Services": "B2B Services",
178
+ "Marketing Agency": "B2B Services",
179
+ "Consulting Services": "B2B Services",
180
+ "Cybersecurity": "B2B Software & Tech",
181
+ "CRM Software": "B2B Software & Tech",
182
+ "Marketing Automation Software": "B2B Software & Tech",
183
+ "Healthcare": "Health & Wellness",
184
+ "Pharmaceuticals": "Health & Wellness",
185
+ "Hotels, Lodging, Resorts and Cruises": "Food, Hospitality & Travel",
186
+ "Restaurants, Food & Beverage": "Food, Hospitality & Travel",
187
+ "Real Estate": "Finance, Insurance & Real Estate",
188
+ "Insurance": "Finance, Insurance & Real Estate"
189
+ }
190
+
191
+ for specific, parent in industry_mappings.items():
192
+ print(f" '{specific}' → '{parent}'")
193
+ print()
194
+
195
+ print("📌 COMMON PAGE TYPE MAPPINGS:")
196
+ page_mappings = {
197
+ "Homepage": "Awareness & Discovery",
198
+ "Blog / Content": "Awareness & Discovery",
199
+ "Features Page": "Awareness & Discovery",
200
+ "Pricing Page": "Consideration & Evaluation",
201
+ "Demo Squeeze": "Consideration & Evaluation",
202
+ "Product Page (PDP)": "Consideration & Evaluation",
203
+ "Checkout": "Conversion",
204
+ "Contact Sales": "Conversion",
205
+ "Signup": "Conversion",
206
+ "Login": "Internal & Navigation",
207
+ "Navigation": "Internal & Navigation",
208
+ "Thank You": "Post-Conversion & Other"
209
+ }
210
+
211
+ for specific, parent in page_mappings.items():
212
+ print(f" '{specific}' → '{parent}'")
213
+ print()
214
+
215
+ print("📌 COMMON CONVERSION TYPE MAPPINGS:")
216
+ conversion_mappings = {
217
+ "Request Demo/Contact Sales": "High-Intent Lead Gen",
218
+ "Start Free Trial/Signup": "High-Intent Lead Gen",
219
+ "See Pricing/Request Quote": "High-Intent Lead Gen",
220
+ "Buy Now": "Direct Purchase",
221
+ "Reservation / Booking": "Direct Purchase",
222
+ "Subscription (No Free Trial)": "Direct Purchase",
223
+ "Download Asset / App": "Info/Content Lead Gen",
224
+ "Register for Webinar/Event": "Info/Content Lead Gen",
225
+ "Subscribe to Newsletter/Mailing List": "Info/Content Lead Gen",
226
+ "Find a Branch/Seller/Provider": "Location Search",
227
+ "Donate": "Non-Profit/Community"
228
+ }
229
+
230
+ for specific, parent in conversion_mappings.items():
231
+ print(f" '{specific}' → '{parent}'")
232
+ print()
233
+
234
+
235
+ def benefits_summary():
236
+ """
237
+ Summary of benefits from the new mapping feature.
238
+ """
239
+ print("=" * 80)
240
+ print("✨ BENEFITS OF AUTOMATIC MAPPING")
241
+ print("=" * 80)
242
+ print()
243
+
244
+ benefits = [
245
+ "✅ Send your own specific categorization (339 industries supported)",
246
+ "✅ No need to learn or memorize parent group names",
247
+ "✅ API handles conversion automatically",
248
+ "✅ Response shows both original and mapped values",
249
+ "✅ Backward compatible - parent groups still work",
250
+ "✅ More accurate categorization possible",
251
+ "✅ Easier integration with existing systems",
252
+ "✅ Better tracking of what was actually provided vs used"
253
+ ]
254
+
255
+ for benefit in benefits:
256
+ print(f" {benefit}")
257
+ print()
258
+
259
+
260
+ if __name__ == "__main__":
261
+ print("\n")
262
+ print("🚀 A/B TEST PREDICTOR API - AUTOMATIC MAPPING DEMO")
263
+ print("\n")
264
+
265
+ # Show mapping reference
266
+ mapping_reference_guide()
267
+
268
+ # Show benefits
269
+ benefits_summary()
270
+
271
+ print("=" * 80)
272
+ print("USAGE EXAMPLES")
273
+ print("=" * 80)
274
+ print()
275
+
276
+ print("ℹ️ NOTE: The following examples show the structure.")
277
+ print(" To run them, uncomment the function calls and provide valid image paths.")
278
+ print()
279
+
280
+ # Uncomment these to run actual predictions:
281
+ # predict_ab_test_with_specific_values()
282
+ # predict_ab_test_with_parent_groups()
283
+ # batch_predictions_with_mixed_values()
284
+
285
+ print("=" * 80)
286
+ print("STATISTICS")
287
+ print("=" * 80)
288
+ print()
289
+ print("📊 Supported Values:")
290
+ print(" - 339 specific industry values → 14 parent groups")
291
+ print(" - 43 specific page type values → 5 parent groups")
292
+ print(" - 16 specific conversion type values → 6 parent groups")
293
+ print()
294
+ print("📂 For complete list, see: mapping.json")
295
+ print()
296
+ print("=" * 80)
297
+ print("DOCUMENTATION")
298
+ print("=" * 80)
299
+ print()
300
+ print("📖 Full API Documentation: API_DOCUMENTATION.md")
301
+ print("📝 Update Summary: MAPPING_UPDATE_SUMMARY.md")
302
+ print("🧪 Test Script: test_mapping_feature.py")
303
+ print()
304
+
MAPPING_UPDATE_SUMMARY.md ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Automatic Value Mapping Update - Summary
2
+
3
+ ## Overview
4
+
5
+ The A/B Test Predictor API has been enhanced with automatic value mapping functionality. The API now accepts both **specific values** and **parent group values** for Industry, Page Type, and Conversion Type inputs, automatically converting them using the `mapping.json` file before feeding to the model.
6
+
7
+ ## Changes Made
8
+
9
+ ### 1. Core Implementation (`app.py`)
10
+
11
+ #### New Functions Added:
12
+ - `load_value_mappings()`: Loads the `mapping.json` file at startup
13
+ - `convert_to_parent_group()`: Converts specific values to their parent groups
14
+ - `get_all_possible_values()`: Returns all possible values (both specific and grouped) for API documentation
15
+
16
+ #### Updated Functions:
17
+ - `predict_with_categorical_data()`: Now converts incoming specific values to parent groups before prediction
18
+ - Accepts original values from API
19
+ - Converts industry → grouped_industry
20
+ - Converts page_type → grouped_page_type
21
+ - Converts conversion_type → grouped_conversion_type
22
+ - Returns both original and grouped values in response
23
+
24
+ - `predict_single()`: Updated docstring to clarify it expects grouped values
25
+ - `predict_batch()`: Added documentation noting it expects pre-grouped values in CSV
26
+
27
+ #### Response Structure Enhancement:
28
+ The API response now includes both `providedCategories` and `groupedCategories`:
29
+
30
+ ```json
31
+ {
32
+ "predictionResults": { ... },
33
+ "providedCategories": {
34
+ "industry": "Cybersecurity",
35
+ "pageType": "Homepage",
36
+ "conversionType": "Request Demo/Contact Sales"
37
+ },
38
+ "groupedCategories": {
39
+ "industry": "B2B Software & Tech",
40
+ "pageType": "Awareness & Discovery",
41
+ "conversionType": "High-Intent Lead Gen"
42
+ },
43
+ "processingInfo": { ... }
44
+ }
45
+ ```
46
+
47
+ ### 2. UI Updates (Gradio Interface)
48
+
49
+ Updated the "🎯 API Prediction" tab description to explain:
50
+ - API accepts both specific and parent group values
51
+ - Automatic conversion happens behind the scenes
52
+ - Model uses parent groups internally
53
+
54
+ ### 3. Documentation Updates (`API_DOCUMENTATION.md`)
55
+
56
+ Added comprehensive documentation for the new mapping feature:
57
+ - **New Section**: "🔄 Automatic Value Mapping" explaining how it works
58
+ - **Updated**: Valid Category Values sections with parent groups and example specific values
59
+ - **Updated**: Response format to show both `providedCategories` and `groupedCategories`
60
+ - **Added**: Mapping examples for Industry, Page Type, and Conversion Type
61
+ - **Added**: Code examples showing usage with specific values
62
+
63
+ ## How It Works
64
+
65
+ ### Data Flow:
66
+ 1. **API receives request** with specific values (e.g., "Cybersecurity", "Homepage")
67
+ 2. **Mapping function** looks up values in `mapping.json`
68
+ 3. **Conversion happens** to parent groups (e.g., "B2B Software & Tech", "Awareness & Discovery")
69
+ 4. **Model processes** using parent group values
70
+ 5. **Response includes** both original and grouped values
71
+
72
+ ### Example Mappings:
73
+
74
+ #### Industry:
75
+ - `Accounting Services` → `B2B Services`
76
+ - `Cybersecurity` → `B2B Software & Tech`
77
+ - `Healthcare` → `Health & Wellness`
78
+ - 200+ specific industries supported
79
+
80
+ #### Page Type:
81
+ - `Homepage` → `Awareness & Discovery`
82
+ - `Pricing Page` → `Consideration & Evaluation`
83
+ - `Checkout` → `Conversion`
84
+ - `Login` → `Internal & Navigation`
85
+
86
+ #### Conversion Type:
87
+ - `Request Demo/Contact Sales` → `High-Intent Lead Gen`
88
+ - `Buy Now` → `Direct Purchase`
89
+ - `Download Asset / App` → `Info/Content Lead Gen`
90
+
91
+ ## API Usage Examples
92
+
93
+ ### Before (only parent groups accepted):
94
+ ```python
95
+ result = client.predict(
96
+ "control.jpg",
97
+ "variant.jpg",
98
+ "SaaS",
99
+ "B2B",
100
+ "High-Intent Lead Gen", # Had to know parent group
101
+ "B2B Software & Tech", # Had to know parent group
102
+ "Awareness & Discovery", # Had to know parent group
103
+ api_name="/predict_with_categorical_data"
104
+ )
105
+ ```
106
+
107
+ ### After (accepts specific values):
108
+ ```python
109
+ result = client.predict(
110
+ "control.jpg",
111
+ "variant.jpg",
112
+ "SaaS",
113
+ "B2B",
114
+ "Request Demo/Contact Sales", # Specific value (auto-converted)
115
+ "Cybersecurity", # Specific value (auto-converted)
116
+ "Homepage", # Specific value (auto-converted)
117
+ api_name="/predict_with_categorical_data"
118
+ )
119
+ ```
120
+
121
+ ## Benefits
122
+
123
+ 1. **🎯 More Flexible Input**: Accept detailed, specific categorizations
124
+ 2. **🔄 Automatic Processing**: No need for clients to pre-process data
125
+ 3. **📊 Transparency**: Both original and grouped values returned
126
+ 4. **✅ Backward Compatible**: Still accepts parent group values directly
127
+ 5. **🛠️ Easy Integration**: Clients can send their own categorization system
128
+
129
+ ## Files Modified
130
+
131
+ 1. `/app.py` - Core application logic
132
+ 2. `/API_DOCUMENTATION.md` - Updated API documentation
133
+ 3. `/mapping.json` - Reference file (already existed, now actively used)
134
+
135
+ ## Testing Recommendations
136
+
137
+ 1. Test with parent group values (should work as before)
138
+ 2. Test with specific values (should auto-convert)
139
+ 3. Test with mixed values (some specific, some parent groups)
140
+ 4. Verify response includes both `providedCategories` and `groupedCategories`
141
+ 5. Test edge cases:
142
+ - Unknown values (should return as-is with warning)
143
+ - Case sensitivity
144
+ - Values with special characters
145
+
146
+ ## Deployment Notes
147
+
148
+ - **No Breaking Changes**: Existing API calls with parent groups still work
149
+ - **New Feature**: Specific value support is additive
150
+ - **Dependencies**: Requires `mapping.json` file to be present
151
+ - **Backward Compatible**: All existing integrations continue working
152
+
153
+ ## Version Info
154
+
155
+ - **Update Date**: October 31, 2025
156
+ - **API Version**: 1.1 (backward compatible with 1.0)
157
+ - **Model Version**: Unchanged (still GGG Enhanced)
158
+
159
+ ## Future Enhancements
160
+
161
+ Potential improvements for future versions:
162
+ 1. Add validation endpoint to check if a value will be mapped
163
+ 2. Return mapping confidence scores
164
+ 3. Support for custom mapping files
165
+ 4. API endpoint to retrieve all possible values
166
+ 5. Fuzzy matching for close-but-not-exact values
167
+
168
+ ## Example Logs
169
+
170
+ When using the updated API, you'll see logs like:
171
+ ```
172
+ 📋 Original categories from API: SaaS | B2B | Request Demo/Contact Sales | Cybersecurity | Homepage
173
+ ✅ Mapped 'Request Demo/Contact Sales' -> 'High-Intent Lead Gen'
174
+ ✅ Mapped 'Cybersecurity' -> 'B2B Software & Tech'
175
+ ✅ Mapped 'Homepage' -> 'Awareness & Discovery'
176
+ 📋 Mapped to parent groups: SaaS | B2B | High-Intent Lead Gen | B2B Software & Tech | Awareness & Discovery
177
+ ```
178
+
179
+ ---
180
+
181
+ **For Questions or Issues:**
182
+ - Review the updated `API_DOCUMENTATION.md`
183
+ - Check `mapping.json` for complete list of supported values
184
+ - Verify your input values match the expected format (case-sensitive)
185
+
QUICK_START_GUIDE.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A/B Test Predictor - Quick Start Guide
2
+
3
+ ## 🚀 Get Started in 3 Steps
4
+
5
+ ### 1. Install
6
+
7
+ ```bash
8
+ pip install gradio-client
9
+ ```
10
+
11
+ ### 2. Predict
12
+
13
+ ```python
14
+ from gradio_client import Client
15
+
16
+ client = Client("SpiralyzeLLC/ABTestPredictor")
17
+
18
+ result = client.predict(
19
+ "control.jpg", # Your control image
20
+ "variant.jpg", # Your variant image
21
+ "SaaS", # Business Model
22
+ "B2B", # Customer Type
23
+ "High-Intent Lead Gen", # Conversion Type
24
+ "B2B Software & Tech", # Industry
25
+ "Awareness & Discovery", # Page Type
26
+ api_name="/predict_with_categorical_data"
27
+ )
28
+ ```
29
+
30
+ ### 3. View Results
31
+
32
+ ```python
33
+ print(f"Win Probability: {result['predictionResults']['probability']}")
34
+ print(f"Confidence: {result['predictionResults']['modelConfidence']}%")
35
+
36
+ if float(result['predictionResults']['probability']) > 0.5:
37
+ print("🎉 Variant predicted to WIN!")
38
+ else:
39
+ print("⚠️ Control predicted to win")
40
+ ```
41
+
42
+ ## 📋 Input Parameters
43
+
44
+ | Parameter | Values |
45
+ |-----------|--------|
46
+ | **Business Model** | `E-Commerce`, `Lead Generation`, `Other*`, `SaaS` |
47
+ | **Customer Type** | `B2B`, `B2C`, `Both`, `Other*` |
48
+ | **Conversion Type** | `Direct Purchase`, `High-Intent Lead Gen`, `Info/Content Lead Gen`, `Location Search`, `Non-Profit/Community`, `Other Conversion` |
49
+ | **Industry** | `Automotive & Transportation`, `B2B Services`, `B2B Software & Tech`, `Consumer Services`, `Consumer Software & Apps`, `Education`, `Finance, Insurance & Real Estate`, `Food, Hospitality & Travel`, `Health & Wellness`, `Industrial & Manufacturing`, `Media & Entertainment`, `Non-Profit & Government`, `Other`, `Retail & E-commerce` |
50
+ | **Page Type** | `Awareness & Discovery`, `Consideration & Evaluation`, `Conversion`, `Internal & Navigation`, `Post-Conversion & Other` |
51
+
52
+ ## 📊 Response
53
+
54
+ ```json
55
+ {
56
+ "predictionResults": {
57
+ "probability": "0.682", // >0.5 = Variant wins
58
+ "modelConfidence": "66.1", // Accuracy % for this category
59
+ "trainingDataSamples": 14634, // Training data size
60
+ "totalPredictions": 1626, // Total test predictions
61
+ "correctPredictions": 1074 // Correct predictions
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## 🌐 Or Use Web Interface
67
+
68
+ Visit: **https://huggingface.co/spaces/SpiralyzeLLC/ABTestPredictor**
69
+
70
+ 1. Upload images
71
+ 2. Select categories
72
+ 3. Click "Predict"
73
+ 4. Get instant results!
74
+
75
+ ## 📖 Full Documentation
76
+
77
+ For complete API reference, error handling, and advanced examples:
78
+
79
+ 👉 See **[API_DOCUMENTATION.md](API_DOCUMENTATION.md)**
80
+
81
+ ---
82
+
83
+ **Need Help?** Check [Common Issues](API_DOCUMENTATION.md#-common-issues) in the full docs.
84
+
README.md CHANGED
@@ -74,10 +74,29 @@ Advanced A/B testing outcome predictor using multimodal AI analysis combining:
74
 
75
  ## 📡 API Usage
76
 
77
- See `API_USAGE_UPDATED.md` for detailed API documentation including:
78
- - Input parameters and their valid values
79
- - Response format and field descriptions
80
- - Example usage code
81
- - Confidence scoring methodology
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  Built with ❤️ using Gradio, PyTorch, Transformers, and Hugging Face.
 
74
 
75
  ## 📡 API Usage
76
 
77
+ ### Quick Start
78
+ ```python
79
+ from gradio_client import Client
80
+
81
+ client = Client("SpiralyzeLLC/ABTestPredictor")
82
+ result = client.predict(
83
+ "control.jpg", "variant.jpg",
84
+ "SaaS", "B2B", "High-Intent Lead Gen",
85
+ "B2B Software & Tech", "Awareness & Discovery",
86
+ api_name="/predict_with_categorical_data"
87
+ )
88
+ ```
89
+
90
+ ### 📚 Documentation
91
+
92
+ - **[QUICK_START_GUIDE.md](QUICK_START_GUIDE.md)** - Get started in 3 steps
93
+ - **[API_DOCUMENTATION.md](API_DOCUMENTATION.md)** - Complete API reference with examples in Python, JavaScript, and cURL
94
+ - **[API_USAGE_UPDATED.md](API_USAGE_UPDATED.md)** - Technical details and migration notes
95
+
96
+ ### 🌐 Web Interface
97
+
98
+ Use the interactive interface: **https://huggingface.co/spaces/SpiralyzeLLC/ABTestPredictor**
99
+
100
+ ---
101
 
102
  Built with ❤️ using Gradio, PyTorch, Transformers, and Hugging Face.
UPDATE_NOTES.md ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🎯 Automatic Value Mapping - Update Complete
2
+
3
+ ## ✅ What Was Implemented
4
+
5
+ The A/B Test Predictor API now supports **automatic value mapping** for three key inputs:
6
+ 1. **Industry** - Converts 339 specific industries to 14 parent groups
7
+ 2. **Page Type** - Converts 43 specific page types to 5 parent groups
8
+ 3. **Conversion Type** - Converts 16 specific conversion types to 6 parent groups
9
+
10
+ ## 🔄 How It Works
11
+
12
+ ### Before This Update:
13
+ ```python
14
+ # You HAD to use parent groups
15
+ result = client.predict(
16
+ "control.jpg", "variant.jpg",
17
+ "SaaS", "B2B",
18
+ "High-Intent Lead Gen", # Parent group (required)
19
+ "B2B Software & Tech", # Parent group (required)
20
+ "Awareness & Discovery", # Parent group (required)
21
+ api_name="/predict_with_categorical_data"
22
+ )
23
+ ```
24
+
25
+ ### After This Update:
26
+ ```python
27
+ # You CAN NOW use specific values
28
+ result = client.predict(
29
+ "control.jpg", "variant.jpg",
30
+ "SaaS", "B2B",
31
+ "Request Demo/Contact Sales", # Specific value ✨
32
+ "Cybersecurity", # Specific value ✨
33
+ "Homepage", # Specific value ✨
34
+ api_name="/predict_with_categorical_data"
35
+ )
36
+
37
+ # API automatically converts to:
38
+ # "Request Demo/Contact Sales" → "High-Intent Lead Gen"
39
+ # "Cybersecurity" → "B2B Software & Tech"
40
+ # "Homepage" → "Awareness & Discovery"
41
+ ```
42
+
43
+ ## 📊 Response Format
44
+
45
+ The API now returns both the original values you provided AND the grouped values used by the model:
46
+
47
+ ```json
48
+ {
49
+ "predictionResults": { ... },
50
+ "providedCategories": {
51
+ "industry": "Cybersecurity",
52
+ "pageType": "Homepage",
53
+ "conversionType": "Request Demo/Contact Sales"
54
+ },
55
+ "groupedCategories": {
56
+ "industry": "B2B Software & Tech",
57
+ "pageType": "Awareness & Discovery",
58
+ "conversionType": "High-Intent Lead Gen"
59
+ },
60
+ "processingInfo": { ... }
61
+ }
62
+ ```
63
+
64
+ ## 📂 Files Modified
65
+
66
+ 1. **`app.py`**
67
+ - Added `load_value_mappings()` function
68
+ - Added `convert_to_parent_group()` function
69
+ - Updated `predict_with_categorical_data()` to handle mapping
70
+ - Added `get_all_possible_values()` helper function
71
+ - Enhanced response to include both provided and grouped categories
72
+
73
+ 2. **`API_DOCUMENTATION.md`**
74
+ - Added "🔄 Automatic Value Mapping" section
75
+ - Updated category value lists with examples
76
+ - Updated response format documentation
77
+ - Added mapping examples and use cases
78
+
79
+ 3. **`mapping.json`**
80
+ - Already existed, now actively used by the API
81
+ - Contains all 339 industries, 43 page types, 16 conversion types
82
+
83
+ ## 🧪 Testing
84
+
85
+ Created test files to verify functionality:
86
+ - `test_mapping_feature.py` - Unit tests (7/7 passed ✅)
87
+ - `COMPLETE_EXAMPLE_WITH_MAPPING.py` - Usage examples and demos
88
+
89
+ ## ✨ Benefits
90
+
91
+ 1. **More Flexible**: Accept 339+ specific values instead of just 14 parent groups
92
+ 2. **Easier Integration**: Use your existing categorization system
93
+ 3. **Backward Compatible**: Parent groups still work exactly as before
94
+ 4. **Transparent**: See both original and mapped values in response
95
+ 5. **Automatic**: No preprocessing needed on your end
96
+
97
+ ## 📈 Supported Values
98
+
99
+ | Category | Parent Groups | Specific Values | Examples |
100
+ |----------|--------------|----------------|----------|
101
+ | Industry | 14 | 339 | "Accounting Services", "Cybersecurity", "Healthcare" |
102
+ | Page Type | 5 | 43 | "Homepage", "Pricing Page", "Checkout" |
103
+ | Conversion Type | 6 | 16 | "Request Demo", "Buy Now", "Download Asset" |
104
+
105
+ ## 🔍 Example Mappings
106
+
107
+ **Industry:**
108
+ - `Accounting Services` → `B2B Services`
109
+ - `Cybersecurity` → `B2B Software & Tech`
110
+ - `Healthcare` → `Health & Wellness`
111
+
112
+ **Page Type:**
113
+ - `Homepage` → `Awareness & Discovery`
114
+ - `Pricing Page` → `Consideration & Evaluation`
115
+ - `Checkout` → `Conversion`
116
+
117
+ **Conversion Type:**
118
+ - `Request Demo/Contact Sales` → `High-Intent Lead Gen`
119
+ - `Buy Now` → `Direct Purchase`
120
+ - `Download Asset / App` → `Info/Content Lead Gen`
121
+
122
+ ## 📖 Documentation
123
+
124
+ - **API Documentation**: See `API_DOCUMENTATION.md`
125
+ - **Detailed Summary**: See `MAPPING_UPDATE_SUMMARY.md`
126
+ - **Complete Examples**: See `COMPLETE_EXAMPLE_WITH_MAPPING.py`
127
+ - **Unit Tests**: See `test_mapping_feature.py`
128
+ - **Mapping Data**: See `mapping.json`
129
+
130
+ ## 🚀 Deployment
131
+
132
+ - **Status**: Ready to deploy ✅
133
+ - **Breaking Changes**: None (fully backward compatible)
134
+ - **Requirements**: `mapping.json` must be present in root directory
135
+ - **Version**: API v1.1
136
+
137
+ ## ⚠️ Important Notes
138
+
139
+ 1. **Values are case-sensitive**: "Cybersecurity" works, "cybersecurity" doesn't
140
+ 2. **Exact matches required**: Use exact strings from `mapping.json`
141
+ 3. **Unknown values**: Will be passed through as-is (with warning logged)
142
+ 4. **Business Model & Customer Type**: Not mapped (no changes needed)
143
+
144
+ ## 🎉 Ready to Use
145
+
146
+ The update is complete and tested. The API now accepts both specific and parent group values, making it much more flexible and easier to integrate with your existing systems!
147
+
148
+ ---
149
+
150
+ **Updated**: October 31, 2025
151
+ **Version**: 1.1
152
+ **Backward Compatible**: Yes ✅
153
+
app.py CHANGED
@@ -187,6 +187,61 @@ if not os.path.exists(CAT_MAPPINGS_SAVE_PATH):
187
  with open(CAT_MAPPINGS_SAVE_PATH, 'r') as f:
188
  category_mappings = json.load(f)
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  # Load confidence scores directly from JSON file
191
  def load_confidence_scores():
192
  """Load confidence scores from confidence_scores.json"""
@@ -227,6 +282,18 @@ def load_confidence_scores():
227
  traceback.print_exc()
228
  return {}
229
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  # Load confidence scores
231
  try:
232
  print("=" * 50)
@@ -373,10 +440,17 @@ def predict_with_categorical_data(control_image, variant_image, business_model,
373
 
374
  start_time = time.time()
375
 
376
- print(f"📋 Using provided categories: {business_model} | {customer_type} | {conversion_type} | {industry} | {page_type}")
 
 
 
 
 
377
 
378
- # Run the prediction with provided categorical data
379
- prediction_result = predict_single(control_image, variant_image, business_model, customer_type, conversion_type, industry, page_type)
 
 
380
 
381
  # Create comprehensive result with prediction and confidence data
382
  result = {
@@ -388,9 +462,16 @@ def predict_with_categorical_data(control_image, variant_image, business_model,
388
  "industry": industry,
389
  "pageType": page_type
390
  },
 
 
 
 
 
 
 
391
  "processingInfo": {
392
  "totalProcessingTime": f"{time.time() - start_time:.2f}s",
393
- "confidenceSource": f"{industry} | {page_type}"
394
  }
395
  }
396
 
@@ -398,7 +479,12 @@ def predict_with_categorical_data(control_image, variant_image, business_model,
398
 
399
  @spaces.GPU(duration=60) # Maximum allowed duration on free tier
400
  def predict_single(control_image, variant_image, business_model, customer_type, conversion_type, industry, page_type):
401
- """Orchestrates the prediction for a single pair of images and features."""
 
 
 
 
 
402
  try:
403
  if control_image is None or variant_image is None:
404
  return {"Error": 1.0, "Please upload both images": 0.0}
@@ -488,9 +574,46 @@ def predict_single(control_image, variant_image, business_model, customer_type,
488
  "totalLosePrediction": 0
489
  }
490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  @spaces.GPU
492
  def predict_batch(csv_path, control_img_dir, variant_img_dir, num_samples):
493
- """Handles batch prediction from a CSV file."""
 
 
 
 
 
 
494
  if not all([csv_path, control_img_dir, variant_img_dir, num_samples]):
495
  return pd.DataFrame({"Error": ["Please fill in all fields."]})
496
 
@@ -519,7 +642,7 @@ def predict_batch(csv_path, control_img_dir, variant_img_dir, num_samples):
519
  if not v_path or not os.path.exists(v_path):
520
  raise FileNotFoundError(f"Variant image not found: {v_path}")
521
 
522
- # Get categorical features from the row
523
  cat_features_from_row = [row[f] for f in CATEGORICAL_FEATURES]
524
 
525
  # Use the core prediction logic
@@ -561,7 +684,15 @@ with gr.Blocks() as iface:
561
 
562
  with gr.Tab("🎯 API Prediction"):
563
  gr.Markdown("### 📊 Predict with Categorical Data")
564
- gr.Markdown("Upload images and provide categorical data for prediction:")
 
 
 
 
 
 
 
 
565
 
566
  with gr.Row():
567
  with gr.Column():
 
187
  with open(CAT_MAPPINGS_SAVE_PATH, 'r') as f:
188
  category_mappings = json.load(f)
189
 
190
+ # Load mapping.json for converting specific values to parent groups
191
+ def load_value_mappings():
192
+ """Load mapping.json for converting industry, page_type, and conversion_type to parent groups"""
193
+ try:
194
+ script_dir = os.path.dirname(os.path.abspath(__file__))
195
+ mapping_file = os.path.join(script_dir, 'mapping.json')
196
+
197
+ print(f"📂 Looking for mapping file at: {mapping_file}")
198
+
199
+ if not os.path.exists(mapping_file):
200
+ print(f"⚠️ Mapping file not found, trying fallback location...")
201
+ mapping_file = 'mapping.json'
202
+
203
+ with open(mapping_file, 'r') as f:
204
+ mapping_data = json.load(f)
205
+ print(f"✅ Successfully loaded mapping.json with {len(mapping_data)} mapping types")
206
+ return mapping_data
207
+ except Exception as e:
208
+ print(f"⚠️ Error loading mapping.json: {e}")
209
+ import traceback
210
+ traceback.print_exc()
211
+ return {}
212
+
213
+ def convert_to_parent_group(value, mapping_type, value_mappings):
214
+ """
215
+ Convert a specific value to its parent group using mapping.json
216
+
217
+ Args:
218
+ value: The specific value (e.g., "Accounting Services")
219
+ mapping_type: Type of mapping ("industry_mappings", "page_type_mappings", "conversion_type_mappings")
220
+ value_mappings: The loaded mapping.json data
221
+
222
+ Returns:
223
+ The parent group name (e.g., "B2B Services")
224
+ """
225
+ if mapping_type not in value_mappings:
226
+ print(f"⚠️ Mapping type '{mapping_type}' not found in mapping.json")
227
+ return value
228
+
229
+ mappings = value_mappings[mapping_type]
230
+
231
+ # Search for the value in all parent groups
232
+ for parent_group, child_values in mappings.items():
233
+ if value in child_values:
234
+ print(f"✅ Mapped '{value}' -> '{parent_group}'")
235
+ return parent_group
236
+
237
+ # If not found, check if the value itself is a parent group
238
+ if value in mappings.keys():
239
+ print(f"ℹ️ '{value}' is already a parent group")
240
+ return value
241
+
242
+ print(f"⚠️ Value '{value}' not found in {mapping_type}, returning as-is")
243
+ return value
244
+
245
  # Load confidence scores directly from JSON file
246
  def load_confidence_scores():
247
  """Load confidence scores from confidence_scores.json"""
 
282
  traceback.print_exc()
283
  return {}
284
 
285
+ # Load value mappings for converting specific values to parent groups
286
+ try:
287
+ print("=" * 50)
288
+ print("🚀 LOADING VALUE MAPPINGS...")
289
+ print("=" * 50)
290
+ value_mappings = load_value_mappings()
291
+ print(f"✅ Value mappings loaded successfully")
292
+ print("=" * 50)
293
+ except Exception as e:
294
+ print(f"⚠️ Error loading value mappings: {e}")
295
+ value_mappings = {}
296
+
297
  # Load confidence scores
298
  try:
299
  print("=" * 50)
 
440
 
441
  start_time = time.time()
442
 
443
+ print(f"📋 Original categories from API: {business_model} | {customer_type} | {conversion_type} | {industry} | {page_type}")
444
+
445
+ # Convert specific values to parent groups using mapping.json
446
+ grouped_conversion_type = convert_to_parent_group(conversion_type, "conversion_type_mappings", value_mappings)
447
+ grouped_industry = convert_to_parent_group(industry, "industry_mappings", value_mappings)
448
+ grouped_page_type = convert_to_parent_group(page_type, "page_type_mappings", value_mappings)
449
 
450
+ print(f"📋 Mapped to parent groups: {business_model} | {customer_type} | {grouped_conversion_type} | {grouped_industry} | {grouped_page_type}")
451
+
452
+ # Run the prediction with grouped categorical data
453
+ prediction_result = predict_single(control_image, variant_image, business_model, customer_type, grouped_conversion_type, grouped_industry, grouped_page_type)
454
 
455
  # Create comprehensive result with prediction and confidence data
456
  result = {
 
462
  "industry": industry,
463
  "pageType": page_type
464
  },
465
+ "groupedCategories": {
466
+ "businessModel": business_model,
467
+ "customerType": customer_type,
468
+ "conversionType": grouped_conversion_type,
469
+ "industry": grouped_industry,
470
+ "pageType": grouped_page_type
471
+ },
472
  "processingInfo": {
473
  "totalProcessingTime": f"{time.time() - start_time:.2f}s",
474
+ "confidenceSource": f"{grouped_industry} | {grouped_page_type}"
475
  }
476
  }
477
 
 
479
 
480
  @spaces.GPU(duration=60) # Maximum allowed duration on free tier
481
  def predict_single(control_image, variant_image, business_model, customer_type, conversion_type, industry, page_type):
482
+ """
483
+ Orchestrates the prediction for a single pair of images and features.
484
+
485
+ Note: This function expects GROUPED values for conversion_type, industry, and page_type.
486
+ If calling from API, use predict_with_categorical_data() which handles the conversion automatically.
487
+ """
488
  try:
489
  if control_image is None or variant_image is None:
490
  return {"Error": 1.0, "Please upload both images": 0.0}
 
574
  "totalLosePrediction": 0
575
  }
576
 
577
+ def get_all_possible_values():
578
+ """
579
+ Get all possible values (both specific and grouped) for industry, page_type, and conversion_type.
580
+ This is useful for API documentation and validation.
581
+ """
582
+ all_values = {
583
+ "industry": [],
584
+ "page_type": [],
585
+ "conversion_type": []
586
+ }
587
+
588
+ # Get all industry values (both parent groups and specific values)
589
+ if "industry_mappings" in value_mappings:
590
+ for parent_group, child_values in value_mappings["industry_mappings"].items():
591
+ all_values["industry"].append(parent_group)
592
+ all_values["industry"].extend(child_values)
593
+
594
+ # Get all page type values
595
+ if "page_type_mappings" in value_mappings:
596
+ for parent_group, child_values in value_mappings["page_type_mappings"].items():
597
+ all_values["page_type"].append(parent_group)
598
+ all_values["page_type"].extend(child_values)
599
+
600
+ # Get all conversion type values
601
+ if "conversion_type_mappings" in value_mappings:
602
+ for parent_group, child_values in value_mappings["conversion_type_mappings"].items():
603
+ all_values["conversion_type"].append(parent_group)
604
+ all_values["conversion_type"].extend(child_values)
605
+
606
+ return all_values
607
+
608
  @spaces.GPU
609
  def predict_batch(csv_path, control_img_dir, variant_img_dir, num_samples):
610
+ """
611
+ Handles batch prediction from a CSV file.
612
+ Note: CSV should contain grouped values (not specific values) for:
613
+ - grouped_conversion_type
614
+ - grouped_industry
615
+ - grouped_page_type
616
+ """
617
  if not all([csv_path, control_img_dir, variant_img_dir, num_samples]):
618
  return pd.DataFrame({"Error": ["Please fill in all fields."]})
619
 
 
642
  if not v_path or not os.path.exists(v_path):
643
  raise FileNotFoundError(f"Variant image not found: {v_path}")
644
 
645
+ # Get categorical features from the row (expects grouped values in CSV)
646
  cat_features_from_row = [row[f] for f in CATEGORICAL_FEATURES]
647
 
648
  # Use the core prediction logic
 
684
 
685
  with gr.Tab("🎯 API Prediction"):
686
  gr.Markdown("### 📊 Predict with Categorical Data")
687
+ gr.Markdown("""
688
+ Upload images and provide categorical data for prediction.
689
+
690
+ **Note:** For Industry, Page Type, and Conversion Type, you can provide either:
691
+ - Specific values (e.g., "Accounting Services") - will be automatically converted to parent group (e.g., "B2B Services")
692
+ - Parent group values (e.g., "B2B Services") - will be used directly
693
+
694
+ The model uses parent groups internally, but the API accepts both for convenience.
695
+ """)
696
 
697
  with gr.Row():
698
  with gr.Column():
mapping.json ADDED
@@ -0,0 +1,456 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "industry_mappings": {
3
+ "Automotive & Transportation": [
4
+ "Automotive Services",
5
+ "Transportation*"
6
+ ],
7
+ "B2B Services": [
8
+ "Accounting Services",
9
+ "Affiliate Marketing",
10
+ "Cleaning Services",
11
+ "Consulting Services",
12
+ "Creative Service Providers",
13
+ "Digital Marketing Services [DO NOT USE - Use Marketing Agency instead]",
14
+ "Enterprise Services",
15
+ "Events Planning",
16
+ "Funeral Related Services ",
17
+ "HR & Recruitment Agency",
18
+ "HR & Recruitment Software",
19
+ "Implementation Services Providers",
20
+ "Job Search",
21
+ "Law Firms & Legal Services",
22
+ "Marketing",
23
+ "Marketing Agency",
24
+ "Multimedia & Design Agencies",
25
+ "Printing",
26
+ "Research & Development",
27
+ "Research & Development Services",
28
+ "Solution Consulting Providers",
29
+ "Translation & Linguistic Services"
30
+ ],
31
+ "B2B Software & Tech": [
32
+ "AI & Machine Learning Operationalization (MLOps) Software",
33
+ "AI Sales Assistant Software",
34
+ "API Management Tools",
35
+ "Account-Based Marketing Software",
36
+ "Accounting & Financial Software",
37
+ "Accounting & Financial Software ",
38
+ "Adblocking Software",
39
+ "Address Verification Tools",
40
+ "Advertiser Campaign Management Software",
41
+ "Application Development Software",
42
+ "Asset Management Software",
43
+ "Auction ",
44
+ "Audio Editing Software",
45
+ "Augmented Reality (AR) Software",
46
+ "Automotive & Transportation Software",
47
+ "Blockchain Software",
48
+ "Business Card Scanning Software",
49
+ "Business Intelligence Software",
50
+ "Business Intelligence Software ",
51
+ "Business Scheduling Software",
52
+ "CAD Software",
53
+ "Call & Contact Center Software",
54
+ "Carbon Accounting Software",
55
+ "Child Care Software",
56
+ "Church Management Software",
57
+ "Cloud-Based Software",
58
+ "Competitive Intelligence Software",
59
+ "Confidentiality Software",
60
+ "Construction Software",
61
+ "Content & Collaboration Software ",
62
+ "Content Management System (CMS) Tools & Software",
63
+ "Content Marketing Software",
64
+ "Continuous Testing Platforms Software",
65
+ "Contract Analytics Software",
66
+ "Contract Management Software",
67
+ "Contractor Platform",
68
+ "Conversational Intelligence Software ",
69
+ "Conversational Marketing Software",
70
+ "Conversion Rate Optimization (CRO) Software",
71
+ "Corporate Social Responsibility (CSR) Software",
72
+ "Customer Data Platforms (CDP)",
73
+ "Customer Relationship Management (CRM) Software ",
74
+ "Customer Service Software",
75
+ "Customer Success Software",
76
+ "Cybersecurity",
77
+ "Data Analytics",
78
+ "Data Destruction Software",
79
+ "Data Governance Software",
80
+ "Data Integration Software",
81
+ "Data Labeling Software",
82
+ "Data Management Platform (DMP)",
83
+ "Data Quality Tools",
84
+ "Data Recovery Software ",
85
+ "Data Science and Machine Learning Platforms",
86
+ "DataOps Platform",
87
+ "Database & File Management Software ",
88
+ "Demand Generation Software",
89
+ "Deployment Software",
90
+ "DevOps Software",
91
+ "DevSecOps Software",
92
+ "Diagramming Software",
93
+ "Digital Adoption Platform",
94
+ "Digital Analytics Software",
95
+ "Digital Experience Platform",
96
+ "Digital Signage Software",
97
+ "Direct Mail Automation Software",
98
+ "Disk Cleanup Software",
99
+ "Distribution Software",
100
+ "Document Generation Software",
101
+ "Document Scanning Software",
102
+ "E-Commerce Software",
103
+ "E-Commerce Software ",
104
+ "E-Signature Software",
105
+ "E-mail Signature Software",
106
+ "Education Management Software",
107
+ "Email Marketing Software",
108
+ "Email Verification Software",
109
+ "Emergency Medical Services Software ",
110
+ "Emergency Notification Software",
111
+ "Employee Scheduling Software",
112
+ "Engineering Software ",
113
+ "Enterprise Resource Planning (ERP) Software ",
114
+ "Enterprise SaaS",
115
+ "Enterprise Search Software",
116
+ "Entity Management Software",
117
+ "Environmental, Social, and Governance (ESG) Reporting Software",
118
+ "Event Management Software",
119
+ "Event Stream Processing Software",
120
+ "Experience Management Software",
121
+ "Feature Management Software",
122
+ "Field Sales Software",
123
+ "Field Service Management Software",
124
+ "Fitness Software",
125
+ "Fleet Tracking Software",
126
+ "Fleet Tracking Software ",
127
+ "Fundraising Software ",
128
+ "Generative AI Software",
129
+ "Governance, Risk and Compliance (GRC) Platform",
130
+ "Graphic Design Software",
131
+ "Gym Management Software",
132
+ "Healthcare Management Software",
133
+ "Healthcare Software",
134
+ "Help Desk Software",
135
+ "Hospitality Software",
136
+ "IT Management Software",
137
+ "IT Services ",
138
+ "Identity Management Software",
139
+ "Identity Verification & Anti-Money Laundering Software",
140
+ "Inbound Call Tracking Software",
141
+ "Incident Management Software",
142
+ "Integrated Development Environments",
143
+ "Internal Communications Software",
144
+ "Internet Service Providers",
145
+ "Inventory Management Software",
146
+ "IoT Device Management Platform",
147
+ "Knowledge Management Software",
148
+ "Learning Management Software (LMS)",
149
+ "Legal Software",
150
+ "Legal Software ",
151
+ "Life Sciences Software",
152
+ "Live Chat Software",
153
+ "Load Balancing Software",
154
+ "Local Marketing Software",
155
+ "Location Intelligence Software",
156
+ "Marketing Analytics Software",
157
+ "Marketing Automation Software",
158
+ "Message Queue (MQ) Software",
159
+ "Microsoft Channel Partners",
160
+ "Mobile App Development ",
161
+ "Mobile Forms Automation Software",
162
+ "Monitoring Software",
163
+ "Networking Software ",
164
+ "Nonprofit Software",
165
+ "Note-Taking Management Software ",
166
+ "On-Demand Delivery Software",
167
+ "Online Appointment Scheduling Software ",
168
+ "Online Community Management Software",
169
+ "Online Form Builder Software ",
170
+ "Online Marketplace Optimization Tool",
171
+ "Online Reputation Management Software",
172
+ "Org Chart Software",
173
+ "Other Development Software",
174
+ "POS Software",
175
+ "Partner Management Software",
176
+ "Payroll Software",
177
+ "Podcast Hosting Platform",
178
+ "Pop-Up Builder Software",
179
+ "Presentation Software",
180
+ "Print Management Software",
181
+ "Privacy Software",
182
+ "Process Automation Software ",
183
+ "Procurement Software",
184
+ "Productivity Bots Software",
185
+ "Professional Services Automation Software",
186
+ "Project, Portfolio, & Program Management Software",
187
+ "Property Management Software",
188
+ "Public Relations (PR) Software",
189
+ "Public Safety Software",
190
+ "Public Sector Software",
191
+ "Quality Management Systems (QMS)",
192
+ "Real Estate Software",
193
+ "Regulatory Information Management (RIM) Systems",
194
+ "Remote Monitoring & Management (RMM) Software",
195
+ "Remote Support Software",
196
+ "Repository Management Software",
197
+ "Requirements Management Software",
198
+ "Research Software",
199
+ "Retail Software",
200
+ "Revenue Operations & Intelligence (RO&I) Software",
201
+ "Route Planning Software",
202
+ "SEO Software",
203
+ "SMS Marketing Software",
204
+ "SaaS Spend Management Software",
205
+ "Sales Acceleration Software",
206
+ "Sales Gamification",
207
+ "Sales Intelligence Software",
208
+ "Screen and Video Capture Software",
209
+ "Service Desk Software",
210
+ "Shipping Software ",
211
+ "Social Media Marketing Software ",
212
+ "Software Design Software",
213
+ "Software Testing Tools ",
214
+ "Spa and Salon Management Software",
215
+ "Space Management Software",
216
+ "Sports Software",
217
+ "Stock Media Software",
218
+ "Storage & System Management Software ",
219
+ "Supply Chain Management (SCM) Software ",
220
+ "Sustainability Management Software",
221
+ "Talent Management Software",
222
+ "Team Collaboration Software",
223
+ "Tech Development Tools",
224
+ "Technology",
225
+ "Text Analysis Software",
226
+ "Time Tracking Software",
227
+ "Transcription Software",
228
+ "URL Shortener",
229
+ "Video Conferencing Software",
230
+ "Video Email Software",
231
+ "Video Platform as a Service (VPaaS) Software",
232
+ "Video Software",
233
+ "Virtual Mailbox Software",
234
+ "Virtual Private Networks (VPN) ",
235
+ "VoIP (Voice over IP) Provider",
236
+ "Vulnerability Management Software ",
237
+ "Web Data Providers Software",
238
+ "Website Builder Software",
239
+ "Website Hosting",
240
+ "Whistleblowing Software",
241
+ "Workforce Management Software"
242
+ ],
243
+ "Consumer Services": [
244
+ "Consumer Services",
245
+ "Dating",
246
+ "Delivery Services ",
247
+ "Home & Office Security",
248
+ "Pets",
249
+ "Rental Services ",
250
+ "Weddings"
251
+ ],
252
+ "Consumer Software & Apps": [
253
+ "Consumer Software",
254
+ "Mobile Marketing Software",
255
+ "Personality Tests"
256
+ ],
257
+ "Education": [
258
+ "Education & Universities",
259
+ "Language Learning",
260
+ "Online Learning Platforms"
261
+ ],
262
+ "Finance, Insurance & Real Estate": [
263
+ "Cryptocurrency",
264
+ "Finance",
265
+ "Insurance",
266
+ "Quote Management Software",
267
+ "Real Estate",
268
+ "Transactional Email Software"
269
+ ],
270
+ "Food, Hospitality & Travel": [
271
+ "Airlines, Airports & Air Services ",
272
+ "Hotels, Lodging, Resorts and Cruises",
273
+ "Restaurants, Food & Beverage",
274
+ "Travel Agencies & Services",
275
+ "Travel Arrangement Software"
276
+ ],
277
+ "Health & Wellness": [
278
+ "Ancestry",
279
+ "Beauty & Cosmetics",
280
+ "Corporate Wellness Software",
281
+ "Elderly Care ",
282
+ "Fitness, Weight loss & Wellness ",
283
+ "Healthcare",
284
+ "Human Services Software",
285
+ "Medical Devices & Equipment ",
286
+ "Mental Health & Rehabilitation Facilities",
287
+ "Pharmaceuticals",
288
+ "Vitamins, Supplements & Health Stores",
289
+ "Water Testing"
290
+ ],
291
+ "Industrial & Manufacturing": [
292
+ "Aerospace & Defense ",
293
+ "Agriculture & Livestock",
294
+ "Construction",
295
+ "Energy, Electricity, Utilities & Waste",
296
+ "Freight & Logistics Services",
297
+ "Industrial Machinery & Equipment",
298
+ "Manufacturing",
299
+ "Minerals & Mining",
300
+ "Oil & Gas",
301
+ "Oil & Gas Software",
302
+ "Plastic, Packaging & Containers",
303
+ "Telecommunication "
304
+ ],
305
+ "Media & Entertainment": [
306
+ "Editor Software",
307
+ "Entertainment",
308
+ "Fine Art",
309
+ "Gaming & Gambling ",
310
+ "Magazines, Newspapers and News Services",
311
+ "Media & Internet",
312
+ "Museum",
313
+ "Music Production & Services",
314
+ "Photography & Photography Software",
315
+ "Social Media",
316
+ "Sports & Recreation ",
317
+ "Streaming Services ",
318
+ "Zoos, Amusement Parks & National Parks"
319
+ ],
320
+ "Non-Profit & Government": [
321
+ "Government Site",
322
+ "Holding Companies & Conglomerates",
323
+ "Non-Profit & Charitable Organizations ",
324
+ "Political Software",
325
+ "Professional / Membership Organizations",
326
+ "Religious Organizations",
327
+ "Surveys"
328
+ ],
329
+ "Other": [
330
+ "Adult Entertainment",
331
+ "Architecture & Interior Design ",
332
+ "Communication",
333
+ "Cycling ",
334
+ "Engineering",
335
+ "Expo Event Websites",
336
+ "General",
337
+ "Horoscope",
338
+ "Laboratory Software",
339
+ "Lottery",
340
+ "Marketplace Apps/Software",
341
+ "Other",
342
+ "Other*",
343
+ "Performing Arts Software",
344
+ "Personal Websites"
345
+ ],
346
+ "Retail & E-commerce": [
347
+ "Apparel & Accessories ",
348
+ "Appliances, Furniture, and Hardware Retail",
349
+ "Automobile Parts & Dealers",
350
+ "Boats & Submarines ",
351
+ "Books, Stationeries, & Office Supplies",
352
+ "Chemicals and Laboratory Equipment",
353
+ "Consignment",
354
+ "Consumer Electronics",
355
+ "Convenience Stores, Gas Stations & Liquor Stores",
356
+ "Department Stores, Malls, Shopping Centers & Superstores",
357
+ "Flowers, Gifts & Specialty Stores ",
358
+ "Gardening [DO NOT USE - USE LANDSCAPING INSTEAD]",
359
+ "Gardening, Landscaping & Plants",
360
+ "Hardware / DIY Tools",
361
+ "Home Improvement & Hardware Retail [DO NOT USE]",
362
+ "Hygiene Products",
363
+ "Jewelery ",
364
+ "Kitchenware & Tableware",
365
+ "Mom & Baby",
366
+ "Musical Instruments and Equipment",
367
+ "Retail ",
368
+ "Toys"
369
+ ]
370
+ },
371
+ "page_type_mappings": {
372
+ "Awareness & Discovery": [
373
+ "Blog / Content",
374
+ "Features Page",
375
+ "Homepage",
376
+ "Individual Resource Page",
377
+ "Organic Landing Page",
378
+ "Paid Landing Page (PLP)",
379
+ "Resource Listing",
380
+ "Solutions Page"
381
+ ],
382
+ "Consideration & Evaluation": [
383
+ "Calculator",
384
+ "Competitor Comparison",
385
+ "Demo Long Page",
386
+ "Demo Squeeze",
387
+ "Listing",
388
+ "Pricing Page",
389
+ "Pricing Squeeze",
390
+ "Product Comparison",
391
+ "Product Page (PDP)",
392
+ "Quote",
393
+ "Trial Long Page",
394
+ "Trial Squeeze",
395
+ "Webinar"
396
+ ],
397
+ "Conversion": [
398
+ "Booking",
399
+ "Checkout",
400
+ "Contact Sales",
401
+ "Contact Us",
402
+ "Donate",
403
+ "Quiz/Survey",
404
+ "Shopping Cart",
405
+ "Signup"
406
+ ],
407
+ "Internal & Navigation": [
408
+ "Internal Page",
409
+ "Locations / Map",
410
+ "Login",
411
+ "Navigation",
412
+ "Search",
413
+ "Sitewide"
414
+ ],
415
+ "Post-Conversion & Other": [
416
+ "About Us",
417
+ "Awards",
418
+ "Cancellation",
419
+ "Careers",
420
+ "In-App",
421
+ "Other",
422
+ "Support",
423
+ "Thank You"
424
+ ]
425
+ },
426
+ "conversion_type_mappings": {
427
+ "Direct Purchase": [
428
+ "Buy Now",
429
+ "Reservation / Booking",
430
+ "Subscription (No Free Trial)"
431
+ ],
432
+ "High-Intent Lead Gen": [
433
+ "Request Demo/Contact Sales",
434
+ "See Pricing/Request Quote",
435
+ "Start Free Trial/Signup"
436
+ ],
437
+ "Info/Content Lead Gen": [
438
+ "Download Asset / App",
439
+ "Register for Webinar/Event",
440
+ "Request Information",
441
+ "Subscribe to Newsletter/Mailing List"
442
+ ],
443
+ "Location Search": [
444
+ "Find a Branch/Seller/Provider"
445
+ ],
446
+ "Non-Profit/Community": [
447
+ "Donate",
448
+ "Leave a Review"
449
+ ],
450
+ "Other Conversion": [
451
+ "Link to Partner Product",
452
+ "Other",
453
+ "zz-Pending"
454
+ ]
455
+ }
456
+ }
test_mapping_feature.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Test script to demonstrate the automatic value mapping feature.
3
+
4
+ This script shows how the API now accepts both specific and parent group values
5
+ for Industry, Page Type, and Conversion Type.
6
+ """
7
+
8
+ import json
9
+
10
+ # Load the mapping.json file
11
+ with open('mapping.json', 'r') as f:
12
+ mappings = json.load(f)
13
+
14
+ def convert_to_parent_group(value, mapping_type):
15
+ """Convert a specific value to its parent group"""
16
+ if mapping_type not in mappings:
17
+ return value
18
+
19
+ mapping_dict = mappings[mapping_type]
20
+
21
+ # Search for the value in all parent groups
22
+ for parent_group, child_values in mapping_dict.items():
23
+ if value in child_values:
24
+ return parent_group
25
+
26
+ # If not found, check if it's already a parent group
27
+ if value in mapping_dict.keys():
28
+ return value
29
+
30
+ return value
31
+
32
+ # Test cases
33
+ test_cases = [
34
+ {
35
+ "name": "Test 1: Specific Industry Value",
36
+ "input": "Accounting Services",
37
+ "mapping_type": "industry_mappings",
38
+ "expected": "B2B Services"
39
+ },
40
+ {
41
+ "name": "Test 2: Specific Page Type Value",
42
+ "input": "Homepage",
43
+ "mapping_type": "page_type_mappings",
44
+ "expected": "Awareness & Discovery"
45
+ },
46
+ {
47
+ "name": "Test 3: Specific Conversion Type Value",
48
+ "input": "Request Demo/Contact Sales",
49
+ "mapping_type": "conversion_type_mappings",
50
+ "expected": "High-Intent Lead Gen"
51
+ },
52
+ {
53
+ "name": "Test 4: Parent Group Value (should remain unchanged)",
54
+ "input": "B2B Software & Tech",
55
+ "mapping_type": "industry_mappings",
56
+ "expected": "B2B Software & Tech"
57
+ },
58
+ {
59
+ "name": "Test 5: Another Specific Industry",
60
+ "input": "Cybersecurity",
61
+ "mapping_type": "industry_mappings",
62
+ "expected": "B2B Software & Tech"
63
+ },
64
+ {
65
+ "name": "Test 6: Pricing Page Type",
66
+ "input": "Pricing Page",
67
+ "mapping_type": "page_type_mappings",
68
+ "expected": "Consideration & Evaluation"
69
+ },
70
+ {
71
+ "name": "Test 7: Buy Now Conversion",
72
+ "input": "Buy Now",
73
+ "mapping_type": "conversion_type_mappings",
74
+ "expected": "Direct Purchase"
75
+ }
76
+ ]
77
+
78
+ print("=" * 80)
79
+ print("TESTING AUTOMATIC VALUE MAPPING FEATURE")
80
+ print("=" * 80)
81
+ print()
82
+
83
+ passed = 0
84
+ failed = 0
85
+
86
+ for test in test_cases:
87
+ result = convert_to_parent_group(test["input"], test["mapping_type"])
88
+ status = "✅ PASS" if result == test["expected"] else "❌ FAIL"
89
+
90
+ if result == test["expected"]:
91
+ passed += 1
92
+ else:
93
+ failed += 1
94
+
95
+ print(f"{status} - {test['name']}")
96
+ print(f" Input: '{test['input']}'")
97
+ print(f" Expected: '{test['expected']}'")
98
+ print(f" Got: '{result}'")
99
+ print()
100
+
101
+ print("=" * 80)
102
+ print(f"SUMMARY: {passed} passed, {failed} failed out of {len(test_cases)} tests")
103
+ print("=" * 80)
104
+ print()
105
+
106
+ # Show some statistics
107
+ print("MAPPING STATISTICS:")
108
+ print(f"- Total Industry Parent Groups: {len(mappings['industry_mappings'])}")
109
+ print(f"- Total Specific Industries: {sum(len(v) for v in mappings['industry_mappings'].values())}")
110
+ print(f"- Total Page Type Parent Groups: {len(mappings['page_type_mappings'])}")
111
+ print(f"- Total Specific Page Types: {sum(len(v) for v in mappings['page_type_mappings'].values())}")
112
+ print(f"- Total Conversion Type Parent Groups: {len(mappings['conversion_type_mappings'])}")
113
+ print(f"- Total Specific Conversion Types: {sum(len(v) for v in mappings['conversion_type_mappings'].values())}")
114
+ print()
115
+
116
+ # Show example API usage
117
+ print("=" * 80)
118
+ print("EXAMPLE API USAGE:")
119
+ print("=" * 80)
120
+ print()
121
+ print("from gradio_client import Client")
122
+ print()
123
+ print('client = Client("SpiralyzeLLC/ABTestPredictor")')
124
+ print()
125
+ print("# Now you can use SPECIFIC values:")
126
+ print("result = client.predict(")
127
+ print(' "control.jpg",')
128
+ print(' "variant.jpg",')
129
+ print(' "SaaS", # Business Model')
130
+ print(' "B2B", # Customer Type')
131
+ print(' "Request Demo/Contact Sales", # Specific conversion type ✨')
132
+ print(' "Cybersecurity", # Specific industry ✨')
133
+ print(' "Homepage", # Specific page type ✨')
134
+ print(' api_name="/predict_with_categorical_data"')
135
+ print(')')
136
+ print()
137
+ print("# The API will automatically convert to:")
138
+ print('# - "Request Demo/Contact Sales" → "High-Intent Lead Gen"')
139
+ print('# - "Cybersecurity" → "B2B Software & Tech"')
140
+ print('# - "Homepage" → "Awareness & Discovery"')
141
+ print()
142
+ print("# Response includes both original and grouped values:")
143
+ print('# result["providedCategories"] # Your original input')
144
+ print('# result["groupedCategories"] # What the model used')
145
+