|
alias ezc="nvim ~/.zshrc && source ~/.zshrc" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_conda() { |
|
|
|
envs=$(conda env list | awk '{print $1}' | tail -n +4) |
|
|
|
|
|
for env in $envs; do |
|
echo "Activating environment: $env" |
|
source activate $env |
|
echo "Upgrading all packages in environment: $env" |
|
conda upgrade --all -y |
|
conda deactivate |
|
done |
|
|
|
echo "All environments have been upgraded." |
|
} |
|
|
|
export LANG=ja_JP.UTF-8 |
|
export LC_ALL=ja_JP.UTF-8 |
|
|
|
function list_word_freqs() { |
|
local target_dir=$1 |
|
if [[ -z "$target_dir" ]]; then |
|
echo "Usage: list_word_freqs <target_directory>" |
|
return 1 |
|
fi |
|
|
|
|
|
local combined_file=$(mktemp) |
|
cat "$target_dir"/*.txt > "$combined_file" |
|
|
|
|
|
awk ' |
|
BEGIN { |
|
ignore["a"] |
|
ignore["the"] |
|
ignore["and"] |
|
ignore["is"] |
|
ignore["with"] |
|
ignore["of"] |
|
ignore["in"] |
|
ignore["or"] |
|
ignore["on"] |
|
ignore["to"] |
|
ignore["has"] |
|
ignore["he"] |
|
ignore["from"] |
|
} |
|
{ |
|
for (i = 1; i <= NF; i++) { |
|
word = tolower($i) |
|
gsub(/[^a-z]/, "", word) |
|
if (length(word) > 0 && !(word in ignore)) { |
|
freq[word]++ |
|
} |
|
} |
|
} |
|
END { |
|
for (word in freq) { |
|
print freq[word], word |
|
} |
|
} |
|
' "$combined_file" | sort -nr | head -n 40 |
|
|
|
|
|
rm "$combined_file" |
|
} |
|
|
|
sample_prompts() { |
|
local target_directory="$1" |
|
|
|
for file in "$target_directory"/*.txt; do |
|
cat "$file" |
|
echo -e "\n" |
|
done |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
replace_comma_with_keep_tags() { |
|
local occurrence_number=$1 |
|
local target_directory=${2:-.} |
|
|
|
if [[ -z "$occurrence_number" ]]; then |
|
echo "Error: occurrence_number is required." |
|
return 1 |
|
fi |
|
|
|
find "$target_directory" -type f -name "*.txt" | while read -r file; do |
|
awk -v occurrence="$occurrence_number" '{ |
|
count = 0 |
|
for (i = 1; i <= NF; i++) { |
|
if ($i ~ /,/) { |
|
count++ |
|
if (count == occurrence) { |
|
gsub(/,/, " |||", $i) |
|
} |
|
} |
|
} |
|
print |
|
}' "$file" > tmpfile && mv tmpfile "$file" |
|
done |
|
} |
|
|
|
display_custom_help() { |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
printf "%s\n" "$(conda env list)" |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
echo "LLMs" |
|
echo "---" |
|
echo "conda activate openwebui && open-webui serve --port 6969" |
|
echo "ollama serve" |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
echo "Taggers + Captioners" |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
echo "gallery-dl --cookies-from-browser firefox https://x.com/whatever" |
|
echo "JTP2" |
|
echo "---" |
|
echo "~/toolkit/jtp2 <dir>" |
|
echo "Joy Captioner" |
|
echo "---" |
|
echo "~/source/repos/joy/joy <dir> --custom_prompt \"<prompt>\" --caption_type custom" |
|
echo "Waifu Diffusion Tagger:" |
|
echo "---" |
|
echo "python ~/source/repos/wdv3-timm/wdv3_timm.py <dir> --model eva02" |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
echo "Database Stuff" |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
echo "Redis" |
|
echo "---" |
|
echo "~/db/redis-stable/src/redis-server : Start server." |
|
echo "PostgreSQL" |
|
echo "---" |
|
echo "psql -d postgres -h /tmp : Connect using socket directory." |
|
echo "Start server:" |
|
echo "pg_ctl -D \$HOME/db/postgresql/data -l \$HOME/db/pgsql.log start" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "- 🐺 TOOLS -" |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
echo "nv : Returns the cuda version number." |
|
echo "remove_repetition : Removes repetition in txt files in a target directory." |
|
echo "copy_sample_prompts : Copies ./sample-prompt.txt file from the current dir to datasets/furry." |
|
echo "remove_number_prefix : Removes all numbers prefixed by a _ from the end of every file." |
|
echo "count_captions : Counts *.caption and *.txt files in each subdirectory." |
|
echo "count_captions_per_folder : Counts *.caption and *.txt files in each subdirectory individually." |
|
echo "llama : Runs Meta-Llama-3-8B-Instruct on port 6969." |
|
echo "copy_matching_caption_files : Copies matching .caption files for <dir> to the current directory." |
|
echo "c : Change to ComfyUI directory and start the server." |
|
echo "t : Start TensorBoard with logs directory." |
|
echo "png2mp4 : Convert PNG sequence to MP4 video." |
|
echo "seed <file> : Display the seed from a safetensors file." |
|
echo "swch <branch> : Clean repo and switch to specified git branch." |
|
echo "convert_to_jxl <directory> : Convert JPG, JPEG, and PNG files to JXL in the specified directory." |
|
echo "convert_pxl_to_png <directory> : Convert PXL files to PNG in the specified directory." |
|
echo "replace_text_in_files [dir] <src> <replace> : Perform text replacement on *.txt files in a target directory." |
|
echo "update_dir [directory] : Update git repositories in subdirectories." |
|
echo "inject_to_captions [dir] \"txt\" : Add prefix to the beginning of each text file in a directory." |
|
echo "chop_lora <input_file> : Generate multiple versions of a Lora file with different presets." |
|
echo "----------------------------------------------------------------------------------------------------------------------" |
|
} |
|
|
|
export RUST_BACKTRACE=1 |
|
|
|
|
|
|
|
|
|
|
|
function nv() { |
|
|
|
local nvcc_output=$(nvcc --version) |
|
|
|
|
|
local version=$(echo "$nvcc_output" | grep -oP 'release \K[0-9]+\.[0-9]+') |
|
|
|
|
|
local result=$(echo "$version" | tr -d '.') |
|
|
|
|
|
echo $result |
|
} |
|
|
|
export BNB_CUDA_VERSION=126 |
|
|
|
|
|
remove_repetition() { |
|
local dir=$1 |
|
|
|
find "$dir" -type f -name "*.txt" | while read -r file; do |
|
|
|
awk ' |
|
{ |
|
n = split($0, words, " ") # Split the line into words |
|
for (i = n; i > 1; i--) { # Iterate from the last word to the second word |
|
if (words[i] != words[i-1]) break # Stop if the current word is not equal to the previous word |
|
} |
|
for (j = 1; j <= i; j++) { # Print the words up to the point where repetition ends |
|
printf "%s%s", words[j], (j == i ? ORS : OFS) # Print the word followed by a space or newline |
|
} |
|
} |
|
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file" |
|
done |
|
} |
|
|
|
|
|
|
|
alias pie='pip install -e . --use-pep517' |
|
|
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
copy_sample_prompts() { |
|
file="./sample-prompts.txt" |
|
if grep -q 'score_*' "$file"; then |
|
cp -v "$file" ~/datasets/furry/sample_prompts/pony/ |
|
else |
|
cp -v "$file" ~/datasets/furry/sample_prompts/compass/ |
|
fi |
|
|
|
echo "File has been organized." |
|
} |
|
|
|
|
|
remove_number_prefix() { |
|
|
|
for file in **/*_[0-9]*.*; do |
|
|
|
new_file="${file%_[0-9]*.*}.${file##*.}" |
|
|
|
mv "$file" "$new_file" |
|
done |
|
} |
|
|
|
|
|
count_captions() { |
|
caption_count=$(find . -type f -name "*.caption" | wc -l) |
|
txt_count=$(find . -type f -name "*.txt" | wc -l) |
|
echo "*.caption files: $caption_count" |
|
echo "*.txt files: $txt_count" |
|
} |
|
|
|
|
|
count_captions_per_folder() { |
|
for dir in */; do |
|
echo "Directory: $dir" |
|
echo -n "*.caption files: " |
|
find "$dir" -type f -name "*.caption" | wc -l |
|
echo -n "*.txt files: " |
|
find "$dir" -type f -name "*.txt" | wc -l |
|
done |
|
} |
|
|
|
|
|
oui() { |
|
conda activate openwebui |
|
open-webui serve --port 6969 |
|
} |
|
|
|
llama() { |
|
~/models/Meta-Llama-3-8B-Instruct.Q5_K_M.llamafile -cb -np 4 -a llama-3-8b --embedding --port 11434 |
|
} |
|
|
|
|
|
copy_matching_caption_files() { |
|
|
|
TARGET_DIR="$1" |
|
|
|
|
|
for image_file in *.(jpg|jpeg|png|gif|bmp|tiff|webp|jxl); do |
|
|
|
if [[ -f "$image_file" ]]; then |
|
|
|
base_name="${image_file%.*}" |
|
|
|
|
|
caption_file="$TARGET_DIR/$base_name.caption" |
|
|
|
|
|
if [[ -f "$caption_file" ]]; then |
|
|
|
cp "$caption_file" . |
|
echo "Copied $caption_file to the current directory." |
|
else |
|
echo "No matching .caption file for $image_file." |
|
fi |
|
fi |
|
done |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
replace_text_in_files() { |
|
local target_dir=$1 |
|
local search_text=$2 |
|
local replace_text=$3 |
|
|
|
|
|
for file in "$target_dir"/*.txt; do |
|
|
|
sed -i "s/$search_text/$replace_text/g" "$file" |
|
done |
|
|
|
echo "Text replacement complete in $target_dir!" |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inject_to_captions() { |
|
local dir="$1" |
|
local prefix="$2" |
|
if [[ -d "$dir" ]]; then |
|
for file in "$dir"/*.txt; do |
|
if [[ -f "$file" ]]; then |
|
if ! grep -q "$prefix" "$file"; then |
|
|
|
local temp_file=$(mktemp) |
|
echo "${prefix}, $(cat "$file")" > "$temp_file" |
|
mv "$temp_file" "$file" |
|
echo "Added '${prefix}, ' to the front of $file" |
|
else |
|
echo "The tag '${prefix}' already exists in $file" |
|
fi |
|
fi |
|
done |
|
else |
|
echo "Directory $dir does not exist." |
|
fi |
|
} |
|
|
|
|
|
update_dir() { |
|
local target_dir="${1:-.}" |
|
|
|
|
|
if [[ -n "$(find "$target_dir" -mindepth 1 -maxdepth 1 -type d)" ]]; then |
|
for dir in "$target_dir"/*/; do |
|
if [[ -d "$dir" ]]; then |
|
( |
|
cd "$dir" || return |
|
|
|
if [[ -d ".git" ]]; then |
|
echo "Updating $(pwd)" |
|
git pull |
|
fi |
|
) |
|
fi |
|
done |
|
fi |
|
} |
|
|
|
export TOKENIZERS_PARALLELISM=false |
|
|
|
alias grabber="Grabber-cli" |
|
|
|
|
|
|
|
chop_lora() { |
|
local input_file="$1" |
|
local base_name="${input_file:r}" |
|
|
|
|
|
declare -A presets=( |
|
["ringdingding"] = "1,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,0" |
|
["squeaker"] = "1,0,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0" |
|
["heavylifter"] = "1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0" |
|
["style1"] = "1,0,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,0,0" |
|
["style2"] = "1,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1,1,1,0,0,0" |
|
["beeg"] = "1,0,0,0,1,1,0,1,1,0,1,0,1,1,1,0,0,0,0,0,0" |
|
["all"] = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1" |
|
["allin"] = "1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0" |
|
["allmid"] = "1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0" |
|
["allout"] = "1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1" |
|
) |
|
|
|
for preset in ${(k)presets}; do |
|
local output_file="${base_name}-${preset}.safetensors" |
|
local vector_string="${presets[$preset]}" |
|
echo "Generating $output_file" |
|
python ~/source/repos/resize_lora/chop_blocks.py "$input_file" "$vector_string" -o "$output_file" |
|
done |
|
} |
|
|
|
function swch() { |
|
if [ -z "$1" ]; then |
|
echo "Please provide a branch name." |
|
return 1 |
|
fi |
|
branchname=$1 |
|
git clean -fxd && git pull && git checkout $branchname |
|
} |
|
|
|
export COMFYUI_PATH="$HOME/ComfyUI" |
|
export ZSH="$HOME/.oh-my-zsh" |
|
|
|
ZSH_THEME="kade" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins=(git autojump conda-env) |
|
|
|
extract_iframes() { |
|
|
|
input_file="$1" |
|
scene_change_fraction="${2:-0.1}" |
|
|
|
|
|
base_name=$(basename "$input_file" .webm) |
|
|
|
|
|
/usr/bin/ffmpeg -i "$input_file" -f image2 -vf "select=eq(pict_type\,PICT_TYPE_I)*gt(scene\,$scene_change_fraction),showinfo" -fps_mode vfr "${base_name}-%06d.png" |
|
} |
|
|
|
convert_to_jxl() { |
|
local target_directory="$1" |
|
|
|
|
|
if [[ ! -d "$target_directory" ]]; then |
|
echo "The specified directory does not exist: $target_directory" >&2 |
|
return 1 |
|
fi |
|
|
|
|
|
find "$target_directory" \( -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" \) -type f | while read -r file; do |
|
input_path="$file" |
|
output_path="${file%.*}.jxl" |
|
|
|
|
|
if magick convert "$input_path" "$output_path"; then |
|
echo "Converted: $input_path -> $output_path" |
|
else |
|
echo "Failed to convert $input_path" >&2 |
|
fi |
|
done |
|
|
|
echo "Conversion complete." |
|
} |
|
|
|
|
|
convert_pxl_to_png() { |
|
local target_directory="$1" |
|
|
|
|
|
if [[ ! -d "$target_directory" ]]; then |
|
echo "The specified directory does not exist: $target_directory" >&2 |
|
return 1 |
|
fi |
|
|
|
|
|
find "$target_directory" -type f -name "*.pxl" | while read -r file; do |
|
input_path="$file" |
|
output_path="${file%.pxl}.png" |
|
|
|
|
|
if magick convert "$input_path" "$output_path"; then |
|
echo "Converted: $input_path -> $output_path" |
|
else |
|
echo "Failed to convert $input_path" >&2 |
|
fi |
|
done |
|
|
|
echo "Conversion complete." |
|
} |
|
|
|
|
|
seed() { |
|
local filePath="$1" |
|
python3 -c " |
|
import safetensors, json |
|
filePath = '$filePath' |
|
print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found'))) |
|
" |
|
} |
|
|
|
png2mp4() { |
|
ffmpeg -framerate 8 -pattern_type glob -i '*.png' -vf scale=512x512 -crf 28 \ |
|
-c:v libx264 -pix_fmt yuv420p out.mp4 |
|
} |
|
|
|
|
|
source $ZSH/oh-my-zsh.sh |
|
|
|
export PATH=$PATH:$HOME/source/repos/dataset-tools/target/x86_64-unknown-linux-gnu/release:$HOME/.cargo/bin:$HOME/miniconda3/bin:$HOME/toolkit:$HOME/db/redis-stable/src:$HOME/db/postgresql/bin:$HOME/.local/bin:/opt/cuda/bin |
|
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib:/opt/cuda/targets/x86_64-linux/lib |
|
export COMFYUI_MODEL_PATH=/home/kade/ComfyUI/models |
|
|
|
c_old() { |
|
cd ~/ComfyUI && |
|
python3.12 main.py --listen 0.0.0.0 --preview-method taesd --use-pytorch-cross-attention --disable-xformers --fast |
|
} |
|
|
|
c() { |
|
cd ~/ComfyUI && |
|
conda activate comfyui |
|
python main.py --listen 0.0.0.0 --preview-method taesd --use-pytorch-cross-attention --disable-xformers --front-end-version Comfy-Org/ComfyUI_frontend@latest --fast |
|
} |
|
|
|
alias cp='cp --reflinks=auto' |
|
alias t="tensorboard --logdir=$HOME/output_dir/logs" |
|
alias rt="vim ~/.tmux.conf && echo \"Reloading tmux config\" && tmux source ~/.tmux.conf" |
|
alias zr="vim ~/.zshrc && echo \"Reloading zsh config\" && source ~/.zshrc" |
|
alias ta="tmux att" |
|
alias ga="git add . && git commit -avs && git push" |
|
alias gs="git status" |
|
alias wd="git diff --word-diff-regex='[^,]+' --patience" |
|
alias vim="nvim" |
|
alias vi="nvim" |
|
alias v="nvim" |
|
alias grh='git reset --hard' |
|
alias gcs='git clone --recurse-submodules' |
|
|
|
source /home/kade/.config/broot/launcher/bash/br |
|
|
|
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh |
|
|
|
alias ls='ls --color=always' |
|
|
|
|
|
|
|
__conda_setup="$('/home/kade/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" |
|
if [ $? -eq 0 ]; then |
|
eval "$__conda_setup" |
|
else |
|
if [ -f "/home/kade/miniconda3/etc/profile.d/conda.sh" ]; then |
|
. "/home/kade/miniconda3/etc/profile.d/conda.sh" |
|
else |
|
export PATH="/home/kade/miniconda3/bin:$PATH" |
|
fi |
|
fi |
|
unset __conda_setup |
|
|
|
|
|
unset CONDA_CHANGEPS1 |
|
|
|
function conda_prompt_info() { |
|
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then |
|
echo "(${CONDA_DEFAULT_ENV})" |
|
fi |
|
} |
|
|
|
display_custom_help |
|
|