A newer version of the Gradio SDK is available:
5.49.1
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
- Get your API key from BackgroundFX Pro Dashboard
- Set environment variable:
export BACKGROUNDFX_API_KEY=your-api-key - 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 operationsbatch_processing.py- Process multiple imagesvideo_processing.py- Video background removalwebhook_handler.py- Handle webhooksasync_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 operationsexpress_integration.js- Express.js serverwebsocket_client.js- Real-time updatesreact_component.jsx- React component
πΉ Go Examples
cd go
go mod download
go run basic_usage.go
Available Examples:
basic_usage.go- Core API operationsgin_integration.go- Gin framework integration
π cURL Examples
cd curl
chmod +x *.sh
./basic_commands.sh
Available Scripts:
basic_commands.sh- Essential API callsbatch_upload.sh- Batch processingwebhook_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 tutorialmodel_comparison.ipynb- Compare different modelsbatch_analysis.ipynb- Batch processing analysiscustom_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 previewsmedium- Balanced quality/speedhigh- Professional qualityultra- Maximum quality
Model Selection
rembg- Fast, general purposeu2net- High quality, good for productssam2- Best quality, slowerauto- 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:
- Fork the repository
- Create your example following the existing structure
- Add documentation
- Submit a pull request
π License
All examples are provided under the MIT License. Feel free to use them in your projects!
π Support
- Email: support@backgroundfx.pro
- Discord: Join our community
- GitHub Issues: Report issues
Happy coding! π Build amazing things with BackgroundFX Pro!