Skip to content
JonesDevlinPublic

About

Classify images as modern or fantasy with the TypeSafe Jev API.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

JevPOC

Classify images in a folder as modern or fantasy with the TypeSafe Jev API, and move each file into a subfolder. Low-confidence and out-of-category pictures go to review instead of being forced into a label.

Jev answers two questions about each picture. The script decides the folder:

  • review, when the picture is not clearly a modern or fantasy scene (the yes/no probability is not above 0.7)
  • review, when the modern-versus-fantasy choice is below the confidence threshold
  • modern or fantasy otherwise

The original file is what gets moved. A resized JPEG is sent to Jev only. A failed API call leaves the file where it is.

Image support in Jev is an opt-in preview. The script sends the TypeSafe-Danger-Zone-Images: true header.

Setup

Python 3.11 or newer. Dependencies live in this project's virtualenv, because the python3.12 on this machine is managed by uv and will not take a global pip install.

cd ~/Projects/JevPOC
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python "typesafe-sdk[pil]"
export TYPESAFE_API_KEY=...   # from https://console.typesafe.ai/

The key is read from TYPESAFE_API_KEY. It is not stored in this directory.

Usage

Run the virtualenv's Python, not python3.12 on its own. That interpreter does not have Pillow or the SDK.

~/Projects/JevPOC/.venv/bin/python ~/Projects/JevPOC/classify_images.py ~/Pictures/inbox --dry-run
~/Projects/JevPOC/.venv/bin/python ~/Projects/JevPOC/classify_images.py ~/Pictures/inbox
~/Projects/JevPOC/.venv/bin/python ~/Projects/JevPOC/classify_images.py ~/Pictures/inbox --threshold 0.6

--dry-run still calls Jev. It prints the decision and does not move files.

Flag Default Meaning
folder required Folder whose images are classified. ~ is expanded.
--threshold 0.5 Minimum Choice confidence required to file an image. Must be from 0 to 1.
--model jev-1.14.0 TypeSafe model id. Pinned so the threshold stays tied to one release.
--dry-run off Print decisions without moving files.

For these two options, a confidence of 0.5 means the chosen label has about a 0.75 probability.

Only files sitting directly in folder are considered. Hidden files are skipped. Recognized suffixes are .jpg, .jpeg, .png, .webp, .gif, .bmp, .tif, and .tiff. OneDrive files that are online-only are fetched before they are read. That needs the OneDrive app to be running. If it is not, the script says so instead of waiting on [Errno 60] Operation timed out. Animated files contribute their first frame. If a destination already has that filename, the moved file gets a -1, -2, … suffix.

Exit status is 0 when every file was classified, 1 when one or more files failed, and 2 for a bad folder, a bad threshold, a missing key, or an authentication failure.

Paths

The input folder is the only path you pass. Destinations are always subfolders of that folder, and their names are fixed:

inbox/
  photo.jpg          # classified on this run
  modern/            # filed when the choice is modern and confident
  fantasy/
  review/            # low confidence, or not clearly either scene

There is no flag to send results somewhere else, or to rename modern, fantasy, or review. Those names are also the Choice options Jev returns, so the folder and the label stay the same word. A second run does not look inside the destination folders, so files already sorted stay put.

What is sent

Each picture is rotated upright from its EXIF orientation, then fitted to Jev's limits before upload. Jev rejects images outside these limits and does not resize them:

  • each side from 280 to 1568 pixels
  • PNG or JPEG, still images, at most 16 MiB

The long side is scaled down to 1568. A picture that is still shorter than 280 pixels on one side is scaled up when that fits, or padded with white when the other side would exceed 1568. The upload is a baseline JPEG. The file on disk is unchanged until a confident decision moves it.

About

Classify images as modern or fantasy with the TypeSafe Jev API.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages