ABTestPredictor / COMPLETE_EXAMPLE_WITH_MAPPING.py
nitish-spz's picture
Mapping of grouped metadata
5b49b49
"""
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()