{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Count Tokens in Sample Prompts\n", "\n", "---\n", "\n", "This script is a utility for analyzing prompts in text files, counting the tokens for each sample prompt, and displaying the results in a visually appealing table format using the Rich library. It also provides a warning if the positive prompt's token count exceeds a certain threshold (77 in this case).\n", "\n", "This script is designed to process text files containing positive and negative prompts, count the number of tokens for each prompt, and display the results in a tabular format using the Rich library.\n", "\n", "1. It imports the necessary libraries: `os` for file and directory operations, `tiktoken` for encoding and counting tokens, and `rich.console` and `rich.table` for creating a console interface and a table for displaying the results.\n", "\n", "2. The `count_tokens` function takes a text input and returns the number of tokens in that text using the `tiktoken` library's `cl100k_base` encoding.\n", "\n", "3. The script creates a `Console` object from the `rich` library.\n", "\n", "4. It iterates through all files in the `E:\\training_dir` directory that end with `-sample-prompts.txt`.\n", "\n", "5. For each file, it opens the file and reads its contents line by line.\n", "\n", "6. Each line is expected to be in the format ` --n --`. The script splits the line at `--n` to separate the positive and negative prompts. As it works in \n", "\n", "7. It counts the number of tokens for both the positive and negative prompts using the `count_tokens` function.\n", "\n", "8. A `Table` object from the `rich` library is created, and the positive and negative prompts, along with their token counts, are added to the table as separate rows. The positive prompts are displayed in green, and the negative prompts are displayed in red.\n", "\n", "9. The table is printed to the console using the `Console.print` method.\n", "\n", "10. If the positive prompt's token count exceeds 77 (75 plus a buffer of 2), a warning message is printed in bold red.\n", "\n", "11. The script keeps track of the total number of prompts processed in the current file and prints it at the end." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Processing file: E:\\training_dir\\furrysticker-sample-prompts.txt\n",
       "
\n" ], "text/plain": [ "Processing file: E:\\training_dir\\furrysticker-sample-prompts.txt\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo,       │          77 │\n",
       "│             │ anthro male magic user wolf, purple wizard hat, purple wizard robe, green eyes,     │             │\n",
       "│             │ humanoid hands, claws, pointing up with one hand, \\(white fur:1.4\\), furry sticker, │             │\n",
       "│             │ simple background, black background, white outline                                  │             │\n",
       "│ Negative    │ low quality, worst quality, blurry, sticker                                         │           9 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo, │ 77 │\n", "│ │ anthro male magic user wolf, purple wizard hat, purple wizard robe, green eyes, │ │\n", "│ │ humanoid hands, claws, pointing up with one hand, \\(white fur:1.4\\), furry sticker, │ │\n", "│ │ simple background, black background, white outline │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurry, sticker │ 9 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo,       │          62 │\n",
       "│             │ anthro male fox, red fur, he has blue eyes with a stark gaze, dialogue bubble, text │             │\n",
       "│             │ box, furry sticker, simple background, black background, white outline              │             │\n",
       "│ Negative    │ low quality, worst quality, blurry, sticker                                         │           9 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo, │ 62 │\n", "│ │ anthro male fox, red fur, he has blue eyes with a stark gaze, dialogue bubble, text │ │\n", "│ │ box, furry sticker, simple background, black background, white outline │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurry, sticker │ 9 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo,       │          50 │\n",
       "│             │ anthro female red panda, she has amber eyes, furry sticker, simple background,      │             │\n",
       "│             │ black background, white outline                                                     │             │\n",
       "│ Negative    │ low quality, worst quality, blurry, sticker                                         │           9 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo, │ 50 │\n", "│ │ anthro female red panda, she has amber eyes, furry sticker, simple background, │ │\n", "│ │ black background, white outline │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurry, sticker │ 9 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo,       │          62 │\n",
       "│             │ anthro female lizard, blue scales, white body, scalie, long white claws, she has    │             │\n",
       "│             │ yellow eyes, furry sticker, simple background, black background, white outline      │             │\n",
       "│ Negative    │ low quality, worst quality, blurry, sticker                                         │           9 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo, │ 62 │\n", "│ │ anthro female lizard, blue scales, white body, scalie, long white claws, she has │ │\n", "│ │ yellow eyes, furry sticker, simple background, black background, white outline │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurry, sticker │ 9 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Total number of prompts in furrysticker-sample-prompts.txt: 4\n",
       "
\n" ], "text/plain": [ "\u001b[1mTotal number of prompts in furrysticker-sample-prompts.txt: \u001b[0m\u001b[1;36m4\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Processing file: E:\\training_dir\\realistic-sample-prompts.txt\n",
       "
\n" ], "text/plain": [ "Processing file: E:\\training_dir\\realistic-sample-prompts.txt\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry, solo,   │          60 │\n",
       "│             │ female anthro kindred, mask, presenting, white pillow, bedroom, looking at viewer,  │             │\n",
       "│             │ detailed background, amazing_background, scenery porn, realistic, photo             │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry, solo, │ 60 │\n", "│ │ female anthro kindred, mask, presenting, white pillow, bedroom, looking at viewer, │ │\n", "│ │ detailed background, amazing_background, scenery porn, realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry, solo,   │          70 │\n",
       "│             │ anthro female wolf, sexy pose, standing, gray fur, brown fur, canine pussy, black   │             │\n",
       "│             │ nose, blue eyes, pink areola, pink nipples, detailed background,                    │             │\n",
       "│             │ amazing_background, realistic, photo                                                │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry, solo, │ 70 │\n", "│ │ anthro female wolf, sexy pose, standing, gray fur, brown fur, canine pussy, black │ │\n", "│ │ nose, blue eyes, pink areola, pink nipples, detailed background, │ │\n", "│ │ amazing_background, realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry, solo,   │          73 │\n",
       "│             │ anthro male fox, glowing yellow eyes, night, crescent moon, gold bracers and        │             │\n",
       "│             │ necklace, loincloth, canine genitalia, knot, amazing_background, scenery porn,      │             │\n",
       "│             │ white marble ruins, realistic, photo                                                │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry, solo, │ 73 │\n", "│ │ anthro male fox, glowing yellow eyes, night, crescent moon, gold bracers and │ │\n", "│ │ necklace, loincloth, canine genitalia, knot, amazing_background, scenery porn, │ │\n", "│ │ white marble ruins, realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo,       │          74 │\n",
       "│             │ full-length portrait, anthro female red panda, detailed background,                 │             │\n",
       "│             │ amazing_background, pussy, scenery porn, photo, realistic, looking at viewer, on    │             │\n",
       "│             │ back, sexy pose, humanoid hands, claws, pink areola, pink nipples                   │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, solo, │ 74 │\n", "│ │ full-length portrait, anthro female red panda, detailed background, │ │\n", "│ │ amazing_background, pussy, scenery porn, photo, realistic, looking at viewer, on │ │\n", "│ │ back, sexy pose, humanoid hands, claws, pink areola, pink nipples │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, rating_explicit, source_furry, solo, full-length   │          69 │\n",
       "│             │ portrait, anthro female snow leopard, pussy, pink nipples, pink areola, detailed    │             │\n",
       "│             │ background, amazing_background, scenery porn, snowy mountain peak, on back, sexy    │             │\n",
       "│             │ pose, looking at viewer, realistic, photo                                           │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, rating_explicit, source_furry, solo, full-length │ 69 │\n", "│ │ portrait, anthro female snow leopard, pussy, pink nipples, pink areola, detailed │ │\n", "│ │ background, amazing_background, scenery porn, snowy mountain peak, on back, sexy │ │\n", "│ │ pose, looking at viewer, realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, portrait,   │          71 │\n",
       "│             │ an anthro male wolf, black nose, (white fur:1.2), monotone fur, green eyes, purple  │             │\n",
       "│             │ wizard hat, purple wizard robe, detailed background, amazing_background, forest,    │             │\n",
       "│             │ realistic, photo                                                                    │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, portrait, │ 71 │\n", "│ │ an anthro male wolf, black nose, (white fur:1.2), monotone fur, green eyes, purple │ │\n", "│ │ wizard hat, purple wizard robe, detailed background, amazing_background, forest, │ │\n", "│ │ realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, portrait,   │          65 │\n",
       "│             │ anthro male dragon, scale iridescence, detailed background, amazing_background,     │             │\n",
       "│             │ scenery porn, snowy mountain peak, on back, sexy pose, looking at viewer,           │             │\n",
       "│             │ realistic, photo                                                                    │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, portrait, │ 65 │\n", "│ │ anthro male dragon, scale iridescence, detailed background, amazing_background, │ │\n", "│ │ scenery porn, snowy mountain peak, on back, sexy pose, looking at viewer, │ │\n", "│ │ realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n",
       "┃ Prompt Type  Prompt                                                                               Token Count ┃\n",
       "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n",
       "│ Positive    │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, full-length │          71 │\n",
       "│             │ portrait, anthro female kobold, scalie, scale iridescence, detailed background,     │             │\n",
       "│             │ amazing_background, scenery porn, snowy mountain peak, on back, sexy pose, looking  │             │\n",
       "│             │ at viewer, realistic, photo                                                         │             │\n",
       "│ Negative    │ low quality, worst quality, blurred background, blurry, simple background           │          13 │\n",
       "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mPrompt Type\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mPrompt \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mToken Count\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩\n", "│ \u001b[32mPositive\u001b[0m │ score_9, score_8_up, score_7_up, score_6_up, rating_safe, source_furry, full-length │ 71 │\n", "│ │ portrait, anthro female kobold, scalie, scale iridescence, detailed background, │ │\n", "│ │ amazing_background, scenery porn, snowy mountain peak, on back, sexy pose, looking │ │\n", "│ │ at viewer, realistic, photo │ │\n", "│ \u001b[31mNegative\u001b[0m │ low quality, worst quality, blurred background, blurry, simple background │ 13 │\n", "└─────────────┴─────────────────────────────────────────────────────────────────────────────────────┴─────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Total number of prompts in realistic-sample-prompts.txt: 8\n",
       "
\n" ], "text/plain": [ "\u001b[1mTotal number of prompts in realistic-sample-prompts.txt: \u001b[0m\u001b[1;36m8\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import os\n", "import tiktoken\n", "from rich.console import Console\n", "from rich.table import Table\n", "\n", "def count_tokens(text):\n", " enc = tiktoken.get_encoding(\"cl100k_base\")\n", " tokens = enc.encode(text)\n", " return len(tokens)\n", "\n", "count_tokens(\"canine genitalia, knot\")\n", "\n", "console = Console()\n", "\n", "for file in os.listdir(\"E:\\\\training_dir\"):\n", " if file.endswith(\"-sample-prompts.txt\"):\n", " file_path = os.path.join(\"E:\\\\training_dir\", file)\n", " console.print(f\"Processing file: {file_path}\")\n", "\n", " prompt_count = 0\n", " with open(file_path, \"r\") as f:\n", " lines = f.readlines()\n", "\n", " for line in lines:\n", " if line.startswith(\"#\"):\n", " continue\n", " parts = line.split(\"--n\")\n", " positive_prompt = parts[0].strip()\n", " negative_prompt = parts[1].strip().split(\" --\")[0]\n", "\n", " positive_token_count = count_tokens(positive_prompt)\n", " negative_token_count = count_tokens(negative_prompt)\n", "\n", " table = Table()\n", " table.add_column(\"Prompt Type\", justify=\"left\")\n", " table.add_column(\"Prompt\", justify=\"left\")\n", " table.add_column(\"Token Count\", justify=\"right\")\n", " table.add_row(\"[green]Positive[/green]\", positive_prompt, str(positive_token_count))\n", " table.add_row(\"[red]Negative[/red]\", negative_prompt, str(negative_token_count))\n", " console.print(table)\n", "\n", " if positive_token_count > 77:\n", " console.print(\n", " \"[bold red]Warning: Positive prompt token count exceeds 75.[/bold red]\"\n", " )\n", " prompt_count += 1\n", "\n", " console.print(f\"[bold]Total number of prompts in {file}: {prompt_count}[/bold]\")" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }