Survey

This script allows the AI-supported evaluation of images via a web interface or the command line. The results can be saved as CSV files for data analysis and/or as XMP sidecar files for integration into image management programs such as Darktable.

functions

  • AI-supported rating: Images are rated by a local AI.
  • Flexible design: Use via a web interface or directly from the command line.
  • Result storage: Saves reviews as CSV files and/or XMP sidecar files.
  • Customizable Prompts: System and user prompts can be configured to control the evaluation criteria and output format of the AI.
  • Image conversion: used Darktable CLI For converting original images to temporary JPEG files for AI analysis.
  • Progress Tracking: In web mode, the progress of image processing can be tracked.

Requirements

  • Python 3: A current version of Python.
  • pip: The Python package manager.
  • Darktable: Open source photo editing software. Darktable CLI Must be available in the system path (PATH).
  • LM Studio or a compatible local AI API: A running instance that corresponds to the OpenAI standard and accessible under the configured URL (default: http://localhost:1234/v1/chat/completions).

Installing the Python Dependencies

Open your terminal or command line and run the following command:

Fish
pip install pandas flask requests  

file structure

Make sure the following files are in the same directory:

  • ai-rating.py: The main script.
  • ai_rating_utils.py: A common functions auxiliary file.
  • prompt.txt: Contains the user prompt for the AI rating.
  • system_prompt.txt: Contains the system prompt that tells the AI how to rate the images.
  • template.html: The HTML template for the web interface.

If prompt.txt Oder system_prompt.txt If they do not exist, they are created when the script is first started with standard content.

Configuration of the Prompts

The AI rating is based on two prompts:

  • system_prompt.txt: Defines the evaluation criteria and the desired output format of the AI.
  • prompt.txt: Contains the instruction to the AI to analyze and evaluate the image.

These files can be edited manually or adjusted and saved in Web mode via the user interface.

Execution of the script

Console Mode

Useful for batch processing images without a graphical interface.

Syntax:

Fish
python Ai-Rating.py <folder_path> [--subfolders] [--model <model_tag>] [--no-skip] [--csv] [--xmp] [--api-url <url>]  

Arguments:

  • <folder_path>: The path to the folder that contains the images to be evaluated (mandatory argument).
  • --subfolders: (Optional) Also processes images in subfolders.
  • --model <model_tag>: (Optional) A tag for the AI model used.
  • --no-skip: (Optional) Reprocesses images even if results already exist.
  • --csv: (mandatory argument if --XMP is not specified) saves results in a CSV file.
  • --XMP: (mandatory argument if --csv is not specified) saves results in XMP sidecar files.
  • --api-url <url>: (Optional) Overrides the LM Studio API’s default URL.
Web Mode

Provides a user-friendly interface in the browser.

Starting the server:

Fish
python Ai-Rating.py [--host <host_address>] [--port <port_number>] [--api-url <url>]  

Arguments:

  • --host <host_address>: (optional) The host address (default: 127.0.0.1).
  • --port <port_number>: (optional) The port (default: 5000).
  • --api-url <url>: (Optional) Overrides the LM Studio API’s default URL.

After starting the server, navigate to the displayed address (default http://127.0.0.1:5000).

Operation

  1. Image Conversion: Darktable CLI Converts original images to temporary JPEG files.
  2. AI rating: The JPEGs are sent to the local API along with the prompts.
  3. Result Parsing: The AI answer is parsed to extract evaluation criteria, overall rating and keywords.
  4. Save the results:
    • CSV: Results are in ai_rating_results_<model_tag>.csv saved.
    • XMP: XMP sidecar files are created or updated for each image.

Troubleshooting

  • Darktable CLI not found: Make sure DarkTable is installed and the path to Darktable CLI included in your system path variable.
  • API error: Check whether the local AI API is running and is reachable.
  • Prompt not found: The script created prompt.txt and system_prompt.txt automatically.
  • No output (CSV/XMP): Make sure the appropriate options are enabled in Console or Web Mode.

changelog

  • V2.1: Improved error handling, timing logs
  • V2.0: First version with XMP support

support

For questions, bugs or posts: www.net-fx.de, have fun with AI-supported tagging! 📸🤖