ABTestPredictor / test_mapping_feature.py
nitish-spz's picture
Mapping of grouped metadata
5b49b49
"""
Test script to demonstrate the automatic value mapping feature.
This script shows how the API now accepts both specific and parent group values
for Industry, Page Type, and Conversion Type.
"""
import json
# Load the mapping.json file
with open('mapping.json', 'r') as f:
mappings = json.load(f)
def convert_to_parent_group(value, mapping_type):
"""Convert a specific value to its parent group"""
if mapping_type not in mappings:
return value
mapping_dict = mappings[mapping_type]
# Search for the value in all parent groups
for parent_group, child_values in mapping_dict.items():
if value in child_values:
return parent_group
# If not found, check if it's already a parent group
if value in mapping_dict.keys():
return value
return value
# Test cases
test_cases = [
{
"name": "Test 1: Specific Industry Value",
"input": "Accounting Services",
"mapping_type": "industry_mappings",
"expected": "B2B Services"
},
{
"name": "Test 2: Specific Page Type Value",
"input": "Homepage",
"mapping_type": "page_type_mappings",
"expected": "Awareness & Discovery"
},
{
"name": "Test 3: Specific Conversion Type Value",
"input": "Request Demo/Contact Sales",
"mapping_type": "conversion_type_mappings",
"expected": "High-Intent Lead Gen"
},
{
"name": "Test 4: Parent Group Value (should remain unchanged)",
"input": "B2B Software & Tech",
"mapping_type": "industry_mappings",
"expected": "B2B Software & Tech"
},
{
"name": "Test 5: Another Specific Industry",
"input": "Cybersecurity",
"mapping_type": "industry_mappings",
"expected": "B2B Software & Tech"
},
{
"name": "Test 6: Pricing Page Type",
"input": "Pricing Page",
"mapping_type": "page_type_mappings",
"expected": "Consideration & Evaluation"
},
{
"name": "Test 7: Buy Now Conversion",
"input": "Buy Now",
"mapping_type": "conversion_type_mappings",
"expected": "Direct Purchase"
}
]
print("=" * 80)
print("TESTING AUTOMATIC VALUE MAPPING FEATURE")
print("=" * 80)
print()
passed = 0
failed = 0
for test in test_cases:
result = convert_to_parent_group(test["input"], test["mapping_type"])
status = "βœ… PASS" if result == test["expected"] else "❌ FAIL"
if result == test["expected"]:
passed += 1
else:
failed += 1
print(f"{status} - {test['name']}")
print(f" Input: '{test['input']}'")
print(f" Expected: '{test['expected']}'")
print(f" Got: '{result}'")
print()
print("=" * 80)
print(f"SUMMARY: {passed} passed, {failed} failed out of {len(test_cases)} tests")
print("=" * 80)
print()
# Show some statistics
print("MAPPING STATISTICS:")
print(f"- Total Industry Parent Groups: {len(mappings['industry_mappings'])}")
print(f"- Total Specific Industries: {sum(len(v) for v in mappings['industry_mappings'].values())}")
print(f"- Total Page Type Parent Groups: {len(mappings['page_type_mappings'])}")
print(f"- Total Specific Page Types: {sum(len(v) for v in mappings['page_type_mappings'].values())}")
print(f"- Total Conversion Type Parent Groups: {len(mappings['conversion_type_mappings'])}")
print(f"- Total Specific Conversion Types: {sum(len(v) for v in mappings['conversion_type_mappings'].values())}")
print()
# Show example API usage
print("=" * 80)
print("EXAMPLE API USAGE:")
print("=" * 80)
print()
print("from gradio_client import Client")
print()
print('client = Client("SpiralyzeLLC/ABTestPredictor")')
print()
print("# Now you can use SPECIFIC values:")
print("result = client.predict(")
print(' "control.jpg",')
print(' "variant.jpg",')
print(' "SaaS", # Business Model')
print(' "B2B", # Customer Type')
print(' "Request Demo/Contact Sales", # Specific conversion type ✨')
print(' "Cybersecurity", # Specific industry ✨')
print(' "Homepage", # Specific page type ✨')
print(' api_name="/predict_with_categorical_data"')
print(')')
print()
print("# The API will automatically convert to:")
print('# - "Request Demo/Contact Sales" β†’ "High-Intent Lead Gen"')
print('# - "Cybersecurity" β†’ "B2B Software & Tech"')
print('# - "Homepage" β†’ "Awareness & Discovery"')
print()
print("# Response includes both original and grouped values:")
print('# result["providedCategories"] # Your original input')
print('# result["groupedCategories"] # What the model used')