File size: 60,766 Bytes
806ca56 84f3a3d 806ca56 84f3a3d 806ca56 84f3a3d 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 84f3a3d 9d0cfc4 84f3a3d 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 9d0cfc4 806ca56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
{
"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 `<positive_prompt> --n <negative_prompt> --<additional_arguments>`. 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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Processing file: E:\\training_dir\\furrysticker-sample-prompts.txt\n",
"</pre>\n"
],
"text/plain": [
"Processing file: E:\\training_dir\\furrysticker-sample-prompts.txt\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurry, sticker β 9 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurry, sticker β 9 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurry, sticker β 9 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurry, sticker β 9 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Total number of prompts in furrysticker-sample-prompts.txt: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Processing file: E:\\training_dir\\realistic-sample-prompts.txt\n",
"</pre>\n"
],
"text/plain": [
"Processing file: E:\\training_dir\\realistic-sample-prompts.txt\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββ³ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ³ββββββββββββββ\n",
"β<span style=\"font-weight: bold\"> Prompt Type </span>β<span style=\"font-weight: bold\"> Prompt </span>β<span style=\"font-weight: bold\"> Token Count </span>β\n",
"β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
"β <span style=\"color: #008000; text-decoration-color: #008000\">Positive</span> β 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",
"β <span style=\"color: #800000; text-decoration-color: #800000\">Negative</span> β low quality, worst quality, blurred background, blurry, simple background β 13 β\n",
"βββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββ\n",
"</pre>\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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Total number of prompts in realistic-sample-prompts.txt: </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">8</span>\n",
"</pre>\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
}
|