File size: 5,249 Bytes
e93a798
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# ============================================================================
# A/B Test Predictor - cURL API Examples
# ============================================================================

# Configuration
API_URL="http://localhost:7860"  # Change to your deployment URL
# For Hugging Face Spaces: API_URL="https://your-username-abtestpredictor.hf.space"

# ============================================================================
# Example 1: Basic Prediction with Image Files
# ============================================================================

# Convert images to base64
CONTROL_IMAGE_B64=$(base64 -i control_image.jpg)
VARIANT_IMAGE_B64=$(base64 -i variant_image.jpg)

# Send POST request to Gradio API
curl -X POST "${API_URL}/api/predict" \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      "data:image/jpeg;base64,'"${CONTROL_IMAGE_B64}"'",
      "data:image/jpeg;base64,'"${VARIANT_IMAGE_B64}"'",
      "SaaS",
      "B2B",
      "High-Intent Lead Gen",
      "B2B Software & Tech",
      "Awareness & Discovery"
    ],
    "fn_index": 0
  }'

# ============================================================================
# Example 2: Using a Function to Send Requests
# ============================================================================

predict_abtest() {
    local CONTROL_IMG=$1
    local VARIANT_IMG=$2
    local BUSINESS_MODEL=$3
    local CUSTOMER_TYPE=$4
    local CONVERSION_TYPE=$5
    local INDUSTRY=$6
    local PAGE_TYPE=$7
    
    # Encode images
    local CONTROL_B64=$(base64 -i "$CONTROL_IMG")
    local VARIANT_B64=$(base64 -i "$VARIANT_IMG")
    
    # Make API call
    curl -X POST "${API_URL}/api/predict" \
      -H "Content-Type: application/json" \
      -d '{
        "data": [
          "data:image/jpeg;base64,'"${CONTROL_B64}"'",
          "data:image/jpeg;base64,'"${VARIANT_B64}"'",
          "'"${BUSINESS_MODEL}"'",
          "'"${CUSTOMER_TYPE}"'",
          "'"${CONVERSION_TYPE}"'",
          "'"${INDUSTRY}"'",
          "'"${PAGE_TYPE}"'"
        ]
      }' | jq .
}

# Usage
predict_abtest \
  "control.jpg" \
  "variant.jpg" \
  "SaaS" \
  "B2B" \
  "High-Intent Lead Gen" \
  "B2B Software & Tech" \
  "Awareness & Discovery"

# ============================================================================
# Example 3: Multiple Predictions in a Loop
# ============================================================================

# Read test cases from CSV
while IFS=',' read -r control variant business customer conversion industry page
do
    echo "Processing: $control vs $variant"
    
    predict_abtest \
      "$control" \
      "$variant" \
      "$business" \
      "$customer" \
      "$conversion" \
      "$industry" \
      "$page"
    
    sleep 1  # Rate limiting
done < test_cases.csv

# ============================================================================
# Example 4: Save Results to File
# ============================================================================

predict_and_save() {
    local OUTPUT_FILE=$1
    
    predict_abtest \
      "control.jpg" \
      "variant.jpg" \
      "SaaS" \
      "B2B" \
      "High-Intent Lead Gen" \
      "B2B Software & Tech" \
      "Awareness & Discovery" > "$OUTPUT_FILE"
    
    echo "Results saved to $OUTPUT_FILE"
}

predict_and_save "prediction_result.json"

# ============================================================================
# Example 5: Parse and Extract Specific Fields
# ============================================================================

# Get just the win probability
get_win_probability() {
    predict_abtest "$@" | jq -r '.data[0].predictionResults.probability'
}

# Get model confidence
get_confidence() {
    predict_abtest "$@" | jq -r '.data[0].predictionResults.modelConfidence'
}

# Usage
PROB=$(get_win_probability "control.jpg" "variant.jpg" "SaaS" "B2B" "High-Intent Lead Gen" "B2B Software & Tech" "Awareness & Discovery")
CONF=$(get_confidence "control.jpg" "variant.jpg" "SaaS" "B2B" "High-Intent Lead Gen" "B2B Software & Tech" "Awareness & Discovery")

echo "Win Probability: $PROB"
echo "Model Confidence: $CONF%"

# ============================================================================
# Valid Category Values (for reference)
# ============================================================================

# Business Model options:
# - "E-Commerce"
# - "Lead Generation"
# - "Other*"
# - "SaaS"

# Customer Type options:
# - "B2B"
# - "B2C"
# - "Both"
# - "Other*"

# Conversion Type options:
# - "Direct Purchase"
# - "High-Intent Lead Gen"
# - "Info/Content Lead Gen"
# - "Location Search"
# - "Non-Profit/Community"
# - "Other Conversion"

# Industry options:
# - "Automotive & Transportation"
# - "B2B Services"
# - "B2B Software & Tech"
# - "Consumer Services"
# - "Consumer Software & Apps"
# - "Education"
# - "Finance, Insurance & Real Estate"
# - "Food, Hospitality & Travel"
# - "Health & Wellness"
# - "Industrial & Manufacturing"
# - "Media & Entertainment"
# - "Non-Profit & Government"
# - "Other"
# - "Retail & E-commerce"

# Page Type options:
# - "Awareness & Discovery"
# - "Consideration & Evaluation"
# - "Conversion"
# - "Internal & Navigation"
# - "Post-Conversion & Other"