Spaces:
Runtime error
Runtime error
| """ | |
| 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() | |