This Python script uses the GPT-4 Vision API to label images in a specified directory and sort them into subdirectories based on their labels.
- Python 3.6 or higher
- OpenAI API key
- aiohttp library
- configparser library
- glob library
- logging library
- openai library
- requests library
- shutil library
- Clone the repository.
- Install the required Python libraries using pip:
pip3 install -r requirements.txt
- Open the
config.ini
file. - Set the
API_KEY
under the OpenAI section to your OpenAI API key. - Set the
SOURCE_DIRECTORY
under the Directories section to the root source directory for your images.
- Run the script using Python:
python3 main.py
The script will find all images in the source directory and its subdirectories, send them to the OpenAI API for labelling, and then sort them into subdirectories in a "sorted" directory within the source directory based on their labels.
By default, the script will ask for confirmation before sending the images to OpenAI for labelling, print the path of every image it finds, and delete the original images after copying them to the sorted directory. These behaviors can be changed by modifying the arguments to the label_and_move_images function call in the if name == "main": block.
This project is licensed under the terms of the MIT license.