MogensR's picture
Create examples/README.md
729ba5e

A newer version of the Gradio SDK is available: 5.49.1

Upgrade

BackgroundFX Pro Examples

Welcome to the BackgroundFX Pro examples collection! This directory contains practical, production-ready code examples in multiple programming languages and for various use cases.

πŸš€ Quick Start

  1. Get your API key from BackgroundFX Pro Dashboard
  2. Set environment variable: export BACKGROUNDFX_API_KEY=your-api-key
  3. Choose your language and run the examples

πŸ“ Directory Structure

examples/
β”œβ”€β”€ python/              # Python examples
β”œβ”€β”€ javascript/          # JavaScript/Node.js examples
β”œβ”€β”€ go/                  # Go examples
β”œβ”€β”€ curl/               # cURL command examples
β”œβ”€β”€ integrations/       # Platform integrations
β”œβ”€β”€ notebooks/          # Jupyter notebooks
β”œβ”€β”€ docker/             # Docker configurations
└── use-cases/          # Industry-specific examples

🐍 Python Examples

Basic Usage

cd python
pip install -r requirements.txt
python basic_usage.py

Available Examples:

  • basic_usage.py - Core API operations
  • batch_processing.py - Process multiple images
  • video_processing.py - Video background removal
  • webhook_handler.py - Handle webhooks
  • async_processing.py - Asynchronous operations

🟨 JavaScript Examples

Node.js

cd javascript/node
npm install
node basic_usage.js

Browser/React

cd javascript/browser
# Open react_component.jsx in your React app
# Or open vanilla_js.html in a browser

Available Examples:

  • basic_usage.js - Core API operations
  • express_integration.js - Express.js server
  • websocket_client.js - Real-time updates
  • react_component.jsx - React component

🐹 Go Examples

cd go
go mod download
go run basic_usage.go

Available Examples:

  • basic_usage.go - Core API operations
  • gin_integration.go - Gin framework integration

πŸ”— cURL Examples

cd curl
chmod +x *.sh
./basic_commands.sh

Available Scripts:

  • basic_commands.sh - Essential API calls
  • batch_upload.sh - Batch processing
  • webhook_test.sh - Webhook testing

πŸ”Œ Platform Integrations

WordPress Plugin

cd integrations/wordpress
# Copy to wp-content/plugins/
# Activate in WordPress admin

Shopify App

cd integrations/shopify
npm install
npm run dev

Next.js

cd integrations/nextjs
# Copy components to your Next.js app

Flask

cd integrations/flask
pip install -r requirements.txt
python app.py

πŸ““ Jupyter Notebooks

Interactive notebooks for learning and experimentation:

cd notebooks
jupyter notebook

Available Notebooks:

  • getting_started.ipynb - Interactive tutorial
  • model_comparison.ipynb - Compare different models
  • batch_analysis.ipynb - Batch processing analysis
  • custom_training.ipynb - Train custom models

🐳 Docker Examples

Simple Setup

cd docker/simple
docker-compose up

Full Stack

cd docker/full-stack
docker-compose up -d

Kubernetes

cd docker/kubernetes
kubectl apply -f deployment.yaml

πŸ’Ό Use Cases

E-commerce

Automated product photography workflow:

cd use-cases/e-commerce
python product_automation.py

Features:

  • Batch process product catalogs
  • Generate platform-specific sizes
  • Create marketing variations
  • Shopify/WooCommerce integration

Social Media

Content creation automation:

cd use-cases/social-media
python instagram_stories.py

Features:

  • Story templates
  • Batch processing
  • Auto-resizing
  • Filter effects

Real Estate

Property image enhancement:

cd use-cases/real-estate
python property_images.py

Features:

  • Virtual staging
  • Sky replacement
  • Batch processing
  • MLS compliance

Photography

Professional photo editing:

cd use-cases/photography
python portrait_processing.py

Features:

  • Portrait enhancement
  • Wedding batch processing
  • Background replacement
  • Color grading

πŸ”‘ API Key Setup

Environment Variable (Recommended)

export BACKGROUNDFX_API_KEY=your-api-key-here

Configuration File

Create .env file:

BACKGROUNDFX_API_KEY=your-api-key-here
BACKGROUNDFX_API_URL=https://api.backgroundfx.pro/v1

In Code

client = BackgroundFXClient(api_key="your-api-key-here")

πŸ“Š Performance Tips

Batch Processing

  • Use batch endpoints for multiple images
  • Process in parallel when possible
  • Implement retry logic with exponential backoff

Quality Settings

  • low - Fast processing, good for previews
  • medium - Balanced quality/speed
  • high - Professional quality
  • ultra - Maximum quality

Model Selection

  • rembg - Fast, general purpose
  • u2net - High quality, good for products
  • sam2 - Best quality, slower
  • auto - Let API choose

πŸ”§ Common Issues

Rate Limiting

# Implement exponential backoff
import time

def retry_with_backoff(func, max_retries=3):
    for i in range(max_retries):
        try:
            return func()
        except RateLimitError:
            wait_time = 2 ** i
            time.sleep(wait_time)
    raise Exception("Max retries exceeded")

Large Files

# Compress before upload
from PIL import Image

def compress_image(path, max_size_mb=10):
    img = Image.open(path)
    img.thumbnail((4096, 4096))
    img.save(path, optimize=True, quality=85)

Memory Management

# Process in chunks for large batches
def process_in_chunks(images, chunk_size=10):
    for i in range(0, len(images), chunk_size):
        chunk = images[i:i+chunk_size]
        process_batch(chunk)

πŸ“š Additional Resources

🀝 Contributing

We welcome contributions! To add new examples:

  1. Fork the repository
  2. Create your example following the existing structure
  3. Add documentation
  4. Submit a pull request

πŸ“„ License

All examples are provided under the MIT License. Feel free to use them in your projects!

πŸ†˜ Support


Happy coding! πŸŽ‰ Build amazing things with BackgroundFX Pro!