| # | |
| # Pull captions from filenames and make them suitable for use by Khoya trainer. | |
| # | |
| # Directory containing the .png files | |
| png_directory="/path/to/png_files" | |
| # Directory to save the .txt files | |
| txt_directory="/path/to/txt_files" | |
| # Create the txt_directory if it doesn't exist | |
| mkdir -p "$txt_directory" | |
| # Loop through each .png file in the png_directory | |
| for png_file in "$png_directory"/*.png; do | |
| # Extract the filename without the extension | |
| base_name=$(basename "$png_file" .png) | |
| # Replace underscores with spaces | |
| txt_content="${base_name//_/ }" | |
| # Create a .txt file with the same name and write the content | |
| echo "$txt_content" > "$txt_directory/${base_name}.txt" | |
| done | |
| echo "TXT files created in $txt_directory" | |