Spaces:
Runtime error
Runtime error
File size: 5,700 Bytes
e749f25 |
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 |
# A/B Test Predictor API - Updated Usage Guide
## Overview
The A/B Test Predictor API now accepts **both image inputs and categorical data** directly from API calls. All AI-powered auto-categorization features (Perplexity and Gemini API calls) have been removed for a more streamlined, efficient prediction service.
## What Changed
### β
Added
- Direct categorical data input via API
- Simplified prediction endpoint that accepts both images and metadata
- Cleaner JSON response format with confidence scores
### β Removed
- Perplexity API integration (auto-categorization)
- Gemini API integration (pattern detection)
- All external AI API calls
- `requests` dependency
- Unnecessary imports (`base64`, `BytesIO`)
## API Endpoint
### `predict_with_categorical_data`
**Purpose**: Make A/B test predictions with provided images and categorical data.
**Inputs**:
1. `control_image` (numpy array/image): The control version image
2. `variant_image` (numpy array/image): The variant version image
3. `business_model` (string): One of:
- E-Commerce
- Lead Generation
- Other*
- SaaS
4. `customer_type` (string): One of:
- B2B
- B2C
- Both
- Other*
5. `conversion_type` (string): One of:
- Direct Purchase
- High-Intent Lead Gen
- Info/Content Lead Gen
- Location Search
- Non-Profit/Community
- Other Conversion
6. `industry` (string): One of:
- 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
7. `page_type` (string): One of:
- Awareness & Discovery
- Consideration & Evaluation
- Conversion
- Internal & Navigation
- Post-Conversion & Other
**Output**: JSON object with the following structure:
```json
{
"predictionResults": {
"probability": "0.682",
"modelConfidence": "66.1",
"trainingDataSamples": 14634,
"totalPredictions": 1626,
"correctPredictions": 1074,
"totalWinPrediction": 667,
"totalLosePrediction": 959
},
"providedCategories": {
"businessModel": "SaaS",
"customerType": "B2B",
"conversionType": "High-Intent Lead Gen",
"industry": "B2B Software & Tech",
"pageType": "Awareness & Discovery"
},
"processingInfo": {
"totalProcessingTime": "2.34s",
"confidenceSource": "B2B Software & Tech | Awareness & Discovery"
}
}
```
## Response Fields Explained
### predictionResults
- **probability**: Win probability for the variant (0-1 scale, >0.5 means variant wins)
- **modelConfidence**: Model accuracy percentage based on historical data for this category combination
- **trainingDataSamples**: Number of training samples used for this category combination
- **totalPredictions**: Total test predictions made for this category combination
- **correctPredictions**: Number of correct predictions for this category combination
- **totalWinPrediction**: Number of actual wins in the historical data
- **totalLosePrediction**: Number of actual losses in the historical data
### providedCategories
- Echo back of the categorical inputs provided by the user
### processingInfo
- **totalProcessingTime**: Time taken for the prediction
- **confidenceSource**: The Industry + Page Type combination used for confidence scoring
## Confidence Scoring
Confidence scores are based on **Industry + Page Type combinations** from historical A/B test data. This provides more reliable confidence metrics compared to using all 5 categorical features, as these 2-feature combinations have higher sample counts (average ~160 samples per combination).
## Example Usage (Python)
```python
import requests
import numpy as np
from PIL import Image
# Load your images
control_img = Image.open("control.jpg")
variant_img = Image.open("variant.jpg")
# Convert to numpy arrays
control_array = np.array(control_img)
variant_array = np.array(variant_img)
# Make prediction (via Gradio interface or direct function call)
result = predict_with_categorical_data(
control_image=control_array,
variant_image=variant_array,
business_model="SaaS",
customer_type="B2B",
conversion_type="High-Intent Lead Gen",
industry="B2B Software & Tech",
page_type="Awareness & Discovery"
)
print(f"Win Probability: {result['predictionResults']['probability']}")
print(f"Model Confidence: {result['predictionResults']['modelConfidence']}%")
print(f"Based on {result['predictionResults']['trainingDataSamples']} training samples")
```
## Gradio Interface
The application now has two main tabs:
1. **π― API Prediction**: Primary interface for predictions with categorical data
2. **π Manual Selection**: Alternative interface with dropdown menus
3. **Batch Prediction from CSV**: For processing multiple tests at once
## Performance
- Average prediction time: 2-4 seconds (GPU-accelerated)
- No external API latency (all processing is local)
- Supports concurrent requests with queue management
- Optimized for 4x L4 GPU setup
## Migration Notes
If you were previously using the auto-categorization feature:
1. You now need to provide categorical data directly
2. The response format has changed slightly (see above)
3. Pattern detection is no longer included in the response
4. Processing is now faster without external API calls
## Need Help?
For questions or issues, refer to:
- `README.md` - General project documentation
- `setup_instructions.md` - Setup and deployment guide
- `confidence_scores.json` - Historical confidence data
|