File size: 10,902 Bytes
5b49b49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
"""
Complete Example: Using the A/B Test Predictor API with Automatic Mapping

This example demonstrates how to use the updated API that accepts both
specific and parent group values for Industry, Page Type, and Conversion Type.

The API now automatically converts specific values to parent groups using
mapping.json before feeding them to the model.
"""

from gradio_client import Client

def predict_ab_test_with_specific_values():
    """
    Example showing how to use SPECIFIC values.
    The API will automatically map them to parent groups.
    """
    print("=" * 80)
    print("EXAMPLE 1: Using Specific Values (NEW FEATURE)")
    print("=" * 80)
    print()
    
    # Initialize the client
    client = Client("SpiralyzeLLC/ABTestPredictor")
    
    # Make prediction with SPECIFIC values
    # These will be automatically converted to parent groups
    result = client.predict(
        "path/to/control.jpg",
        "path/to/variant.jpg",
        "SaaS",                           # Business Model (no mapping needed)
        "B2B",                            # Customer Type (no mapping needed)
        "Request Demo/Contact Sales",     # Will map to: High-Intent Lead Gen
        "Cybersecurity",                  # Will map to: B2B Software & Tech
        "Homepage",                       # Will map to: Awareness & Discovery
        api_name="/predict_with_categorical_data"
    )
    
    print("πŸ“₯ INPUT:")
    print(f"   Industry: {result['providedCategories']['industry']}")
    print(f"   Page Type: {result['providedCategories']['pageType']}")
    print(f"   Conversion Type: {result['providedCategories']['conversionType']}")
    print()
    
    print("πŸ”„ AUTO-MAPPED TO:")
    print(f"   Industry: {result['groupedCategories']['industry']}")
    print(f"   Page Type: {result['groupedCategories']['pageType']}")
    print(f"   Conversion Type: {result['groupedCategories']['conversionType']}")
    print()
    
    print("🎯 PREDICTION RESULTS:")
    print(f"   Win Probability: {result['predictionResults']['probability']}")
    print(f"   Model Confidence: {result['predictionResults']['modelConfidence']}%")
    print(f"   Training Samples: {result['predictionResults']['trainingDataSamples']}")
    print()
    
    return result


def predict_ab_test_with_parent_groups():
    """
    Example showing traditional usage with parent groups.
    This still works exactly as before (backward compatible).
    """
    print("=" * 80)
    print("EXAMPLE 2: Using Parent Groups (TRADITIONAL METHOD)")
    print("=" * 80)
    print()
    
    client = Client("SpiralyzeLLC/ABTestPredictor")
    
    # Make prediction with PARENT GROUP values
    result = client.predict(
        "path/to/control.jpg",
        "path/to/variant.jpg",
        "SaaS",
        "B2B",
        "High-Intent Lead Gen",          # Parent group value
        "B2B Software & Tech",            # Parent group value
        "Awareness & Discovery",          # Parent group value
        api_name="/predict_with_categorical_data"
    )
    
    print("πŸ“₯ INPUT (Parent Groups):")
    print(f"   Industry: {result['providedCategories']['industry']}")
    print(f"   Page Type: {result['providedCategories']['pageType']}")
    print(f"   Conversion Type: {result['providedCategories']['conversionType']}")
    print()
    
    print("🎯 PREDICTION RESULTS:")
    print(f"   Win Probability: {result['predictionResults']['probability']}")
    print(f"   Model Confidence: {result['predictionResults']['modelConfidence']}%")
    print()
    
    return result


def batch_predictions_with_mixed_values():
    """
    Example showing batch processing with mixed values
    (some specific, some parent groups).
    """
    print("=" * 80)
    print("EXAMPLE 3: Batch Processing with Mixed Values")
    print("=" * 80)
    print()
    
    client = Client("SpiralyzeLLC/ABTestPredictor")
    
    test_cases = [
        {
            "name": "E-commerce Checkout Test",
            "business_model": "E-Commerce",
            "customer_type": "B2C",
            "conversion_type": "Buy Now",              # Specific β†’ Direct Purchase
            "industry": "Apparel & Accessories ",       # Specific β†’ Retail & E-commerce
            "page_type": "Checkout"                     # Specific β†’ Conversion
        },
        {
            "name": "SaaS Pricing Page Test",
            "business_model": "SaaS",
            "customer_type": "B2B",
            "conversion_type": "High-Intent Lead Gen",  # Parent group
            "industry": "B2B Software & Tech",          # Parent group
            "page_type": "Pricing Page"                 # Specific β†’ Consideration & Evaluation
        },
        {
            "name": "Healthcare Portal Test",
            "business_model": "Lead Generation",
            "customer_type": "B2C",
            "conversion_type": "Request Information",   # Specific β†’ Info/Content Lead Gen
            "industry": "Healthcare",                   # Specific β†’ Health & Wellness
            "page_type": "Contact Us"                   # Specific β†’ Conversion
        }
    ]
    
    results = []
    
    for i, test in enumerate(test_cases):
        print(f"πŸ“Š Test {i+1}: {test['name']}")
        print(f"   Input: {test['industry']} | {test['page_type']} | {test['conversion_type']}")
        
        # Note: In a real scenario, you'd provide actual image paths
        result = client.predict(
            f"control_{i}.jpg",
            f"variant_{i}.jpg",
            test['business_model'],
            test['customer_type'],
            test['conversion_type'],
            test['industry'],
            test['page_type'],
            api_name="/predict_with_categorical_data"
        )
        
        print(f"   Mapped: {result['groupedCategories']['industry']} | "
              f"{result['groupedCategories']['pageType']} | "
              f"{result['groupedCategories']['conversionType']}")
        print(f"   Probability: {result['predictionResults']['probability']}")
        print()
        
        results.append(result)
    
    return results


def mapping_reference_guide():
    """
    Quick reference guide showing common mappings.
    """
    print("=" * 80)
    print("MAPPING REFERENCE GUIDE")
    print("=" * 80)
    print()
    
    print("πŸ“Œ COMMON INDUSTRY MAPPINGS:")
    industry_mappings = {
        "Accounting Services": "B2B Services",
        "Marketing Agency": "B2B Services",
        "Consulting Services": "B2B Services",
        "Cybersecurity": "B2B Software & Tech",
        "CRM Software": "B2B Software & Tech",
        "Marketing Automation Software": "B2B Software & Tech",
        "Healthcare": "Health & Wellness",
        "Pharmaceuticals": "Health & Wellness",
        "Hotels, Lodging, Resorts and Cruises": "Food, Hospitality & Travel",
        "Restaurants, Food & Beverage": "Food, Hospitality & Travel",
        "Real Estate": "Finance, Insurance & Real Estate",
        "Insurance": "Finance, Insurance & Real Estate"
    }
    
    for specific, parent in industry_mappings.items():
        print(f"   '{specific}' β†’ '{parent}'")
    print()
    
    print("πŸ“Œ COMMON PAGE TYPE MAPPINGS:")
    page_mappings = {
        "Homepage": "Awareness & Discovery",
        "Blog / Content": "Awareness & Discovery",
        "Features Page": "Awareness & Discovery",
        "Pricing Page": "Consideration & Evaluation",
        "Demo Squeeze": "Consideration & Evaluation",
        "Product Page (PDP)": "Consideration & Evaluation",
        "Checkout": "Conversion",
        "Contact Sales": "Conversion",
        "Signup": "Conversion",
        "Login": "Internal & Navigation",
        "Navigation": "Internal & Navigation",
        "Thank You": "Post-Conversion & Other"
    }
    
    for specific, parent in page_mappings.items():
        print(f"   '{specific}' β†’ '{parent}'")
    print()
    
    print("πŸ“Œ COMMON CONVERSION TYPE MAPPINGS:")
    conversion_mappings = {
        "Request Demo/Contact Sales": "High-Intent Lead Gen",
        "Start Free Trial/Signup": "High-Intent Lead Gen",
        "See Pricing/Request Quote": "High-Intent Lead Gen",
        "Buy Now": "Direct Purchase",
        "Reservation / Booking": "Direct Purchase",
        "Subscription (No Free Trial)": "Direct Purchase",
        "Download Asset / App": "Info/Content Lead Gen",
        "Register for Webinar/Event": "Info/Content Lead Gen",
        "Subscribe to Newsletter/Mailing List": "Info/Content Lead Gen",
        "Find a Branch/Seller/Provider": "Location Search",
        "Donate": "Non-Profit/Community"
    }
    
    for specific, parent in conversion_mappings.items():
        print(f"   '{specific}' β†’ '{parent}'")
    print()


def benefits_summary():
    """
    Summary of benefits from the new mapping feature.
    """
    print("=" * 80)
    print("✨ BENEFITS OF AUTOMATIC MAPPING")
    print("=" * 80)
    print()
    
    benefits = [
        "βœ… Send your own specific categorization (339 industries supported)",
        "βœ… No need to learn or memorize parent group names",
        "βœ… API handles conversion automatically",
        "βœ… Response shows both original and mapped values",
        "βœ… Backward compatible - parent groups still work",
        "βœ… More accurate categorization possible",
        "βœ… Easier integration with existing systems",
        "βœ… Better tracking of what was actually provided vs used"
    ]
    
    for benefit in benefits:
        print(f"   {benefit}")
    print()


if __name__ == "__main__":
    print("\n")
    print("πŸš€ A/B TEST PREDICTOR API - AUTOMATIC MAPPING DEMO")
    print("\n")
    
    # Show mapping reference
    mapping_reference_guide()
    
    # Show benefits
    benefits_summary()
    
    print("=" * 80)
    print("USAGE EXAMPLES")
    print("=" * 80)
    print()
    
    print("ℹ️  NOTE: The following examples show the structure.")
    print("   To run them, uncomment the function calls and provide valid image paths.")
    print()
    
    # Uncomment these to run actual predictions:
    # predict_ab_test_with_specific_values()
    # predict_ab_test_with_parent_groups()
    # batch_predictions_with_mixed_values()
    
    print("=" * 80)
    print("STATISTICS")
    print("=" * 80)
    print()
    print("πŸ“Š Supported Values:")
    print("   - 339 specific industry values β†’ 14 parent groups")
    print("   - 43 specific page type values β†’ 5 parent groups")
    print("   - 16 specific conversion type values β†’ 6 parent groups")
    print()
    print("πŸ“‚ For complete list, see: mapping.json")
    print()
    print("=" * 80)
    print("DOCUMENTATION")
    print("=" * 80)
    print()
    print("πŸ“– Full API Documentation: API_DOCUMENTATION.md")
    print("πŸ“ Update Summary: MAPPING_UPDATE_SUMMARY.md")
    print("πŸ§ͺ Test Script: test_mapping_feature.py")
    print()