Tensor.Art
Create
user_661323374995269704

user_661323374995269704

8
Followers
1
Following
188
Runs
0
Downloads
147
Likes
Latest
Most Liked
Script to copy TensorArt downloaded .png into parsed modelname subfolders TAMS 2.0 (linux)

Script to copy TensorArt downloaded .png into parsed modelname subfolders TAMS 2.0 (linux)

IntroductionI wrote this gnu/linux bash script to parse downloaded files from TAMS 2.0, get the model name from the exif, and copy the file into a model name sub-folder. Why? Why not.PreReqexiftool from: https://exiftool.org/ I extracted it to my home folder.jq from: sudo apt-get install jqperl from: it was already installed for melinux? (I don't know how to do this in macOS/Windows, sorry)ScriptPaste this code into: something.shRead each line because it's unsafe to run random scriptsChange the two directory paths at the topChange the path to exiftool if needed (the ~/ExifTool/exiftool)Make it executable: chmod +x something.shThen just run it like: ./something.sh.. if it looks okay delete the downloaded files. Can change copy to move if feeling brave#!/bin/bash # Directory containing the .png files src_dir="/home/contoso/Downloads" # Directory to copy files to dest_base_dir="/home/contoso/Downloads/test" # Loop through all .png files in the source directory for file in "$src_dir"/*.png; do # Extract the modelFileName from the EXIF data modelFileName=$(perl ~/ExifTool/exiftool -if '($Prompt =~/ckpt_name/i)' -Generation_data "$file" -s3 -q | jq -r '.baseModel.modelFileName') # Sanitize the model name to prevent code injection sanitized_modelname=$(echo "$modelFileName" | sed 's/[^a-zA-Z0-9_-]//g') echo "$sanitized_modelname" # Check if sanitized_modelname is not empty if [ -n "$sanitized_modelname" ]; then # Create the destination directory if it doesn't exist dest_dir="$dest_base_dir/$sanitized_modelname" mkdir -p "$dest_dir" # Copy the file to the destination directory cp "$file" "$dest_dir/" fi done NotesExifTool created by Phil Harvey. Very impressive. Active community and forum at the creator's website.Maybe this is an "exiftool common scripting error #3" but I can't find an easy way to get the model name from the JSON using only exiftool. If the exif had one separate line for model name then exiftool could read it as a simple tag and copy the files based on that.I only use this website to make AI pics. Maybe something else does this automatically but I am not installing local AI gen software and this works for me. Maybe it will inspire someone and solve a problem.Please understand this post isn't an offer for support. This took me a week to figure out. I don't know what I am doing.I am not responsible if this disappears your files or someone somehow injects code to rm -rf your data by naming a model with code injection. I asked bing to write code to sanitize the input variable.Okay bye.
Fix EXIF data from EMS-#####-EMS using ExifTool (nevermind this is for TAMS 1.0)

Fix EXIF data from EMS-#####-EMS using ExifTool (nevermind this is for TAMS 1.0)

Never mind this is for TAMS 1.0. The 2.0 has the model in the EXIF so try this:https://tensor.art/articles/770139760170868195IntroductionYou download your images from this website but the EXIF data for the model / lora looks like:Model: EMS-342970-EMS, or <lora:EMS-45352-EMS:0.500000>.The ExifTool utility can fix this. I am using linux but it should also work for mac/Windows if you follow https://exiftool.org/install.htmlPreReq- Download ExifTool from https://exiftool.org/ and extract the archive into your home drive.- Make a new dot-file called .ExifTool_config in the same folder as exiftool.- linux example: ~/Image-ExifTool-12.86/.ExifTool_config- windows might need cmd like: echo.>.ExifTool_config.ExifTool_config fileEdit the config file. Copy/paste the basic example.- This is perl language, search and replace, and not optimized, but it works. Switch is probably more efficient.- The \+ is an escape for the + in the model name.- The /g at the end searches for all instances.- 'Parameters' is the block it changes in the EXIF.- Add all your desired entries and save the file.You only need to make new entries like:$val =~ s/EMS-151022-EMS/RealCartoon Realistic v11/g; %Image::ExifTool::UserDefined = ( 'Image::ExifTool::Composite' => { MyParameters=> { Require => 'Parameters', ValueConv => q{ # MODEL $val =~ s/EMS-151022-EMS/RealCartoon Realistic v11/g; $val =~ s/EMS-219023-EMS/ShampooMix_v4-fp16-no-ema/g; $val =~ s/EMS-230098-EMS/RealCartoon Realistic v12/g; $val =~ s/EMS-379840-EMS/Lazymix\+ - v4/g; # LoRa $val =~ s/EMS-72516-EMS/Realistic Fusion X - V1/g; $val =~ s/EMS-343944-EMS/A simple nun suit - v1/g; return $val; }, }, }, ); 1; # end Modify the EXIFI use linux, extracted to a folder inside my home folder, and my files are in my Downloads folder, so the command I run is this, where "~/Downloads" has my raw files:perl ~/Image-ExifTool-12.86/exiftool "-Parameters<MyParameters" ~/DownloadsIt will make new files and append "original" to the old, however you can add -overwrite_original to delete the old files once absolutely sure your config file works. This does not forgive. I am not responsible for lost EXIF.Copy into folders based on ModelThis will parse your EXIF for the Model: and grab until the first comma, copy the file into a subfolder of the destination named as the Model. Ideally you already modified the EXIF to fix the model name. In this example the files are in my home Downloads folder on linux.- ~/Downloads/ is the source folder with the files- /path/to/destination/ is the destination parent folder. You need to change this- -r is recursive, if you choose, make it -r -o .- The "-o ." is the copy argument. Remove for move, at your own risk.- If you only run this without first doing the above section you'll get a bunch of EMS-###-EMS folders. The next section will combine everything together into one command.perl ~/Image-ExifTool-12.86/exiftool -if '($Parameters=~/Model/i)' -o . '-Directory</path/to/destination/${Parameters;m/\bModel:\s+(\w+[^,]*)/;$_=$1;}' ~/Downloads/Combine into one commandThis combines the above into one command. This example does a move not a copy. I also renamed my exiftool folder.- ~/Downloads There are two. Rename those to the folder with your EMS-###-EMS pictures- /path/to/destination/ Where you want to move the files after renaming the EMS-###-EMS to Model nameperl ~/ExifTool/exiftool -if '($Parameters=~/Model/i)' "-Parameters<MyParameters" ~/Downloads -overwrite_original -execute '-Directory</path/to/destination/${Parameters;m/\bModel:\s+(\w+[^,]*)/;$_=$1;}' ~/DownloadsNotesYou can rename the Image-ExifTool-12.86 directory or have it wherever.On Windows you might need to change the ' to " when referencing directories.This runs perl code so maybe rename exiftool to something else for safety.ExifTool created by Phil Harvey. Very impressive. Active community and forum at the creator's website.It can do advanced operations and scripting. Above my pay grade.Please understand this post isn't an offer for support. This took me all day to figure out. I don't know what I am doing.
4