ABTestPredictor / CHANGELOG_API_UPDATE.md
nitish-spz's picture
Take input from API instead of AI
e749f25

A newer version of the Gradio SDK is available: 6.5.1

Upgrade

API Update Changelog - October 31, 2025

Summary

Migrated from AI-powered auto-categorization to direct categorical data input API. This update removes external AI API dependencies (Perplexity and Gemini) and provides a more straightforward, efficient prediction service.

Changes Made

πŸ”΄ Removed Features

  1. AI API Integrations

    • ❌ Perplexity Sonar Reasoning Pro (business categorization)
    • ❌ Gemini Pro Vision (pattern detection)
    • ❌ All external API calls and dependencies
  2. Functions Removed

    • analyze_images_with_perplexity() - Previously used for auto-categorizing business context
    • detect_pattern_with_gemini() - Previously used for detecting A/B test patterns
    • load_pattern_descriptions() - Pattern data loader (no longer needed)
    • image_to_base64() - Image conversion for API calls
    • predict_with_auto_categorization() - Main auto-prediction function
  3. Dependencies Removed

    • requests library (no external HTTP calls)
    • base64 module (no image encoding needed)
    • BytesIO from io module (no in-memory buffer needed)
    • concurrent.futures (no parallel API calls needed)
  4. Configuration Removed

    • PERPLEXITY_API_KEY environment variable
    • PERPLEXITY_API_URL constant
    • GEMINI_API_KEY environment variable
    • GEMINI_API_URL constant
    • pattern_descriptions global variable

🟒 Added Features

  1. New Main Function

    • predict_with_categorical_data() - Accepts images + categorical data directly
    • Clean, focused API with no external dependencies
    • Faster response times (no network latency)
  2. Enhanced Response Format

    • Simplified JSON structure
    • Clear separation of prediction results, provided categories, and processing info
    • All confidence metrics included in single response
  3. Updated Gradio Interface

    • Renamed "πŸ€– Smart Auto-Prediction" tab to "🎯 API Prediction"
    • Updated descriptions to reflect direct input requirement
    • Cleaner UI focused on manual categorical selection

πŸ“ Modified Features

  1. predict_single()

    • No changes to core functionality
    • Still handles image processing, OCR, and model inference
    • Returns same detailed prediction results
  2. get_confidence_data()

    • No changes - still uses Industry + Page Type for confidence scoring
    • Maintains same fallback logic
  3. Gradio Interface Layout

    • Tab 1: "🎯 API Prediction" (replaces auto-prediction)
    • Tab 2: "πŸ“‹ Manual Selection" (unchanged)
    • Tab 3: "Batch Prediction from CSV" (unchanged)

File Changes

Modified Files

  1. app.py

    • Removed ~400 lines of AI API code
    • Added new predict_with_categorical_data() function
    • Updated Gradio interface
    • Cleaned up imports
  2. requirements.txt

    • Removed: requests
    • Kept all other dependencies (torch, transformers, gradio, etc.)
  3. README.md

    • Updated overview section
    • Removed AI architecture section
    • Removed API key requirements
    • Added reference to API_USAGE_UPDATED.md

New Files

  1. API_USAGE_UPDATED.md

    • Complete API documentation
    • Input/output specifications
    • Example usage code
    • Migration guide
  2. CHANGELOG_API_UPDATE.md (this file)

    • Detailed change log
    • Migration instructions

API Changes

Before (Auto-Categorization)

# Input: Only images
result = predict_with_auto_categorization(
    control_image=control_img,
    variant_image=variant_img
)

# Output: Included auto-detected categories and patterns
{
    "predictionResults": {...},
    "autoDetectedCategories": {...},
    "detectedPattern": {...},
    "processingInfo": {...}
}

After (Direct Input)

# Input: Images + Categorical data
result = predict_with_categorical_data(
    control_image=control_img,
    variant_image=variant_img,
    business_model="SaaS",
    customer_type="B2B",
    conversion_type="High-Intent Lead Gen",
    industry="B2B Software & Tech",
    page_type="Awareness & Discovery"
)

# Output: Prediction with provided categories
{
    "predictionResults": {...},
    "providedCategories": {...},
    "processingInfo": {...}
}

Migration Guide

For Existing Users

If you were using the auto-categorization feature:

  1. Determine Categories: You'll need to provide categorical data explicitly

    • Business Model (4 options)
    • Customer Type (4 options)
    • Conversion Type (6 options)
    • Industry (14 options)
    • Page Type (5 options)
  2. Update API Calls: Change from predict_with_auto_categorization() to predict_with_categorical_data()

  3. Update Response Handling:

    • Remove pattern detection logic
    • Use providedCategories instead of autoDetectedCategories
  4. Remove API Keys: No longer need PERPLEXITY_API_KEY or GEMINI_API_KEY

Benefits of Migration

βœ… Faster: No external API latency (2-4s vs 10-15s previously) βœ… Cheaper: No external API costs βœ… Simpler: Direct input/output, no complex AI logic βœ… More Reliable: No dependency on external services βœ… More Control: User decides categorization instead of AI

Performance Comparison

Before (With AI APIs)

  • Average processing time: 10-15 seconds
  • External API calls: 2 (Perplexity + Gemini)
  • Cost per prediction: ~$0.01-0.02
  • Failure points: 3 (Perplexity, Gemini, Model)

After (Direct Input)

  • Average processing time: 2-4 seconds
  • External API calls: 0
  • Cost per prediction: GPU compute only
  • Failure points: 1 (Model only)

Testing Recommendations

  1. Verify categorical mappings: Ensure all category values match expected options
  2. Test confidence scoring: Verify Industry + Page Type combinations return correct stats
  3. Batch testing: Test with multiple samples to ensure consistency
  4. Error handling: Test with invalid categories to ensure proper error messages

Support

For issues or questions:

  • See API_USAGE_UPDATED.md for detailed documentation
  • Check confidence_scores.json for available category combinations
  • Review README.md for general information

Version Info

  • Previous Version: Auto-categorization with Perplexity + Gemini
  • Current Version: Direct categorical input
  • Update Date: October 31, 2025
  • Breaking Changes: Yes (API signature changed)