Fashion Analyzer
A modular Gemini Vision batch analyzer for fashion product images.
Prerequisites
- Python 3.10+
- Set Gemini API key in your shell:
OR
$env:GEMINI_API_KEY="YOUR_KEY_HERE"
export GEMINI_API_KEY="YOUR_KEY_HERE"
- Install dependencies:
pip install -r requirements.txt
Run
From this folder:
python main.py "path/to/images.zip"Optional output filename:
python main.py "path/to/images.zip" -o my_results.csvConfiguration
Edit config.json in this folder. Key settings:
apimodel,api_key_env_varimages_per_request: prefer 2 (max supported 3)max_concurrent: concurrent requests per batchwait_between_batches_seconds: pause between batchesmax_retries,retry_delay_seconds: retry basicsbackoff_multiplier,max_retry_delay_seconds: exponential backoffrespect_server_retry_delay: whether to use server-provided delay hints
processing.batch_size: number of concurrent requests per batchoutput: export options and directorytesting: failure injection toggles for testing retries
Free-tier safe settings (15 RPM) for ~700 images
Set these to avoid rate limits while maintaining good throughput:
{
"api": {
"max_concurrent": 7,
"images_per_request": 2,
"wait_between_batches_seconds": 30.0,
"max_retries": 1,
"retry_delay_seconds": 1.0,
"backoff_multiplier": 2.0,
"max_retry_delay_seconds": 60.0,
"respect_server_retry_delay": true
},
"processing": { "batch_size": 7 }
}- Throughput: ~14 requests/minute → ~25 minutes for 700 images (350 requests at 2 images/request), depending on latency.
Retries and Backoff
- The analyzer retries up to
max_retriesusing exponential backoff:- Delay =
retry_delay_seconds * (backoff_multiplier ** attempt), capped bymax_retry_delay_seconds. - If
respect_server_retry_delayis true and the server provides a hint (e.g.,retry_delay { seconds: N }orRetry-After), the larger delay is used.
- Delay =
Testing failure/retry (optional)
In config.json:
"testing": {
"enabled": true,
"fail_first_requests": 1,
"malformed_json_every_k": 3,
"exception_probability": 0.0
}- Use to validate retry logic; set
enabled: falseto turn off.
Output
- Results:
./results/fashion_analysis_{timestamp}.csvand/or.json - Request stats:
..._request_stats.csvand.json - Console logs show progress, batch timing, token usage, and retry notices.
Project Structure
fashion_analyzer/analyzer.py: core logic (concurrency, retries, parsing, stats)config.py: config loaderutils.py: ZIP extraction and helpersprogress.py: console progress barstats.py: request statistics
main.py: entry point
Troubleshooting
- 429 rate limit: Reduce
max_concurrentor increasewait_between_batches_seconds; considerrespect_server_retry_delay: true. See Gemini API quotas. - Missing API key: Ensure
GEMINI_API_KEYis set in the current shell. - CSV export missing: Install
pandasor setoutput.export_csvto false.
On this page
Contributors
Created August 7, 2025
Updated January 6, 2026