Skip to content

AetherCoded/OpenAI-Card-Sorter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI TCG Sorter

OpenAI TCG Sorter is a script designed to organize images of trading cards by utilizing the OpenAI GPT-4o API for card identification. The script reads card images from a specified directory, processes them using the OpenAI API, and sorts them into categorized directories based on the card name, set name, and TCG name.

Features

  • API Integration: Uses OpenAI GPT-4o API for card identification.
  • Image Encoding: Converts images to base64 format for API processing.
  • Logging: Detailed logging of the processing steps and errors.
  • File Organization: Moves and renames files based on card details.
  • Alias Resolution: Handles multiple aliases for TCG names.
  • Unicode Normalization: Sanitizes filenames to remove special characters.

Setup

Requirements

  • Python 3.6+
  • An OpenAI API key with paid compute time available.

Dependencies

Install the required packages using pip:

pip install requests unidecode

Configuration

Create a tcg.cfg file in the same directory as the script with the following content:

api_key=YOUR_API_KEY_HERE
aliases=alias1:alias1_main,alias2:alias2_main
logging_level=WARNING
  • api_key: Your OpenAI API key.
  • aliases: A semicolon-separated list of alias pairs in the format alias1:alias1_main,alias2:alias2_main.
  • logging_level: Logging level (e.g., DEBUG, INFO, WARNING, ERROR).

Running the Script

Run the script from the command line:

python script.py

Usage

  1. Place your card images in the Import directory.
  2. Run the script using the command above.
  3. The script will process each image, identify the card details, and move the image to the Sorted directory under a categorized subdirectory.

Example

For an image named example_card.jpg with card name "Pikachu", set name "Base Set", and TCG name "Pokemon":

  • The image will be moved to Sorted/Pokemon/ and renamed to Pikachu - Base Set.jpg.

Logging

The script logs all actions and errors to log.txt. Check this file for detailed information on the script's operations and any issues encountered.

Troubleshooting

  • Missing API Key: Ensure your tcg.cfg file contains a valid API key.
  • Invalid Aliases: Ensure alias pairs are correctly formatted in the tcg.cfg file.
  • File Permissions: Ensure the script has the necessary permissions to read and write files in the specified directories.

For further assistance, refer to the OpenAI documentation or the error logs generated by the script.

About

OpenAI Card Sorter is a TCG OCR solution leveraging the OpenAI API to automatically rename and sort trading card images

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages