Merge branch 'main' of hf.co:/k4d3/toolkit
Browse files- .zshrc +77 -13
- audiogen_medium.py → audiogen_medium +2 -0
- concat_captions +64 -0
- extract_description +107 -0
- ocr +33 -0
- pick_caption +27 -0
- steal_sdscripts_metadata +0 -0
- tensorboard_that_errors_on_conda +8 -0
- zsh/gallery-dl.zsh +10 -0
- zsh/install_members.zsh +27 -0
.zshrc
CHANGED
@@ -42,6 +42,8 @@ ZSH_THEME="kade"
|
|
42 |
# COMPLETION_WAITING_DOTS="true"
|
43 |
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
44 |
|
|
|
|
|
45 |
# Set the system language and locale to Japanese UTF-8
|
46 |
export LANG=ja_JP.UTF-8
|
47 |
export LC_ALL=ja_JP.UTF-8
|
@@ -126,6 +128,12 @@ source $ZSH/oh-my-zsh.sh
|
|
126 |
# - CUDA binary directory
|
127 |
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
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
# Extend the LD_LIBRARY_PATH to include:
|
130 |
# - Conda environment's library directory
|
131 |
# - CUDA library directory for x86_64 Linux
|
@@ -255,17 +263,17 @@ function re() {
|
|
255 |
# It searches for all .txt files in the specified directory and its subdirectories.
|
256 |
# If a file contains the specified tag, the function removes the tag from its original position
|
257 |
# and prepends it to the beginning of the file.
|
258 |
-
# Usage:
|
259 |
-
|
260 |
local tag="$1"
|
261 |
local dir="$2"
|
262 |
|
263 |
if [[ -z "$tag" || -z "$dir" ]]; then
|
264 |
-
echo "Usage:
|
265 |
return 1
|
266 |
fi
|
267 |
|
268 |
-
find "$dir" -type f -name "*.
|
269 |
if grep -q "$tag" "$file"; then
|
270 |
sed -i "s/$tag//g" "$file"
|
271 |
sed -i "1s/^/$tag, /" "$file"
|
@@ -379,14 +387,14 @@ list_word_freqs() {
|
|
379 |
|
380 |
# Function: sample_prompts
|
381 |
# Description:
|
382 |
-
# This function takes a sample of the
|
383 |
# It reads and displays the contents of all .txt files in the specified directory,
|
384 |
-
# providing a quick overview of the tags
|
385 |
#
|
386 |
# Usage: sample_prompts <target_directory>
|
387 |
#
|
388 |
# Parameters:
|
389 |
-
# - target_directory: The directory containing the .txt files with tags
|
390 |
#
|
391 |
# Output:
|
392 |
# Prints the contents of each .txt file in the target directory, separated by newlines.
|
@@ -400,16 +408,16 @@ sample_prompts() {
|
|
400 |
}
|
401 |
|
402 |
# replace_comma_with_keep_tags
|
403 |
-
# Description: This function replaces the specified occurrence of a comma with " |||" in all *.
|
404 |
# in all subdirectories of a target directory or the current directory when no path is passed.
|
405 |
# Usage: replace_comma_with_keep_tags <occurrence_number> [target_directory]
|
406 |
# Parameters:
|
407 |
# - occurrence_number: The occurrence number of the comma to be replaced (e.g., 1 for the first occurrence).
|
408 |
-
# - target_directory (optional): The target directory to search for *.
|
409 |
# Example:
|
410 |
# replace_comma_with_keep_tags 2 /path/to/directory
|
411 |
# replace_comma_with_keep_tags 1
|
412 |
-
|
413 |
local occurrence_number=$1
|
414 |
local target_directory=${2:-.}
|
415 |
|
@@ -434,6 +442,32 @@ replace_comma_with_keep_tags() {
|
|
434 |
done
|
435 |
}
|
436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
# Function: display_custom_help
|
438 |
# Description:
|
439 |
# This function displays a custom help menu with various commands, environment information,
|
@@ -664,14 +698,15 @@ replace_text_in_files() {
|
|
664 |
|
665 |
# This script adds a specified prefix to the beginning of each text file in a given directory.
|
666 |
# If the prefix already exists in the text file, it moves the prefix to the front of the text file without leaving extra commas or spaces.
|
667 |
-
# Usage:
|
668 |
# Arguments:
|
669 |
# <directory> - The directory containing the text files to be modified.
|
670 |
# <prefix> - The prefix to be added to the beginning of each text file.
|
671 |
# The script checks if the specified directory exists and iterates over each text file in the directory.
|
672 |
# For each text file, it creates a temporary file with the modified content and then replaces the original file with the temporary file.
|
673 |
# If the directory does not exist, it prints an error message.
|
674 |
-
|
|
|
675 |
local dir="$1"
|
676 |
local prefix="$2"
|
677 |
if [[ -d "$dir" ]]; then
|
@@ -697,6 +732,32 @@ inject_to_captions() {
|
|
697 |
fi
|
698 |
}
|
699 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
# Function to update git repositories in subdirectories
|
701 |
update_dir() {
|
702 |
local target_dir="${1:-.}"
|
@@ -918,6 +979,8 @@ filePath = '$filePath'
|
|
918 |
print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found')))"
|
919 |
}
|
920 |
|
|
|
|
|
921 |
source ~/toolkit/zsh/png2mp4.zsh
|
922 |
|
923 |
# Function: c
|
@@ -952,7 +1015,8 @@ source ~/toolkit/zsh/png2mp4.zsh
|
|
952 |
c() {
|
953 |
cd ~/ComfyUI &&
|
954 |
conda activate comfyui
|
955 |
-
python main.py --listen 0.0.0.0 --preview-method taesd --use-pytorch-cross-attention --disable-xformers --
|
|
|
956 |
}
|
957 |
#
|
958 |
# Usage:
|
|
|
42 |
# COMPLETION_WAITING_DOTS="true"
|
43 |
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
44 |
|
45 |
+
export GIN_MODE=release
|
46 |
+
|
47 |
# Set the system language and locale to Japanese UTF-8
|
48 |
export LANG=ja_JP.UTF-8
|
49 |
export LC_ALL=ja_JP.UTF-8
|
|
|
128 |
# - CUDA binary directory
|
129 |
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
|
130 |
|
131 |
+
# Function to remove $HOME/miniconda3/bin, $HOME/miniconda3/condabin from PATH and $HOME/miniconda3/lib from LD_LIBRARY_PATH
|
132 |
+
rconda() {
|
133 |
+
export PATH=$(echo $PATH | tr ':' '\n' | grep -v "$HOME/miniconda3/bin" | grep -v "$HOME/miniconda3/condabin" | tr '\n' ':' | sed 's/:$//')
|
134 |
+
export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v "$HOME/miniconda3/lib" | tr '\n' ':' | sed 's/:$//')
|
135 |
+
}
|
136 |
+
|
137 |
# Extend the LD_LIBRARY_PATH to include:
|
138 |
# - Conda environment's library directory
|
139 |
# - CUDA library directory for x86_64 Linux
|
|
|
263 |
# It searches for all .txt files in the specified directory and its subdirectories.
|
264 |
# If a file contains the specified tag, the function removes the tag from its original position
|
265 |
# and prepends it to the beginning of the file.
|
266 |
+
# Usage: rejiggle_tags <tag> <directory>
|
267 |
+
rejiggle_tags() {
|
268 |
local tag="$1"
|
269 |
local dir="$2"
|
270 |
|
271 |
if [[ -z "$tag" || -z "$dir" ]]; then
|
272 |
+
echo "Usage: rejiggle_tags <tag> <directory>"
|
273 |
return 1
|
274 |
fi
|
275 |
|
276 |
+
find "$dir" -type f -name "*.tags" | while read -r file; do
|
277 |
if grep -q "$tag" "$file"; then
|
278 |
sed -i "s/$tag//g" "$file"
|
279 |
sed -i "1s/^/$tag, /" "$file"
|
|
|
387 |
|
388 |
# Function: sample_prompts
|
389 |
# Description:
|
390 |
+
# This function takes a sample of the tag in a target training directory.
|
391 |
# It reads and displays the contents of all .txt files in the specified directory,
|
392 |
+
# providing a quick overview of the tags used for training.
|
393 |
#
|
394 |
# Usage: sample_prompts <target_directory>
|
395 |
#
|
396 |
# Parameters:
|
397 |
+
# - target_directory: The directory containing the .txt files with tags.
|
398 |
#
|
399 |
# Output:
|
400 |
# Prints the contents of each .txt file in the target directory, separated by newlines.
|
|
|
408 |
}
|
409 |
|
410 |
# replace_comma_with_keep_tags
|
411 |
+
# Description: This function replaces the specified occurrence of a comma with " |||" in all *.tags files
|
412 |
# in all subdirectories of a target directory or the current directory when no path is passed.
|
413 |
# Usage: replace_comma_with_keep_tags <occurrence_number> [target_directory]
|
414 |
# Parameters:
|
415 |
# - occurrence_number: The occurrence number of the comma to be replaced (e.g., 1 for the first occurrence).
|
416 |
+
# - target_directory (optional): The target directory to search for *.tags files. If not provided, the current directory is used.
|
417 |
# Example:
|
418 |
# replace_comma_with_keep_tags 2 /path/to/directory
|
419 |
# replace_comma_with_keep_tags 1
|
420 |
+
replace_comma_with_keep_tags_txt() {
|
421 |
local occurrence_number=$1
|
422 |
local target_directory=${2:-.}
|
423 |
|
|
|
442 |
done
|
443 |
}
|
444 |
|
445 |
+
|
446 |
+
replace_comma_with_keep_tags() {
|
447 |
+
local occurrence_number=$1
|
448 |
+
local target_directory=${2:-.}
|
449 |
+
|
450 |
+
if [[ -z "$occurrence_number" ]]; then
|
451 |
+
echo "Error: occurrence_number is required."
|
452 |
+
return 1
|
453 |
+
fi
|
454 |
+
|
455 |
+
find "$target_directory" -type f -name "*.tags" | while read -r file; do
|
456 |
+
awk -v occurrence="$occurrence_number" '{
|
457 |
+
count = 0
|
458 |
+
for (i = 1; i <= NF; i++) {
|
459 |
+
if ($i ~ /,/) {
|
460 |
+
count++
|
461 |
+
if (count == occurrence) {
|
462 |
+
gsub(/,/, " |||", $i)
|
463 |
+
}
|
464 |
+
}
|
465 |
+
}
|
466 |
+
print
|
467 |
+
}' "$file" > tmpfile && mv tmpfile "$file"
|
468 |
+
done
|
469 |
+
}
|
470 |
+
|
471 |
# Function: display_custom_help
|
472 |
# Description:
|
473 |
# This function displays a custom help menu with various commands, environment information,
|
|
|
698 |
|
699 |
# This script adds a specified prefix to the beginning of each text file in a given directory.
|
700 |
# If the prefix already exists in the text file, it moves the prefix to the front of the text file without leaving extra commas or spaces.
|
701 |
+
# Usage: inject_to_tags <directory> <prefix>
|
702 |
# Arguments:
|
703 |
# <directory> - The directory containing the text files to be modified.
|
704 |
# <prefix> - The prefix to be added to the beginning of each text file.
|
705 |
# The script checks if the specified directory exists and iterates over each text file in the directory.
|
706 |
# For each text file, it creates a temporary file with the modified content and then replaces the original file with the temporary file.
|
707 |
# If the directory does not exist, it prints an error message.
|
708 |
+
|
709 |
+
inject_to_txt() {
|
710 |
local dir="$1"
|
711 |
local prefix="$2"
|
712 |
if [[ -d "$dir" ]]; then
|
|
|
732 |
fi
|
733 |
}
|
734 |
|
735 |
+
inject_to_tags() {
|
736 |
+
local dir="$1"
|
737 |
+
local prefix="$2"
|
738 |
+
if [[ -d "$dir" ]]; then
|
739 |
+
for file in "$dir"/*.tags; do
|
740 |
+
if [[ -f "$file" ]]; then
|
741 |
+
if grep -q "$prefix" "$file"; then
|
742 |
+
# Move the existing prefix to the front of the text file without leaving extra commas or spaces
|
743 |
+
local temp_file=$(mktemp)
|
744 |
+
sed "s/$prefix//" "$file" | sed "1s/^/${prefix}, /" | sed 's/^, //' | sed 's/,,/,/g' | sed 's/, ,/,/g' | sed 's/ ,/,/g' > "$temp_file"
|
745 |
+
mv "$temp_file" "$file"
|
746 |
+
echo "Moved '${prefix}' to the front of $file"
|
747 |
+
else
|
748 |
+
# Use a temporary file to store the modified content
|
749 |
+
local temp_file=$(mktemp)
|
750 |
+
echo "${prefix}, $(cat "$file")" | sed 's/,,/,/g' | sed 's/, ,/,/g' | sed 's/ ,/,/g' > "$temp_file"
|
751 |
+
mv "$temp_file" "$file"
|
752 |
+
echo "Added '${prefix}, ' to the front of $file"
|
753 |
+
fi
|
754 |
+
fi
|
755 |
+
done
|
756 |
+
else
|
757 |
+
echo "Directory $dir does not exist."
|
758 |
+
fi
|
759 |
+
}
|
760 |
+
|
761 |
# Function to update git repositories in subdirectories
|
762 |
update_dir() {
|
763 |
local target_dir="${1:-.}"
|
|
|
979 |
print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found')))"
|
980 |
}
|
981 |
|
982 |
+
source ~/toolkit/zsh/install_members.zsh
|
983 |
+
source ~/toolkit/zsh/gallery-dl.zsh
|
984 |
source ~/toolkit/zsh/png2mp4.zsh
|
985 |
|
986 |
# Function: c
|
|
|
1015 |
c() {
|
1016 |
cd ~/ComfyUI &&
|
1017 |
conda activate comfyui
|
1018 |
+
python main.py --listen 0.0.0.0 --preview-method taesd --use-pytorch-cross-attention --disable-xformers --fast
|
1019 |
+
# --front-end-version /home/kade/source/repos/ComfyUI_frontend/dist
|
1020 |
}
|
1021 |
#
|
1022 |
# Usage:
|
audiogen_medium.py → audiogen_medium
RENAMED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import sys
|
2 |
import torchaudio
|
3 |
from audiocraft.models import AudioGen
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
import sys
|
4 |
import torchaudio
|
5 |
from audiocraft.models import AudioGen
|
concat_captions
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
|
3 |
+
"""
|
4 |
+
This script walks through a directory, identifies image files, and checks for the existence of corresponding
|
5 |
+
.caption and .tags files. It then concatenates the contents of .caption and .tags files into the .txt files.
|
6 |
+
|
7 |
+
Usage:
|
8 |
+
- Place the script in the directory containing the image files.
|
9 |
+
- Run the script to concatenate .caption and .tags files into .txt files.
|
10 |
+
- Use the dry_run flag to preview the changes without writing to the .txt files.
|
11 |
+
|
12 |
+
Functions:
|
13 |
+
get_files(path): Walks through the directory and yields image files along with their .caption and .tags files.
|
14 |
+
concat(caption_path, tags_path, txt_path, dry_run=False): Concatenates the contents of .caption and .tags files into the .txt file.
|
15 |
+
"""
|
16 |
+
|
17 |
+
from pathlib import Path
|
18 |
+
import os
|
19 |
+
|
20 |
+
FILE_EXTS = {".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif", ".jxl"}
|
21 |
+
|
22 |
+
|
23 |
+
def get_files(path):
|
24 |
+
path = Path(path)
|
25 |
+
# Walk the directory, looking for image files
|
26 |
+
for root, dirs, files in os.walk(path):
|
27 |
+
root = path / root
|
28 |
+
for file in files:
|
29 |
+
file = root / file
|
30 |
+
if file.suffix not in FILE_EXTS:
|
31 |
+
continue
|
32 |
+
caption = file.with_suffix(".caption")
|
33 |
+
tags = file.with_suffix(".tags")
|
34 |
+
txt = file.with_suffix(".txt")
|
35 |
+
if not caption.exists():
|
36 |
+
print(f"{caption} does not exist")
|
37 |
+
if not tags.exists():
|
38 |
+
print(f"{tags} does not exist")
|
39 |
+
yield file, caption, tags, txt
|
40 |
+
|
41 |
+
|
42 |
+
def concat(caption_path, tags_path, txt_path, dry_run=False):
|
43 |
+
with open(caption_path, "r") as f:
|
44 |
+
caption = f.read().strip()
|
45 |
+
|
46 |
+
with open(tags_path, "r") as f:
|
47 |
+
tags = f.read().strip(", \n")
|
48 |
+
|
49 |
+
txt = f"{tags}, {caption}"
|
50 |
+
|
51 |
+
if dry_run:
|
52 |
+
print(f"{txt_path}:")
|
53 |
+
print(txt)
|
54 |
+
print()
|
55 |
+
else:
|
56 |
+
with open(txt_path, 'w') as f:
|
57 |
+
f.write(txt)
|
58 |
+
print(f"wrote {txt_path}")
|
59 |
+
|
60 |
+
if __name__ == "__main__":
|
61 |
+
dry_run = False
|
62 |
+
for f in get_files("."):
|
63 |
+
concat(*f[1:], dry_run=dry_run)
|
64 |
+
|
extract_description
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
"""
|
4 |
+
JSON Caption Extractor
|
5 |
+
|
6 |
+
This script processes JSON files in the specified directory (or current directory if not specified)
|
7 |
+
and its subdirectories, extracting cleaned captions from them. It performs the following tasks:
|
8 |
+
|
9 |
+
1. Recursively searches for JSON files in the specified directory and its subdirectories.
|
10 |
+
2. Reads each JSON file found.
|
11 |
+
3. Extracts the 'description' field from each JSON file.
|
12 |
+
4. Cleans the description by removing HTML links, newline characters, and extra spaces.
|
13 |
+
5. Writes the cleaned description to a new file with the same name as the input file
|
14 |
+
but with a '.caption' extension in the same directory as the input file.
|
15 |
+
6. Provides logging information about the processing status and any errors encountered.
|
16 |
+
|
17 |
+
Usage:
|
18 |
+
python extract_description [-v] [-d DIRECTORY]
|
19 |
+
|
20 |
+
Arguments:
|
21 |
+
-d, --directory The directory to process (optional, defaults to current directory)
|
22 |
+
-v, --verbose Enable verbose logging (optional)
|
23 |
+
|
24 |
+
The script processes all JSON files in the specified directory and its subdirectories.
|
25 |
+
"""
|
26 |
+
|
27 |
+
import json
|
28 |
+
import os
|
29 |
+
import re
|
30 |
+
import argparse
|
31 |
+
import logging
|
32 |
+
from typing import Dict, Any
|
33 |
+
|
34 |
+
def clean_description(description: str) -> str:
|
35 |
+
"""
|
36 |
+
Clean the input description by removing HTML links, newline characters, and extra spaces.
|
37 |
+
|
38 |
+
Args:
|
39 |
+
description (str): The original description string.
|
40 |
+
|
41 |
+
Returns:
|
42 |
+
str: The cleaned description string.
|
43 |
+
"""
|
44 |
+
# Remove HTML links
|
45 |
+
description = re.sub(r'<a href=".*?".*?>(.*?)</a>', r'\1', description)
|
46 |
+
# Remove newline characters
|
47 |
+
description = description.replace('\n', ' ')
|
48 |
+
# Remove extra spaces
|
49 |
+
description = re.sub(r'\s+', ' ', description).strip()
|
50 |
+
return description
|
51 |
+
|
52 |
+
def process_json_file(file_path: str) -> None:
|
53 |
+
"""
|
54 |
+
Process a single JSON file by extracting the description, cleaning it,
|
55 |
+
and writing it to a new caption file.
|
56 |
+
|
57 |
+
Args:
|
58 |
+
file_path (str): The path to the JSON file to process.
|
59 |
+
|
60 |
+
Raises:
|
61 |
+
Exception: If there's an error reading the JSON file or writing the output file.
|
62 |
+
"""
|
63 |
+
try:
|
64 |
+
with open(file_path, 'r') as json_file:
|
65 |
+
data: Dict[str, Any] = json.load(json_file)
|
66 |
+
|
67 |
+
description = data.get('description', '')
|
68 |
+
cleaned_description = clean_description(description)
|
69 |
+
|
70 |
+
output_file = os.path.splitext(file_path)[0] + '.caption'
|
71 |
+
|
72 |
+
with open(output_file, 'w') as caption_file:
|
73 |
+
caption_file.write(cleaned_description)
|
74 |
+
|
75 |
+
logging.info(f"Processed {file_path} -> {output_file}")
|
76 |
+
except Exception as e:
|
77 |
+
logging.error(f"Error processing {file_path}: {str(e)}")
|
78 |
+
|
79 |
+
def process_directory(directory: str) -> None:
|
80 |
+
"""
|
81 |
+
Recursively process all JSON files in the specified directory and its subdirectories.
|
82 |
+
|
83 |
+
Args:
|
84 |
+
directory (str): The path to the directory to process.
|
85 |
+
"""
|
86 |
+
for root, _, files in os.walk(directory):
|
87 |
+
for file in files:
|
88 |
+
if file.lower().endswith('.json'):
|
89 |
+
file_path = os.path.join(root, file)
|
90 |
+
process_json_file(file_path)
|
91 |
+
|
92 |
+
def main():
|
93 |
+
parser = argparse.ArgumentParser(description="Process JSON files and extract captions.")
|
94 |
+
parser.add_argument('-d', '--directory', default='.', help="Directory to process (default: current directory)")
|
95 |
+
parser.add_argument('-v', '--verbose', action='store_true', help="Enable verbose logging")
|
96 |
+
args = parser.parse_args()
|
97 |
+
|
98 |
+
log_level = logging.DEBUG if args.verbose else logging.INFO
|
99 |
+
logging.basicConfig(level=log_level, format='%(asctime)s - %(levelname)s - %(message)s')
|
100 |
+
|
101 |
+
directory = os.path.abspath(args.directory)
|
102 |
+
logging.info(f"Processing directory: {directory}")
|
103 |
+
process_directory(directory)
|
104 |
+
logging.info("Processing complete.")
|
105 |
+
|
106 |
+
if __name__ == "__main__":
|
107 |
+
main()
|
ocr
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
from transformers import AutoModel, AutoTokenizer
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
6 |
+
model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
|
7 |
+
model = model.eval().cuda()
|
8 |
+
|
9 |
+
|
10 |
+
# input your test image
|
11 |
+
image_file = 'xxx.jpg'
|
12 |
+
|
13 |
+
# plain texts OCR
|
14 |
+
res = model.chat(tokenizer, image_file, ocr_type='ocr')
|
15 |
+
|
16 |
+
# format texts OCR:
|
17 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format')
|
18 |
+
|
19 |
+
# fine-grained OCR:
|
20 |
+
# res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_box='')
|
21 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format', ocr_box='')
|
22 |
+
# res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_color='')
|
23 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format', ocr_color='')
|
24 |
+
|
25 |
+
# multi-crop OCR:
|
26 |
+
# res = model.chat_crop(tokenizer, image_file, ocr_type='ocr')
|
27 |
+
# res = model.chat_crop(tokenizer, image_file, ocr_type='format')
|
28 |
+
|
29 |
+
# render the formatted OCR results:
|
30 |
+
# res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')
|
31 |
+
|
32 |
+
print(res)
|
33 |
+
|
pick_caption
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
|
6 |
+
def process_caption_files():
|
7 |
+
for file in os.listdir():
|
8 |
+
if file.endswith(".caption"):
|
9 |
+
# Check if the file already contains processed data
|
10 |
+
with open(file, 'r') as f:
|
11 |
+
lines = f.readlines()
|
12 |
+
|
13 |
+
if "\n----------\n" not in "".join(lines):
|
14 |
+
continue
|
15 |
+
|
16 |
+
for line in lines:
|
17 |
+
if "----------" in line:
|
18 |
+
break # Stop processing after finding the separator
|
19 |
+
|
20 |
+
content = ''.join(lines[:lines.index(line)]) # Extract text before the separator
|
21 |
+
processed_content = re.sub(r'[\-]+|\n', '', content) # Remove newlines and separator
|
22 |
+
|
23 |
+
with open(file, 'w') as f: # Save the condensed caption back to the same file
|
24 |
+
f.write(processed_content)
|
25 |
+
|
26 |
+
process_caption_files()
|
27 |
+
|
steal_sdscripts_metadata
CHANGED
File without changes
|
tensorboard_that_errors_on_conda
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import re
|
4 |
+
import sys
|
5 |
+
from tensorboard.main import run_main
|
6 |
+
if __name__ == '__main__':
|
7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
8 |
+
sys.exit(run_main())
|
zsh/gallery-dl.zsh
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Override the gallery-dl command to change the directory to ~/datasets
|
2 |
+
# before executing the original command
|
3 |
+
function gallery-dl() {
|
4 |
+
# Change to the ~/datasets directory
|
5 |
+
cd ~/datasets
|
6 |
+
|
7 |
+
# Execute the original gallery-dl command with all passed arguments
|
8 |
+
command gallery-dl "$@"
|
9 |
+
}
|
10 |
+
|
zsh/install_members.zsh
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/zsh
|
2 |
+
|
3 |
+
install_members() {
|
4 |
+
# Read the Cargo.toml file and extract the members
|
5 |
+
# The awk command extracts the lines between 'members = [' and ']'
|
6 |
+
# The sed command removes the first and last lines (which are '[' and ']')
|
7 |
+
# It also removes quotes, commas, and comments, and deletes empty lines
|
8 |
+
members=$(awk '/members = \[/,/\]/' Cargo.toml | sed -e '1d;$d' -e 's/[",]//g' -e 's/#.*//g' -e '/^\s*$/d')
|
9 |
+
|
10 |
+
# Convert the members string into an array
|
11 |
+
members_array=(${(f)members})
|
12 |
+
|
13 |
+
# Loop through each member and run the cargo install command
|
14 |
+
for member in $members_array; do
|
15 |
+
# Trim leading and trailing whitespace from each member
|
16 |
+
member=$(echo $member | xargs)
|
17 |
+
echo "Processing $member..."
|
18 |
+
# Change to the member's directory
|
19 |
+
# If the directory change fails, print an error message and exit the function
|
20 |
+
cd $member || { echo "Failed to enter directory $member"; return 1; }
|
21 |
+
# Run the cargo install command with the specified options
|
22 |
+
cargo install -Z build-std --target x86_64-unknown-linux-gnu --path .
|
23 |
+
# Return to the previous directory
|
24 |
+
cd ..
|
25 |
+
done
|
26 |
+
}
|
27 |
+
|