Spaces:
Runtime error
Runtime error
File size: 4,708 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 |
"""
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')
|