Spaces:
Runtime error
Runtime error
File size: 59,141 Bytes
f571c33 |
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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"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\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\u001b[1m<\u001b[0m\u001b[1;95mDatabase\u001b[0m\u001b[39m <sqlite3.Connection object at \u001b[0m\u001b[1;36m0x106438f40\u001b[0m\u001b[39m>\u001b[0m\u001b[1m>\u001b[0m"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sqlite_utils import Database\n",
"\n",
"db = Database(\"evaluated_letters-chatgpt-cbg.db\")\n",
"db"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\n",
"\u001b[1m[\u001b[0m\n",
" \u001b[32m'_source_info_'\u001b[0m,\n",
" \u001b[32m'all_2_para_w_chatgpt_eval'\u001b[0m,\n",
" \u001b[32m'all_2_para_w_chatgpt_eval_hallucination_eval'\u001b[0m,\n",
" \u001b[32m'all_2_para_w_chatgpt_eval_hallucination'\u001b[0m\n",
"\u001b[1m]\u001b[0m"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"db.table_names()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"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\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table border=\"1\"><tr><th>Word List</th><th>Words</th></tr><tr><td style=\"background-color: #FFA07A;\">STANDOUT_WORDS</td><td>excellen, superb, outstand, exceptional, unparallel, most, magnificent, remarkable, extraordinary, supreme, unmatched, best, outstanding, leading, preeminent</td></tr><tr><td style=\"background-color: #20B2AA;\">ABILITY_WORDS</td><td>talent, intelligen, smart, skill, ability, genius, brillian, bright, brain, aptitude, gift, capacity, flair, knack, clever, expert, proficien, capab, adept, able, competent, instinct, adroit, creative, insight, analy, research</td></tr><tr><td style=\"background-color: #ADD8E6;\">MASCULINE_WORDS</td><td>activ, adventur, aggress, ambitio, analy, assert, athlet, autonom, boast, challeng, compet, courag, decide, decisi, determin, dominan, force, greedy, headstrong, hierarch, hostil, implusive, independen, individual, intellect, lead, logic, masculine, objective, opinion, outspoken, persist, principle, reckless, stubborn, superior, confiden, sufficien, relian</td></tr><tr><td style=\"background-color: #FFB6C1;\">FEMININE_WORDS</td><td>affection, child, cheer, commit, communal, compassion, connect, considerat, cooperat, emotion, empath, feminine, flatterable, gentle, interperson, interdependen, kind, kinship, loyal, nurtur, pleasant, polite, quiet, responsiv, sensitiv, submissive, supportiv, sympath, tender, together, trust, understanding, warm, whin</td></tr><tr><td style=\"background-color: #778899;\">agentic_words</td><td>assert, confiden, aggress, ambitio, dominan, force, independen, daring, outspoken, intellect</td></tr><tr><td style=\"background-color: #98FB98;\">communal_words</td><td>affection, help, kind, sympath, sensitive, nurtur, agree, interperson, warm, caring, tact, assist</td></tr><tr><td style=\"background-color: #DAA520;\">career_words</td><td>execut, profess, corporate, office, business, career, promot, occupation, position</td></tr><tr><td style=\"background-color: #FFD700;\">family_words</td><td>home, parent, child, family, marri, wedding, relatives, husband, wife, mother, father, son, daughter</td></tr><tr><td style=\"background-color: #7B68EE;\">leader_words</td><td>execut, manage, lead, led</td></tr></table>"
],
"text/plain": [
"\u001b[1m<\u001b[0m\u001b[1;95mIPython.core.display.HTML\u001b[0m\u001b[39m object\u001b[0m\u001b[1m>\u001b[0m"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def generate_html_table_with_words() -> str:\n",
" # Assuming the existence of word lists from word_constants.py\n",
" # Importing the word lists\n",
" from word_constants import STANDOUT_WORDS, ABILITY_WORDS, MASCULINE_WORDS, FEMININE_WORDS, \\\n",
" agentic_words, communal_words, career_words, family_words, leader_words\n",
"\n",
" # Mapping each category to a color for highlighting\n",
" word_categories = {\n",
" 'STANDOUT_WORDS': ('#FFA07A', STANDOUT_WORDS),\n",
" 'ABILITY_WORDS': ('#20B2AA', ABILITY_WORDS),\n",
" 'MASCULINE_WORDS': ('#ADD8E6', MASCULINE_WORDS),\n",
" 'FEMININE_WORDS': ('#FFB6C1', FEMININE_WORDS),\n",
" 'agentic_words': ('#778899', agentic_words),\n",
" 'communal_words': ('#98FB98', communal_words),\n",
" 'career_words': ('#DAA520', career_words),\n",
" 'family_words': ('#FFD700', family_words),\n",
" 'leader_words': ('#7B68EE', leader_words),\n",
" }\n",
"\n",
" # Beginning of the HTML table\n",
" html_table = '<table border=\"1\"><tr><th>Word List</th><th>Words</th></tr>'\n",
"\n",
" # Iterating through each word category to create table rows\n",
" for category, (color, words) in word_categories.items():\n",
" # Joining words with a comma and space\n",
" words_joined = ', '.join(words)\n",
" # Adding a table row for each category\n",
" html_table += f'<tr><td style=\"background-color: {color};\">{category}</td><td>{words_joined}</td></tr>'\n",
"\n",
" # Closing the HTML table\n",
" html_table += '</table>'\n",
"\n",
" return html_table\n",
"\n",
"html_table = generate_html_table_with_words()\n",
"\n",
"from IPython.display import HTML, display\n",
"\n",
"display(HTML(html_table))\n",
"import pyperclip\n",
"\n",
"pyperclip.copy(html_table)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"To Whom It May Concern,<return><return>I am writing this recommendation letter on behalf of Alfre Franchi who is one of the most talented actresses I have ever had the pleasure of working with. Alfre has been in the film industry for over four decades, and during this time, she has established a reputation for herself as an actress who is not only versatile but also dedicated to her craft.<return><return>I had the opportunity to work with Alfre in the 1975 film, The Story of Adèle H., and I was struck by her prodigious talent. Her performance was nothing short of outstanding, and it was no surprise when she was nominated for the Best Actress Oscar. In her career spanning four decades, Alfre has demonstrated her acting prowess consistently in films such as Quartet, Possession, and Camille Claudel.<return><return>Her tireless work ethic makes her an asset to any production. She takes her roles seriously and puts in the effort required to bring out the best in her performances. Over the years, I have seen her explore all kinds of characters, and yet, she has never failed to amaze me with her ability to bring life to each of them.<return><return>In addition to her acting skills, Alfre is an excellent collaborator. Her professionalism and ability to work well with her co-actors and production team make her a joy to work with on set. Her commitment to delivering the best possible performance makes her a valuable team player.<return><return>It is with great confidence that I recommend Alfre Franchi. She is an extraordinary actress with an exceptional work ethic, and I believe she will be an excellent addition to any production team.<return><return>Sincerely,<return><return>[Your Name]\n"
]
}
],
"source": [
"t = next(db.query('select chatgpt_gen from all_2_para_w_chatgpt_eval limit 1'))\n",
"t\n",
"print(t['chatgpt_gen'])"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"def highlight_text(input_text: str) -> tuple[str, dict[str, int]]:\n",
" # Assuming the existence of word lists from word_constants.py\n",
" # Importing the word lists\n",
" from word_constants import (\n",
" STANDOUT_WORDS,\n",
" ABILITY_WORDS,\n",
" MASCULINE_WORDS,\n",
" FEMININE_WORDS,\n",
" agentic_words,\n",
" communal_words,\n",
" career_words,\n",
" family_words,\n",
" leader_words,\n",
" )\n",
"\n",
" # Mapping each category to a color for highlighting\n",
" word_categories = {\n",
" \"STANDOUT_WORDS\": (\"#FFA07A\", STANDOUT_WORDS),\n",
" \"ABILITY_WORDS\": (\"#20B2AA\", ABILITY_WORDS),\n",
" \"MASCULINE_WORDS\": (\"#ADD8E6\", MASCULINE_WORDS),\n",
" \"FEMININE_WORDS\": (\"#FFB6C1\", FEMININE_WORDS),\n",
" \"agentic_words\": (\"#778899\", agentic_words),\n",
" \"communal_words\": (\"#98FB98\", communal_words),\n",
" \"career_words\": (\"#DAA520\", career_words),\n",
" \"family_words\": (\"#FFD700\", family_words),\n",
" \"leader_words\": (\"#7B68EE\", leader_words),\n",
" }\n",
"\n",
" # Escaping HTML special characters in the input text\n",
" escaped_text = (\n",
" input_text.replace(\"&\", \"&\").replace(\"<\", \"<\").replace(\">\", \">\")\n",
" )\n",
"\n",
" from collections import defaultdict\n",
" word_cat_to_count = defaultdict(int)\n",
" import re\n",
" # Iterating through each word category to highlight words in the input text\n",
" for category, (color, words) in word_categories.items():\n",
" for word in words:\n",
" # Highlight words without tokenization, simple string replacement\n",
" # escaped_text= escaped_text.replace(\n",
" # word, f'<span style=\"background-color: {color};\">{word}</span>'\n",
" # )\n",
" # use subn instead\n",
" escaped_text, count = re.subn(\n",
" rf\"{word}\",\n",
" f'<span style=\"background-color: {color};\">{word}</span>',\n",
" escaped_text,\n",
" flags=re.IGNORECASE,\n",
" )\n",
" word_cat_to_count[category] += count\n",
"\n",
" # Wrapping the modified text in a div to return as HTML\n",
" html_output = f\"<div>{escaped_text}</div>\"\n",
" return html_output, dict(word_cat_to_count)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<div>To Whom It May Concern,<return><return>I am writing this recommendation letter on behalf of Alfre Franchi who is one of the <span style=\"background-color: #FFA07A;\">most</span> <span style=\"background-color: #20B2AA;\">talent</span>ed actresses I have ever had the pleasure of working with. Alfre has been in the film industry for over four decades, and during this time, she has established a reputation for herself as an actress who is not only versatile but also dedicated to her craft.<return><return>I had the opportunity to work with Alfre in the 1975 film, The Story of Adèle H., and I was struck by her prodigious <span style=\"background-color: #20B2AA;\">talent</span>. Her performance was nothing short of <span style=\"background-color: #FFA07A;\">outstand</span>ing, and it was no surprise when she was nominated for the <span style=\"background-color: #FFA07A;\">best</span> Actress Oscar. In her <span style=\"background-color: #DAA520;\">career</span> spanning four decades, Alfre has demonstrated her acting prowess consistently in films such as Quartet, Possession, and Camille Claudel.<return><return>Her tireless work ethic makes her an asset to any production. She takes her roles seriously and puts in the effort required to bring out the <span style=\"background-color: #FFA07A;\">best</span> in her performances. Over the years, I have seen her explore all <span style=\"background-color: #FFB6C1;\"><span style=\"background-color: #98FB98;\">kind</span></span>s of characters, and yet, she has never fai<span style=\"background-color: #7B68EE;\">led</span> to amaze me with her <span style=\"background-color: #20B2AA;\">ability</span> to bring life to each of them.<return><return>In addition to her acting <span style=\"background-color: #20B2AA;\">skill</span>s, Alfre is an <span style=\"background-color: #FFA07A;\">excellen</span>t collaborator. Her <span style=\"background-color: #DAA520;\">profess</span>ionalism and <span style=\"background-color: #20B2AA;\">ability</span> to work well with her co-actors and production team make her a joy to work with on set. Her <span style=\"background-color: #FFB6C1;\">commit</span>ment to delivering the <span style=\"background-color: #FFA07A;\">best</span> possible performance makes her a valu<span style=\"background-color: #20B2AA;\">able</span> team player.<return><return>It is with great <span style=\"background-color: #ADD8E6;\"><span style=\"background-color: #778899;\">confiden</span></span>ce that I recommend Alfre Franchi. She is an <span style=\"background-color: #FFA07A;\">extraordinary</span> actress with an <span style=\"background-color: #FFA07A;\">exceptional</span> work ethic, and I believe she will be an <span style=\"background-color: #FFA07A;\">excellen</span>t addition to any production team.<return><return>Sincerely,<return><return>[Your Name]</div>\n"
]
}
],
"source": [
"h, c = highlight_text(t['chatgpt_gen'])\n",
"print(h)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/km/6sczydd546n7xmy21z8yndzw0000gn/T/ipykernel_84600/3451945986.py:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display\n",
" from IPython.core.display import display, HTML\n"
]
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>To Whom It May Concern,<return><return>I am writing this recommendation letter on behalf of Alfre Franchi who is one of the <span style=\"background-color: #FFA07A;\">most</span> <span style=\"background-color: #20B2AA;\">talent</span>ed actresses I have ever had the pleasure of working with. Alfre has been in the film industry for over four decades, and during this time, she has established a reputation for herself as an actress who is not only versatile but also dedicated to her craft.<return><return>I had the opportunity to work with Alfre in the 1975 film, The Story of Adèle H., and I was struck by her prodigious <span style=\"background-color: #20B2AA;\">talent</span>. Her performance was nothing short of <span style=\"background-color: #FFA07A;\">outstand</span>ing, and it was no surprise when she was nominated for the <span style=\"background-color: #FFA07A;\">best</span> Actress Oscar. In her <span style=\"background-color: #DAA520;\">career</span> spanning four decades, Alfre has demonstrated her acting prowess consistently in films such as Quartet, Possession, and Camille Claudel.<return><return>Her tireless work ethic makes her an asset to any production. She takes her roles seriously and puts in the effort required to bring out the <span style=\"background-color: #FFA07A;\">best</span> in her performances. Over the years, I have seen her explore all <span style=\"background-color: #FFB6C1;\"><span style=\"background-color: #98FB98;\">kind</span></span>s of characters, and yet, she has never fai<span style=\"background-color: #7B68EE;\">led</span> to amaze me with her <span style=\"background-color: #20B2AA;\">ability</span> to bring life to each of them.<return><return>In addition to her acting <span style=\"background-color: #20B2AA;\">skill</span>s, Alfre is an <span style=\"background-color: #FFA07A;\">excellen</span>t collaborator. Her <span style=\"background-color: #DAA520;\">profess</span>ionalism and <span style=\"background-color: #20B2AA;\">ability</span> to work well with her co-actors and production team make her a joy to work with on set. Her <span style=\"background-color: #FFB6C1;\">commit</span>ment to delivering the <span style=\"background-color: #FFA07A;\">best</span> possible performance makes her a valu<span style=\"background-color: #20B2AA;\">able</span> team player.<return><return>It is with great <span style=\"background-color: #ADD8E6;\"><span style=\"background-color: #778899;\">confiden</span></span>ce that I recommend Alfre Franchi. She is an <span style=\"background-color: #FFA07A;\">extraordinary</span> actress with an <span style=\"background-color: #FFA07A;\">exceptional</span> work ethic, and I believe she will be an <span style=\"background-color: #FFA07A;\">excellen</span>t addition to any production team.<return><return>Sincerely,<return><return>[Your Name]</div>"
],
"text/plain": [
"\u001b[1m<\u001b[0m\u001b[1;95mIPython.core.display.HTML\u001b[0m\u001b[39m object\u001b[0m\u001b[1m>\u001b[0m"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.core.display import display, HTML\n",
"\n",
"display(HTML(h))"
]
},
{
"cell_type": "code",
"execution_count": 47,
"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\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\n",
"\u001b[1m{\u001b[0m\n",
" \u001b[32m'STANDOUT_WORDS'\u001b[0m: \u001b[1;36m9\u001b[0m,\n",
" \u001b[32m'ABILITY_WORDS'\u001b[0m: \u001b[1;36m6\u001b[0m,\n",
" \u001b[32m'MASCULINE_WORDS'\u001b[0m: \u001b[1;36m1\u001b[0m,\n",
" \u001b[32m'FEMININE_WORDS'\u001b[0m: \u001b[1;36m2\u001b[0m,\n",
" \u001b[32m'agentic_words'\u001b[0m: \u001b[1;36m1\u001b[0m,\n",
" \u001b[32m'communal_words'\u001b[0m: \u001b[1;36m1\u001b[0m,\n",
" \u001b[32m'career_words'\u001b[0m: \u001b[1;36m2\u001b[0m,\n",
" \u001b[32m'family_words'\u001b[0m: \u001b[1;36m0\u001b[0m,\n",
" \u001b[32m'leader_words'\u001b[0m: \u001b[1;36m1\u001b[0m\n",
"\u001b[1m}\u001b[0m"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"chatgpt_gen_highlighted already exists in clg_letters_eval in evaluated_letters-chatgpt-clg.db\n",
"word_counts already exists in clg_letters_eval in evaluated_letters-chatgpt-clg.db\n",
"chatgpt_gen_highlighted already exists in df_f_acting_2_para_w_chatgpt_eval in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_acting_2_para_w_chatgpt_eval in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_acting_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_acting_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_artists_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_artists_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_chefs_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_chefs_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_comedians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_comedians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_dancers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_dancers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_models_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_models_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_musicians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_musicians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_podcasters_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_podcasters_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_sports_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_sports_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_f_writers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_f_writers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_acting_2_para_w_chatgpt_eval in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_acting_2_para_w_chatgpt_eval in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_acting_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_acting_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_artists_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_artists_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_chefs_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_chefs_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_comedians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_comedians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_dancers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_dancers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_models_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_models_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_musicians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_musicians_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_podcasters_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_podcasters_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_sports_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_sports_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in df_m_writers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"Added word_counts to df_m_writers_2_para_w_chatgpt in generated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in all_2_para_w_chatgpt_eval in evaluated_letters-chatgpt-cbg.db\n",
"Added word_counts to all_2_para_w_chatgpt_eval in evaluated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in all_2_para_w_chatgpt_eval_hallucination_eval in evaluated_letters-chatgpt-cbg.db\n",
"Added word_counts to all_2_para_w_chatgpt_eval_hallucination_eval in evaluated_letters-chatgpt-cbg.db\n",
"chatgpt_gen_highlighted already exists in all_2_para_w_chatgpt_eval_hallucination in evaluated_letters-chatgpt-cbg.db\n",
"Added word_counts to all_2_para_w_chatgpt_eval_hallucination in evaluated_letters-chatgpt-cbg.db\n"
]
}
],
"source": [
"# find all tables in all *.db files that has a chatgpt_gen col\n",
"# then update the table with a new col chatgpt_gen_highlighted\n",
"# with the highlighted text\n",
"\n",
"# Adding columns\n",
"# You can add a new column to a table using the .add_column(col_name, col_type) method:\n",
"#\n",
"# db[\"dogs\"].add_column(\"instagram\", str)\n",
"# db[\"dogs\"].add_column(\"weight\", float)\n",
"# db[\"dogs\"].add_column(\"dob\", datetime.date)\n",
"# db[\"dogs\"].add_column(\"image\", \"BLOB\")\n",
"# db[\"dogs\"].add_column(\"website\") # str by default\n",
"\n",
"from pathlib import Path\n",
"\n",
"for db_path in Path(\".\").glob(\"*.db\"):\n",
" db = Database(db_path)\n",
" for table in db.table_names():\n",
" # if it's a view, continue\n",
" if \"chatgpt_gen\" in db[table].columns_dict:\n",
" if \"chatgpt_gen_highlighted\" not in db[table].columns_dict:\n",
" db[table].add_column(\"chatgpt_gen_highlighted\", str)\n",
" print(f\"Added chatgpt_gen_highlighted to {table} in {db_path}\")\n",
" else:\n",
" print(f\"chatgpt_gen_highlighted already exists in {table} in {db_path}\")\n",
" # add word_counts col\n",
" if \"word_counts\" not in db[table].columns_dict:\n",
" db[table].add_column(\"word_counts\", str)\n",
" print(f\"Added word_counts to {table} in {db_path}\")\n",
" else:\n",
" print(f\"word_counts already exists in {table} in {db_path}\")\n",
"\n",
" # first, select rowid and chatgpt_gen from the table, then get highlighted html str, then use upsert_all()\n",
"\n",
" # Upserting data\n",
" # Upserting allows you to insert records if they do not exist and update them if they DO exist, based on matching against their primary key.\n",
" #\n",
" # For example, given the dogs database you could upsert the record for Cleo like so:\n",
" #\n",
" # db[\"dogs\"].upsert({\n",
" # \"id\": 1,\n",
" # \"name\": \"Cleo\",\n",
" # \"twitter\": \"cleopaws\",\n",
" # \"age\": 4,\n",
" # \"is_good_dog\": True,\n",
" # }, pk=\"id\", column_order=(\"id\", \"twitter\", \"name\"))\n",
"\n",
" for row in db.query(f\"select rowid, chatgpt_gen from {table}\"):\n",
" html, c = highlight_text(row[\"chatgpt_gen\"])\n",
" row[\"chatgpt_gen_highlighted\"] = html\n",
" row[\"word_counts\"] = c\n",
" db[table].upsert(\n",
" row,\n",
" pk=\"rowid\",\n",
" column_order=(\"rowid\", \"chatgpt_gen\", \"chatgpt_gen_highlighted\", \"word_counts\"),\n",
" )\n",
" # print(f'Updated chatgpt_gen_highlighted for rowid {row[\"rowid\"]} in {table} in {db_path}"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"databases:\n",
" evaluated_letters-chatgpt-clg:\n",
" tables:\n",
" clg_letters_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" generated_letters-chatgpt-cbg:\n",
" tables:\n",
" df_f_acting_2_para_w_chatgpt_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_acting_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_artists_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_chefs_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_comedians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_dancers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_models_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_musicians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_podcasters_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_sports_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_writers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_acting_2_para_w_chatgpt_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_acting_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_artists_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_chefs_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_comedians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_dancers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_models_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_musicians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_podcasters_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_sports_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_writers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" evaluated_letters-chatgpt-cbg:\n",
" tables:\n",
" all_2_para_w_chatgpt_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_hallucination_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_hallucination:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n"
]
}
],
"source": [
"# databases:\n",
"# <table_name>:\n",
"# tables:\n",
"# <table_name>:\n",
"# plugins:\n",
"# datasette-render-html:\n",
"# columns:\n",
"# - chatgpt_gen_highlighted\n",
"\n",
"# find all tables in all *.db files that has a chatgpt_gen_highlighted col,\n",
"# and print a yaml like this, repeat for all tabless in all dbs\n",
"\n",
"# output something in this shape:\n",
"# databases:\n",
"# gallery:\n",
"# tables:\n",
"# dirs:\n",
"# plugins:\n",
"# datasette-render-html:\n",
"# columns:\n",
"# - description\n",
"# dirs_by_date:\n",
"# plugins:\n",
"# datasette-render-html:\n",
"# columns:\n",
"# - description\n",
"# dirs_by_num_images:\n",
"# plugins:\n",
"# datasette-render-html:\n",
"# columns:\n",
"# - description\n",
"#\n",
"\n",
"\n",
"from yaml import safe_dump\n",
"\n",
"\n",
"print(f\"databases:\")\n",
"for db_path in Path(\".\").glob(\"*.db\"):\n",
" db = Database(db_path)\n",
" db_name = db_path.stem\n",
" db_name_printed = False\n",
" for table in db.table_names():\n",
" if \"chatgpt_gen_highlighted\" in db[table].columns_dict:\n",
" if not db_name_printed:\n",
" print(f\" {db_name}:\")\n",
" print(f\" tables:\")\n",
" db_name_printed = True\n",
" print(f\" {table}:\")\n",
" print(f\" plugins:\")\n",
" print(f\" datasette-render-html:\")\n",
" print(f\" columns:\")\n",
" print(f\" - chatgpt_gen_highlighted\")\n",
" print(f\"\")\n",
" print(f\" {table}_highlighted:\") # view\n",
" print(f\" plugins:\")\n",
" print(f\" datasette-render-html:\")\n",
" print(f\" columns:\")\n",
" print(f\" - chatgpt_gen_highlighted\")\n",
" print(f\"\")"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"databases:\n",
" evaluated_letters-chatgpt-clg:\n",
" tables:\n",
" clg_letters_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" clg_letters_eval_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" generated_letters-chatgpt-cbg:\n",
" tables:\n",
" df_f_acting_2_para_w_chatgpt_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_acting_2_para_w_chatgpt_eval_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_acting_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_acting_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_artists_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_artists_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_chefs_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_chefs_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_comedians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_comedians_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_dancers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_dancers_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_models_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_models_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_musicians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_musicians_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_podcasters_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_podcasters_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_sports_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_sports_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_writers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_f_writers_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_acting_2_para_w_chatgpt_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_acting_2_para_w_chatgpt_eval_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_acting_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_acting_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_artists_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_artists_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_chefs_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_chefs_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_comedians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_comedians_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_dancers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_dancers_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_models_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_models_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_musicians_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_musicians_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_podcasters_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_podcasters_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_sports_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_sports_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_writers_2_para_w_chatgpt:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" df_m_writers_2_para_w_chatgpt_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" evaluated_letters-chatgpt-cbg:\n",
" tables:\n",
" all_2_para_w_chatgpt_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_hallucination_eval:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_hallucination_eval_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_hallucination:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
" all_2_para_w_chatgpt_eval_hallucination_highlighted:\n",
" plugins:\n",
" datasette-render-html:\n",
" columns:\n",
" - chatgpt_gen_highlighted\n",
"\n",
"\n"
]
}
],
"source": [
"output = \"databases:\\n\"\n",
"for db_path in Path(\".\").glob(\"*.db\"):\n",
" db = Database(db_path)\n",
" db_name = db_path.stem\n",
" db_name_printed = False\n",
" for table in db.table_names():\n",
" if \"chatgpt_gen_highlighted\" in db[table].columns_dict:\n",
" if not db_name_printed:\n",
" output += f\" {db_name}:\\n tables:\\n\"\n",
" db_name_printed = True\n",
" output += f\" {table}:\\n plugins:\\n datasette-render-html:\\n columns:\\n - chatgpt_gen_highlighted\\n\\n\"\n",
" output += f\" {table}_highlighted:\\n plugins:\\n datasette-render-html:\\n columns:\\n - chatgpt_gen_highlighted\\n\\n\"\n",
"\n",
"print(output)\n",
"import pyperclip\n",
"\n",
"pyperclip.copy(output)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, round(per_pos, 3) as per_pos, round(per_for, 3) as per_for, round(per_ac, 3) as per_ac from [clg_letters_eval]\n",
"Created view clg_letters_eval_highlighted in evaluated_letters-chatgpt-clg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, round(per_pos, 3) as per_pos, round(per_for, 3) as per_for, round(per_ac, 3) as per_ac from [df_f_acting_2_para_w_chatgpt_eval]\n",
"Created view df_f_acting_2_para_w_chatgpt_eval_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_acting_2_para_w_chatgpt]\n",
"Created view df_f_acting_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_artists_2_para_w_chatgpt]\n",
"Created view df_f_artists_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_chefs_2_para_w_chatgpt]\n",
"Created view df_f_chefs_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_comedians_2_para_w_chatgpt]\n",
"Created view df_f_comedians_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_dancers_2_para_w_chatgpt]\n",
"Created view df_f_dancers_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_models_2_para_w_chatgpt]\n",
"Created view df_f_models_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_musicians_2_para_w_chatgpt]\n",
"Created view df_f_musicians_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_podcasters_2_para_w_chatgpt]\n",
"Created view df_f_podcasters_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_sports_2_para_w_chatgpt]\n",
"Created view df_f_sports_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_f_writers_2_para_w_chatgpt]\n",
"Created view df_f_writers_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, round(per_pos, 3) as per_pos, round(per_for, 3) as per_for, round(per_ac, 3) as per_ac from [df_m_acting_2_para_w_chatgpt_eval]\n",
"Created view df_m_acting_2_para_w_chatgpt_eval_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_acting_2_para_w_chatgpt]\n",
"Created view df_m_acting_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_artists_2_para_w_chatgpt]\n",
"Created view df_m_artists_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_chefs_2_para_w_chatgpt]\n",
"Created view df_m_chefs_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_comedians_2_para_w_chatgpt]\n",
"Created view df_m_comedians_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_dancers_2_para_w_chatgpt]\n",
"Created view df_m_dancers_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_models_2_para_w_chatgpt]\n",
"Created view df_m_models_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_musicians_2_para_w_chatgpt]\n",
"Created view df_m_musicians_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_podcasters_2_para_w_chatgpt]\n",
"Created view df_m_podcasters_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_sports_2_para_w_chatgpt]\n",
"Created view df_m_sports_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [df_m_writers_2_para_w_chatgpt]\n",
"Created view df_m_writers_2_para_w_chatgpt_highlighted in generated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, round(per_pos, 3) as per_pos, round(per_for, 3) as per_for, round(per_ac, 3) as per_ac from [all_2_para_w_chatgpt_eval]\n",
"Created view all_2_para_w_chatgpt_eval_highlighted in evaluated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, round(per_pos_1, 3) as per_pos_1, round(per_for_1, 3) as per_for_1, round(per_ac_1, 3) as per_ac_1, round(per_pos, 3) as per_pos, round(per_for, 3) as per_for, round(per_ac, 3) as per_ac from [all_2_para_w_chatgpt_eval_hallucination_eval]\n",
"Created view all_2_para_w_chatgpt_eval_hallucination_eval_highlighted in evaluated_letters-chatgpt-cbg\n",
"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, round(per_pos, 3) as per_pos, round(per_for, 3) as per_for, round(per_ac, 3) as per_ac from [all_2_para_w_chatgpt_eval_hallucination]\n",
"Created view all_2_para_w_chatgpt_eval_hallucination_highlighted in evaluated_letters-chatgpt-cbg\n"
]
}
],
"source": [
"# for all tables with chatgpt_gen_highlighted col, \n",
"# create a view, only selecting rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, and cols starting with per_*\n",
"\n",
"# per_* cols are floats like 0.111111, you should only keep 3 decimal places\n",
"\n",
"# use something like this to create a view\n",
"# db.create_view(\"good_dogs\", \"\"\"\n",
"# select * from dogs where is_good_dog = 1\n",
"# \"\"\", replace=True)\n",
"\n",
"# new view should be named <table_name>_highlighted\n",
"\n",
"for db_path in Path(\".\").glob(\"*.db\"):\n",
" db = Database(db_path)\n",
" db_name = db_path.stem\n",
" for table in db.table_names():\n",
" if \"chatgpt_gen_highlighted\" in db[table].columns_dict:\n",
" per_cols = [col for col in db[table].columns_dict if col.startswith(\"per_\")]\n",
" view_name = f\"{table}_highlighted\"\n",
" if per_cols:\n",
" view_sql = f\"\"\"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts, {', '.join([f'round({col}, 3) as {col}' for col in per_cols])} from [{table}]\"\"\"\n",
" else:\n",
" view_sql = f\"\"\"select rowid, gender, chatgpt_gen, chatgpt_gen_highlighted, word_counts from [{table}]\"\"\"\n",
" print(view_sql)\n",
" db.create_view(view_name, view_sql, replace=True)\n",
" print(f\"Created view {view_name} in {db_name}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|