GitHunt
FA

FayyazAK/Fashion-Analyser-Gemini

Fashion Analyzer

A modular Gemini Vision batch analyzer for fashion product images.

Prerequisites

  • Python 3.10+
  • Set Gemini API key in your shell:
    $env:GEMINI_API_KEY="YOUR_KEY_HERE"
    OR
    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.csv

Configuration

Edit config.json in this folder. Key settings:

  • api
    • model, api_key_env_var
    • images_per_request: prefer 2 (max supported 3)
    • max_concurrent: concurrent requests per batch
    • wait_between_batches_seconds: pause between batches
    • max_retries, retry_delay_seconds: retry basics
    • backoff_multiplier, max_retry_delay_seconds: exponential backoff
    • respect_server_retry_delay: whether to use server-provided delay hints
  • processing.batch_size: number of concurrent requests per batch
  • output: export options and directory
  • testing: 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_retries using exponential backoff:
    • Delay = retry_delay_seconds * (backoff_multiplier ** attempt), capped by max_retry_delay_seconds.
    • If respect_server_retry_delay is true and the server provides a hint (e.g., retry_delay { seconds: N } or Retry-After), the larger delay is used.

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: false to turn off.

Output

  • Results: ./results/fashion_analysis_{timestamp}.csv and/or .json
  • Request stats: ..._request_stats.csv and .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 loader
    • utils.py: ZIP extraction and helpers
    • progress.py: console progress bar
    • stats.py: request statistics
  • main.py: entry point

Troubleshooting

  • 429 rate limit: Reduce max_concurrent or increase wait_between_batches_seconds; consider respect_server_retry_delay: true. See Gemini API quotas.
  • Missing API key: Ensure GEMINI_API_KEY is set in the current shell.
  • CSV export missing: Install pandas or set output.export_csv to false.
FayyazAK/Fashion-Analyser-Gemini | GitHunt