Spaces:
Runtime error
Runtime error
| # 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) | |
| ```python | |
| # 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) | |
| ```python | |
| # 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) | |