A high-performance, multi-threaded book description generator that uses the Open router API to generate detailed descriptions for books. This project offers multiple processing modes optimized for different use cases, from development testing to production-scale processing.
- Multiple Processing Modes: Choose between rate-limited (production-safe) and high-performance generators
- Async & Multi-threading Support: Utilizes multiple CPU cores for maximum performance
- Rate Limiting Compliance: Built-in rate limiting to respect API limits (40 requests/minute)
- Real-time Progress Tracking: Live progress updates with completion rates and timing
- Comprehensive Error Handling: Detailed error tracking with separate failed items logging
- Flexible Configuration: Adjustable worker counts, batch sizes, and processing modes
- Dual Output System: Successful results and failed items saved to separate JSON files
- Incremental Batch Saving: Saves processed data after each batch to
batch_processed.jsonfor resilience.
# Clone the repository
git clone git@github.com:kabir0st/CoverCraft-AI.git
cd CoverCraft-AI
# Install dependencies
uv syncCreate a .env file with your Open Router API key:
echo "KEY=your_open_router_api_key_here" > .envEnsure you have an items.json file in the src/ directory with your book data:
[
{
"id": 13625,
"name": "Book Title",
"barcode": "123456789"
}
]For Production (Recommended):
cd src
python run_rate_limited.py --demoFor Development/Testing:
cd src
python run_generator.py --demo- File:
src/rate_limited_generator.py - Rate Limit: Strict 40 requests per minute
- Workers: 6-8 recommended
- Use Case: Production, large datasets, shared API keys
- Safety: Guaranteed API compliance
python src/run_rate_limited.py --workers 8 --batch-size 10- File:
src/libs/async_generator.py - Rate Limit: None (system/API limited)
- Workers: Up to 32 workers
- Use Case: Development, testing, small datasets
- Speed: Maximum performance
python src/run_generator.py --workers 16 --batch-size 25- File:
src/app.py - Type: Sequential processing
- Use Case: Understanding the basic workflow
- Speed: Slow (one at a time)
python src/app.pyThis project includes comprehensive documentation for different aspects:
- Generator Options Guide - Complete comparison of all available generators
- Usage Guide - Detailed usage instructions with examples and best practices
- Rate Limiting Guide - Specialized guide for production-safe rate-limited processing
- Async Generator Guide - High-performance async processing documentation
# Safe, rate-limited processing
python src/run_rate_limited.py --workers 8 --batch-size 10
# Test first with demo
python src/run_rate_limited.py --demo# Fast processing for development
python src/run_generator.py --demo --workers 4
# High performance testing
python src/run_generator.py --workers 16 --batch-size 20High-End Workstation (32+ cores, 64+ GB RAM)
python src/run_generator.py --workers 32 --batch-size 50Standard Laptop (8-16 cores, 16+ GB RAM)
python src/run_rate_limited.py --workers 8 --batch-size 10Budget System (4-8 cores, 8+ GB RAM)
python src/run_rate_limited.py --workers 4 --batch-size 5| Generator | Speed | Safety | Workers | Best For |
|---|---|---|---|---|
| Rate-Limited | 40/min | High | 6-8 | Production |
| High-Performance | System Max | Medium | 16-32 | Development |
| Simple | ~1/min | High | 1 | Learning |
- Rate-Limited:
items_with_descriptions.json - High-Performance:
items_with_descriptions.json - Simple:
items_with_desc.json
- Rate-Limited:
failed_items.json - High-Performance:
failed_items.json
Error: Rate limit exceeded
Solution: Use rate-limited generator
Command: python src/run_rate_limited.py
Error: Out of memory
Solution: Reduce batch size and workers
Command: python src/run_rate_limited.py --workers 4 --batch-size 5
Error: KEY not found in .env
Solution: Create .env file with KEY=your_api_key
python src/run_rate_limited.py --demo- β Production processing
- β Large datasets (100+ items)
- β Shared/company API keys
- β Unattended processing
Watch for the rate indicator: π¦ 38/40/min
Both generators handle Ctrl+C gracefully and save progress.
Always backup your original items.json before processing.
CoverCraft-AI/
βββ README.md # This file - main project overview
βββ GENERATOR_OPTIONS.md # Complete generator comparison guide
βββ USAGE_GUIDE.md # Detailed usage instructions
βββ RATE_LIMITING_GUIDE.md # Production-safe rate limiting guide
βββ README_ASYNC.md # High-performance async guide
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ src/ # Source code directory
βββ rate_limited_generator.py # Production-safe rate-limited generator
βββ run_generator.py # CLI for async generator
βββ run_rate_limited.py # CLI for rate-limited generator (deprecated, use run_generator.py with options)
βββ demo_async.py # Demo script for async generator
βββ items.json # Input data file
βββ system_prompt.txt # System prompt for the generator
βββ libs/ # Core library files
βββ __init__.py
βββ agent.py # Core API interaction logic
βββ async_app.py # Async application (if applicable)
βββ async_generator.py # High-performance async generator
βββ gen.py # General generation utilities (if applicable)
βββ run_async.py # Runner for async operations (if applicable)
βββ run_rate_limited.py # Runner for rate-limited operations (if applicable, might be deprecated)
βββ utils.py # Helper functions
- 50 items: ~2-3 minutes
- 100 items: ~5-6 minutes
- 500 items: ~25-30 minutes
- 1000 items: ~45-50 minutes
- 50 items: ~30 seconds - 2 minutes
- 100 items: ~1-4 minutes
- 500 items: ~5-20 minutes
- 1000 items: ~10-40 minutes
Times depend on system specs and API response times
- Start with Demo:
python src/run_rate_limited.py --demo - Test Small Batch:
python src/run_rate_limited.py --workers 4 --batch-size 5 - Scale Up Gradually:
python src/run_rate_limited.py --workers 8 --batch-size 10 - Full Production Run:
python src/run_rate_limited.py
- Python 3.12+
- 4+ GB RAM (8+ GB recommended)
- Multi-core CPU (4+ cores recommended)
- Stable internet connection
- Valid Open Router API key
- Read the Documentation: Start with the Usage Guide
- Check Common Issues: Review error messages and solutions above
- Examine Failed Items: Check
failed_items.jsonfor specific failures - Try Conservative Settings: Use fewer workers and smaller batches
- Test with Demo Mode: Always test with demo mode first
- New Users: Start with the Usage Guide
- Production Users: Read the Rate Limiting Guide
- Developers: Check the Async Generator Guide
- Comparison Shopping: Review Generator Options
Remember: It's better to process slowly and successfully than to fail fast! Always prioritize API compliance and data integrity over speed.