File size: 47,710 Bytes
2d2db50 | 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 | {
"cells": [
{
"cell_type": "markdown",
"id": "e6520fa6",
"metadata": {},
"source": [
"For this Project I'm going to import <a href=\"https://colab.research.google.com/drive/1CJmdX8a72dFvtuBZmv0T18eh2UfJ77Uu?usp=sharing\">this</a> model to figure out if an image is real or AI generated. This project is inspired by the <a href=\"https://course.fast.ai/Lessons/lesson2.html\"> Fastai course tutorials</a>, where a similar example was shown. I used Google colab to create the model, Huggingface and gradio to deploy the project, and Github for easy control. This project was made for fun, and as practice for more serious future projects. In this project I learned how to source images from the web, how to clean models, how to export models, and how to best deploy deep learning projects."
]
},
{
"cell_type": "markdown",
"id": "92cd1441",
"metadata": {},
"source": [
"this will set the default module name, so that any exported functions or classes will go into a file called app.py"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "b47015bb",
"metadata": {},
"outputs": [],
"source": [
"#|default_exp app"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e454e29a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\holyw\\AppData\\Local\\Programs\\Python\\Python311\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)"
]
},
{
"cell_type": "markdown",
"id": "54d1eae5",
"metadata": {},
"source": [
"Here we import fastai, which is a library that contains models, and other packets for deep learning development. Gradio is a package that helps develop web interfaces for python code. icrawler is another packet for sourcing images online, Bing is more compatable with icrawler compare to google."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "6049aced",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: fastai in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (2.7.14)\n",
"Requirement already satisfied: gradio in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (6.2.0)\n",
"Requirement already satisfied: icrawler in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.6.10)\n",
"Requirement already satisfied: pip in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (23.2.1)\n",
"Requirement already satisfied: packaging in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from fastai) (25.0)\n",
"Requirement already satisfied: fastdownload<2,>=0.0.5 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (0.0.7)\n",
"Requirement already satisfied: fastcore<1.6,>=1.5.29 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (1.5.55)\n",
"Requirement already satisfied: torchvision>=0.11 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (0.16.2+cpu)\n",
"Requirement already satisfied: matplotlib in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (3.10.8)\n",
"Requirement already satisfied: pandas in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (2.3.3)\n",
"Requirement already satisfied: requests in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (2.32.5)\n",
"Requirement already satisfied: pyyaml in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (6.0.3)\n",
"Requirement already satisfied: fastprogress>=0.2.4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (1.0.5)\n",
"Requirement already satisfied: pillow>=9.0.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (12.0.0)\n",
"Requirement already satisfied: scikit-learn in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (1.8.0)\n",
"Requirement already satisfied: scipy in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (1.16.3)\n",
"Requirement already satisfied: spacy<4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (3.8.11)\n",
"Requirement already satisfied: torch<2.3,>=1.10 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (2.1.2+cpu)\n",
"Requirement already satisfied: aiofiles<25.0,>=22.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (24.1.0)\n",
"Requirement already satisfied: anyio<5.0,>=3.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (4.12.0)\n",
"Requirement already satisfied: brotli>=1.1.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (1.2.0)\n",
"Requirement already satisfied: fastapi<1.0,>=0.115.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.128.0)\n",
"Requirement already satisfied: ffmpy in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (1.0.0)\n",
"Requirement already satisfied: gradio-client==2.0.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (2.0.2)\n",
"Requirement already satisfied: groovy~=0.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.1.2)\n",
"Requirement already satisfied: httpx<1.0,>=0.24.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.28.1)\n",
"Requirement already satisfied: huggingface-hub<2.0,>=0.33.5 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (1.2.3)\n",
"Requirement already satisfied: jinja2<4.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (3.1.6)\n",
"Requirement already satisfied: markupsafe<4.0,>=2.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (3.0.3)\n",
"Requirement already satisfied: numpy<3.0,>=1.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (1.26.4)\n",
"Requirement already satisfied: orjson~=3.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (3.11.5)\n",
"Requirement already satisfied: pydantic<=3.0,>=2.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (2.12.5)\n",
"Requirement already satisfied: pydub in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.25.1)\n",
"Requirement already satisfied: python-multipart>=0.0.18 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.0.21)\n",
"Requirement already satisfied: safehttpx<0.2.0,>=0.1.7 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.1.7)\n",
"Requirement already satisfied: semantic-version~=2.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (2.10.0)\n",
"Requirement already satisfied: starlette<1.0,>=0.40.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.50.0)\n",
"Requirement already satisfied: tomlkit<0.14.0,>=0.12.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.13.3)\n",
"Requirement already satisfied: typer<1.0,>=0.12 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.21.0)\n",
"Requirement already satisfied: typing-extensions~=4.0 in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from gradio) (4.15.0)\n",
"Requirement already satisfied: uvicorn>=0.14.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.40.0)\n",
"Requirement already satisfied: fsspec in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio-client==2.0.2->gradio) (2025.12.0)\n",
"Requirement already satisfied: beautifulsoup4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from icrawler) (4.14.3)\n",
"Requirement already satisfied: bs4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from icrawler) (0.0.2)\n",
"Requirement already satisfied: lxml in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from icrawler) (6.0.2)\n",
"Requirement already satisfied: six in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from icrawler) (1.17.0)\n",
"Requirement already satisfied: idna>=2.8 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5.0,>=3.0->gradio) (3.11)\n",
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi<1.0,>=0.115.2->gradio) (0.0.4)\n",
"Requirement already satisfied: certifi in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx<1.0,>=0.24.1->gradio) (2025.11.12)\n",
"Requirement already satisfied: httpcore==1.* in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx<1.0,>=0.24.1->gradio) (1.0.9)\n",
"Requirement already satisfied: h11>=0.16 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx<1.0,>=0.24.1->gradio) (0.16.0)\n",
"Requirement already satisfied: filelock in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub<2.0,>=0.33.5->gradio) (3.20.1)\n",
"Requirement already satisfied: hf-xet<2.0.0,>=1.2.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub<2.0,>=0.33.5->gradio) (1.2.0)\n",
"Requirement already satisfied: shellingham in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub<2.0,>=0.33.5->gradio) (1.5.4)\n",
"Requirement already satisfied: tqdm>=4.42.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub<2.0,>=0.33.5->gradio) (4.67.1)\n",
"Requirement already satisfied: typer-slim in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub<2.0,>=0.33.5->gradio) (0.21.0)\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from pandas->fastai) (2.9.0.post0)\n",
"Requirement already satisfied: pytz>=2020.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pandas->fastai) (2025.2)\n",
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pandas->fastai) (2025.3)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic<=3.0,>=2.0->gradio) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.41.5 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic<=3.0,>=2.0->gradio) (2.41.5)\n",
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic<=3.0,>=2.0->gradio) (0.4.2)\n",
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (3.0.12)\n",
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (1.0.5)\n",
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (1.0.15)\n",
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (2.0.13)\n",
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (3.0.12)\n",
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (8.3.10)\n",
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (1.1.3)\n",
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (2.5.2)\n",
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (2.0.10)\n",
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (0.4.3)\n",
"Requirement already satisfied: setuptools in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (65.5.0)\n",
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests->fastai) (3.4.4)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests->fastai) (2.6.2)\n",
"Requirement already satisfied: sympy in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch<2.3,>=1.10->fastai) (1.14.0)\n",
"Requirement already satisfied: networkx in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch<2.3,>=1.10->fastai) (3.6.1)\n",
"Requirement already satisfied: click>=8.0.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from typer<1.0,>=0.12->gradio) (8.3.1)\n",
"Requirement already satisfied: rich>=10.11.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from typer<1.0,>=0.12->gradio) (14.2.0)\n",
"Requirement already satisfied: soupsieve>=1.6.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4->icrawler) (2.8.1)\n",
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib->fastai) (1.3.3)\n",
"Requirement already satisfied: cycler>=0.10 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib->fastai) (0.12.1)\n",
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib->fastai) (4.61.1)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib->fastai) (1.4.9)\n",
"Requirement already satisfied: pyparsing>=3 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib->fastai) (3.3.1)\n",
"Requirement already satisfied: joblib>=1.3.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn->fastai) (1.5.3)\n",
"Requirement already satisfied: threadpoolctl>=3.2.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn->fastai) (3.6.0)\n",
"Requirement already satisfied: colorama in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from click>=8.0.0->typer<1.0,>=0.12->gradio) (0.4.6)\n",
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (4.0.0)\n",
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.19.2)\n",
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy<4->fastai) (1.3.3)\n",
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy<4->fastai) (0.1.5)\n",
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy<4->fastai) (0.23.0)\n",
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy<4->fastai) (7.5.0)\n",
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch<2.3,>=1.10->fastai) (1.3.0)\n",
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
"Requirement already satisfied: wrapt in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy<4->fastai) (2.0.1)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"[notice] A new release of pip is available: 23.2.1 -> 25.3\n",
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install fastai gradio icrawler\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "0033302b",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"from fastai.vision.all import load_learner"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "6571ebb8",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"import gradio as gr"
]
},
{
"cell_type": "markdown",
"id": "2bcd5faa",
"metadata": {},
"source": [
"Here I create a instance of a crawler that uses BingImages. The crawler will search for the term 'quayaquill' and it will return a single image. The output below gives use a url to the image."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1bb0d81a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-01-12 16:51:08,982 - INFO - icrawler.crawler - start crawling...\n",
"2026-01-12 16:51:08,996 - INFO - icrawler.crawler - starting 1 feeder threads...\n",
"2026-01-12 16:51:08,997 - INFO - feeder - thread feeder-001 exit\n",
"2026-01-12 16:51:09,015 - INFO - icrawler.crawler - starting 1 parser threads...\n",
"2026-01-12 16:51:09,031 - INFO - icrawler.crawler - starting 1 downloader threads...\n",
"2026-01-12 16:51:10,482 - INFO - parser - parsing result page https://www.bing.com/images/async?q=guayaquill&first=0\n",
"2026-01-12 16:51:12,130 - INFO - downloader - image #1\thttps://pic3.zhimg.com/v2-08529379c3b246bd4a36008ec9c1312a_r.jpg\n",
"2026-01-12 16:51:13,184 - INFO - downloader - downloaded images reach max num, thread downloader-001 is ready to exit\n",
"2026-01-12 16:51:13,184 - INFO - downloader - thread downloader-001 exit\n",
"2026-01-12 16:51:14,041 - INFO - icrawler.crawler - Crawling task done!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-01-12 16:51:14,626 - INFO - parser - downloaded image reached max num, thread parser-001 is ready to exit\n",
"2026-01-12 16:51:14,630 - INFO - parser - thread parser-001 exit\n"
]
}
],
"source": [
"from icrawler.builtin import BingImageCrawler\n",
"crawler = BingImageCrawler()\n",
"crawler.crawl(keyword='guayaquill', max_num=1)"
]
},
{
"cell_type": "markdown",
"id": "371034dd",
"metadata": {},
"source": [
"Now we load the model in our files that was exported from another project"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "1ff86656",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Sequential(\n",
" (0): Sequential(\n",
" (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): ReLU(inplace=True)\n",
" (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)\n",
" (4): Sequential(\n",
" (0): BasicBlock(\n",
" (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" (1): BasicBlock(\n",
" (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (5): Sequential(\n",
" (0): BasicBlock(\n",
" (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (downsample): Sequential(\n",
" (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
" (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (1): BasicBlock(\n",
" (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (6): Sequential(\n",
" (0): BasicBlock(\n",
" (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (downsample): Sequential(\n",
" (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
" (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (1): BasicBlock(\n",
" (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (7): Sequential(\n",
" (0): BasicBlock(\n",
" (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (downsample): Sequential(\n",
" (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
" (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (1): BasicBlock(\n",
" (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (relu): ReLU(inplace=True)\n",
" (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
" (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (1): Sequential(\n",
" (0): AdaptiveConcatPool2d(\n",
" (ap): AdaptiveAvgPool2d(output_size=1)\n",
" (mp): AdaptiveMaxPool2d(output_size=1)\n",
" )\n",
" (1): fastai.layers.Flatten(full=False)\n",
" (2): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (3): Dropout(p=0.25, inplace=False)\n",
" (4): Linear(in_features=1024, out_features=512, bias=False)\n",
" (5): ReLU(inplace=True)\n",
" (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (7): Dropout(p=0.5, inplace=False)\n",
" (8): Linear(in_features=512, out_features=2, bias=False)\n",
" )\n",
")"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#|export\n",
"from fastai.vision.all import *\n",
"import numpy as np\n",
"import torch\n",
"\n",
"dummy_img = PILImage.create(np.zeros((224,224,3), dtype=np.uint8))\n",
"\n",
"dblock = DataBlock(\n",
" blocks=(ImageBlock, CategoryBlock(vocab=['class_0', 'class_1'])),\n",
" get_items=lambda _: [dummy_img],\n",
" get_y=lambda _: 'class_0',\n",
" item_tfms=Resize(224)\n",
")\n",
"\n",
"dls = dblock.dataloaders(source=None, bs=1, device='cpu')\n",
"\n",
"learn = vision_learner(\n",
" dls,\n",
" resnet18,\n",
" n_out=2,\n",
" pretrained=False,\n",
" normalize=False\n",
")\n",
"\n",
"learn.model.load_state_dict(\n",
" torch.load(\"toai.bin\", map_location=\"cpu\")\n",
")\n",
"\n",
"learn.model.eval()\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "0867517f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<All keys matched successfully>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"state_dict = torch.load('toai.bin', map_location='cpu')\n",
"learn.model.load_state_dict(state_dict)"
]
},
{
"cell_type": "markdown",
"id": "55673fd4",
"metadata": {},
"source": [
"This will be a interface for the predict function, gradio will require this function to create its web UI. There are two categories in which an image can be; AI or not AI generated. For what ever image used it will grab the prediction index and probabillity, and it will return a dictionary that will out put the probability that the image would be in either category."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "d228b33f",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"from fastai.vision.all import PILImage\n",
"from PIL import Image\n",
"import requests\n",
"from io import BytesIO\n",
"\n",
"categories = ['AI Generated', 'Not AI Generated']\n",
"\n",
"def classify_image(img):\n",
"\n",
" fastai_img = PILImage.create(img)\n",
" pred, pred_idx, probs = learn.predict(fastai_img)\n",
"\n",
" return dict(zip(categories, map(float, probs)))"
]
},
{
"cell_type": "markdown",
"id": "54ef7eb7",
"metadata": {},
"source": [
"Using gradio we can create a web UI that expects a image input, outputs the lable. The interface will use our classify_image fucntion to output the answers. I'll add some examples below of AI, not AI, and some maybe AI images so that you people can try the model without having to download an image."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aec9f6e4",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-01-12 16:56:19,574 - INFO - httpx - HTTP Request: HEAD https://huggingface.co/api/telemetry/https%3A/api.gradio.app/gradio-initiated-analytics \"HTTP/1.1 200 OK\"\n",
"2026-01-12 16:56:21,249 - INFO - httpx - HTTP Request: GET https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D.jpeg \"HTTP/1.1 302 Found\"\n",
"2026-01-12 16:56:21,314 - INFO - httpx - HTTP Request: GET https://api.gradio.app/pkg-version \"HTTP/1.1 200 OK\"\n",
"2026-01-12 16:56:22,499 - INFO - httpx - HTTP Request: GET https://cas-bridge.xethub.hf.co/xet-bridge-us/696568e544f950f64beadee8/45eead74570e49d6275496982437d4f8e571c9991634ddf0759ab5da472e68e7?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=cas%2F20260112%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260112T215620Z&X-Amz-Expires=3600&X-Amz-Signature=5e90f72e40a21dc990d23ffb5816249414e3db12bfcfe72198f18adc1328c9de&X-Amz-SignedHeaders=host&X-Xet-Cas-Uid=public&response-content-disposition=inline%3B+filename*%3DUTF-8%27%27william_D.jpeg%3B+filename%3D%22william_D.jpeg%22%3B&response-content-type=image%2Fjpeg&x-id=GetObject&Expires=1768258580&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTc2ODI1ODU4MH19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2FzLWJyaWRnZS54ZXRodWIuaGYuY28veGV0LWJyaWRnZS11cy82OTY1NjhlNTQ0Zjk1MGY2NGJlYWRlZTgvNDVlZWFkNzQ1NzBlNDlkNjI3NTQ5Njk4MjQzN2Q0ZjhlNTcxYzk5OTE2MzRkZGYwNzU5YWI1ZGE0NzJlNjhlNyoifV19&Signature=Z0EddAlk4d6jWLjsLYztXvtsHL9IIjWJfnKhGrC%7E82ozFNDPDirJmkE21YJ0j2V7ZM1I0P6vW-PJ4lGzhKb4lPYIAAcUd5x7QAfpO-SOIURPG8tg8tpjFBuEOvQbwmJNfUnd3HCmrZBO3hckRt0MWrIHl1giPa6kXwiTATKxURRtbPoS%7EJ4j4N6-t0OMuu2SGW-01HnoZea5mWeGGgHl95CPqLtURj%7Ea8jzXV4EiS5crufnnR9cawuWNP89znYm6IEx9RqMzx98Z9TykrYqYMYmnwqj6uYtOHg4yy3uwDSBK34vgnMbJao1v19O5VgbS3JLmoRIe9Mi4J2qRv6lBvg__&Key-Pair-Id=K2L8F4GPSG1IFC \"HTTP/1.1 200 OK\"\n",
"2026-01-12 16:56:23,615 - INFO - httpx - HTTP Request: GET https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_dall-e.jpeg \"HTTP/1.1 302 Found\"\n",
"2026-01-12 16:56:24,735 - INFO - httpx - HTTP Request: GET https://cas-bridge.xethub.hf.co/xet-bridge-us/696568e544f950f64beadee8/ff91d58a969691a7959487669bc1856b4ba6d5e485c717a4ac27054a318025e2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=cas%2F20260112%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260112T215623Z&X-Amz-Expires=3600&X-Amz-Signature=3e1b9f863af63325022cc2068b4d466c0e6361d9bfe46dc636f29aa289e4035e&X-Amz-SignedHeaders=host&X-Xet-Cas-Uid=public&response-content-disposition=inline%3B+filename*%3DUTF-8%27%27william_D_dall-e.jpeg%3B+filename%3D%22william_D_dall-e.jpeg%22%3B&response-content-type=image%2Fjpeg&x-id=GetObject&Expires=1768258583&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTc2ODI1ODU4M319LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2FzLWJyaWRnZS54ZXRodWIuaGYuY28veGV0LWJyaWRnZS11cy82OTY1NjhlNTQ0Zjk1MGY2NGJlYWRlZTgvZmY5MWQ1OGE5Njk2OTFhNzk1OTQ4NzY2OWJjMTg1NmI0YmE2ZDVlNDg1YzcxN2E0YWMyNzA1NGEzMTgwMjVlMioifV19&Signature=BNjnqbbXvBeiWjsCXOAJhquB2-1BLXi%7ERpGpNAOWA3JbkAbsLmsaKGT06QsWf66rJZXFrCZjPvOudNdTP57vrB72mQJmxLhhL2H6uzYbeHv99vIXBktuMp4OY9j6jpDrFww9bPILAp4mW-ocoMcg-sl1WNlLRiixHYYV6IfFiSEZtab9yGY3l8RCePbM-zu1p7eamvK41zu51ZAkXg0usDDmAqyATHqAe4fYRq8EersXf1XmWsurm8s7SoQSQd%7Eip77OEnIIlid5tZjaUqKI%7EBQ-8qlRMEKNYWRebLfoxjPhygAMoUPXPQuyAuw%7ETib-e3kQh--SNZUPXefPW4UUyQ__&Key-Pair-Id=K2L8F4GPSG1IFC \"HTTP/1.1 200 OK\"\n",
"2026-01-12 16:56:25,832 - INFO - httpx - HTTP Request: GET https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_gemini.jpg \"HTTP/1.1 302 Found\"\n",
"2026-01-12 16:56:27,016 - INFO - httpx - HTTP Request: GET https://cas-bridge.xethub.hf.co/xet-bridge-us/696568e544f950f64beadee8/70dff9bee8531c0eff0b418f94a014aec586077b2b21f15373d8f571f219fc8f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=cas%2F20260112%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260112T215625Z&X-Amz-Expires=3600&X-Amz-Signature=54877b8e30f9ed49df3d9f61647722e7da6e2154ed51c105acd0342d70b9bc26&X-Amz-SignedHeaders=host&X-Xet-Cas-Uid=public&response-content-disposition=inline%3B+filename*%3DUTF-8%27%27william_D_gemini.jpg%3B+filename%3D%22william_D_gemini.jpg%22%3B&response-content-type=image%2Fjpeg&x-id=GetObject&Expires=1768258585&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTc2ODI1ODU4NX19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2FzLWJyaWRnZS54ZXRodWIuaGYuY28veGV0LWJyaWRnZS11cy82OTY1NjhlNTQ0Zjk1MGY2NGJlYWRlZTgvNzBkZmY5YmVlODUzMWMwZWZmMGI0MThmOTRhMDE0YWVjNTg2MDc3YjJiMjFmMTUzNzNkOGY1NzFmMjE5ZmM4ZioifV19&Signature=hMVJI98tE-NhD67aVZaz1SesKUTDb75Y50zjWwdF87Ij6y9p%7EmhOoOVXGO-xgMl6lIbmOKISTCxRPvIZL4impK17txRsoaSra6NXC789TmARC2yweDEeTeiRwqbtVNDki4mOIzsudCtv-5wEvjZvjRTOSEQCk5PrKTpBazuvDunB4%7EUAYWHuqnx8yT9S11JmB1qONr45sFRqTlVlT1ghwV-YFZv4OcY45Rw6cZh5O%7EQn6gCaDmcCxgIRiYXYU8gidYvp3XDP451j4h00alnj2HYEMjsfJ20kkWIyxANLrQs5eztiezhAnvFJdTe%7Ee2wsVjRIPJIRUXsGrQMMkNX0GA__&Key-Pair-Id=K2L8F4GPSG1IFC \"HTTP/1.1 200 OK\"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7861\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-01-12 16:56:28,484 - INFO - httpx - HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events \"HTTP/1.1 200 OK\"\n",
"2026-01-12 16:56:28,498 - INFO - httpx - HTTP Request: HEAD http://127.0.0.1:7861/ \"HTTP/1.1 200 OK\"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2026-01-12 16:56:28,615 - INFO - httpx - HTTP Request: HEAD https://huggingface.co/api/telemetry/https%3A/api.gradio.app/gradio-launched-telemetry \"HTTP/1.1 200 OK\"\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#|export\n",
"interface = gr.Interface(fn=classify_image, inputs=gr.Image(type=\"pil\", image_mode=\"RGB\"), \n",
" outputs=gr.Label(),\n",
" examples=[\"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D.jpeg\", \n",
" \"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_dall-e.jpeg\",\n",
" \"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_gemini.jpg\"],\n",
" cache_examples=False,\n",
" title=\"AI or Not AI Image Classifier\",\n",
" description=\"Upload an image to determine if it is AI generated or not.\")\n",
"interface.launch(inline=True)"
]
},
{
"cell_type": "markdown",
"id": "037d94b1",
"metadata": {},
"source": [
"Finally I'm writting a scrip that will export a cell is it contains #|export. Originally I was going to use nbdev just like the lesson, but nbdev wasn't really working so I imporvise using what I already laid out.\n",
"\n",
"First I made sure I had the lastest version of fastcore is a versatile library that includes json, re, and pathlib. JSON package lets me write a JSON script, that will open app.py, and iterate through everycell. If a cell contains #|export then that cell will get appended into a list of cells. Then pathlib will let us write these cells into app.py "
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "8f808c25",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found existing installation: fastcore 1.11.3\n",
"Uninstalling fastcore-1.11.3:\n",
" Successfully uninstalled fastcore-1.11.3\n",
"Collecting fastcore\n",
" Using cached fastcore-1.11.3-py3-none-any.whl.metadata (3.7 kB)\n",
"Requirement already satisfied: packaging in c:\\users\\holyw\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (from fastcore) (25.0)\n",
"Using cached fastcore-1.11.3-py3-none-any.whl (89 kB)\n",
"Installing collected packages: fastcore\n",
"Successfully installed fastcore-1.11.3\n"
]
}
],
"source": [
"!pip uninstall fastcore -y\n",
"!pip install fastcore"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c9b230fd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Exported app.py\n"
]
}
],
"source": [
"# Export only cells marked with \"#|export\"\n",
"import json, re, pathlib\n",
"\n",
"nb = json.load(open(\"app.ipynb\", \"r\", encoding=\"utf-8\"))\n",
"out = []\n",
"\n",
"for cell in nb[\"cells\"]:\n",
" if cell[\"cell_type\"] == \"code\":\n",
" src = \"\".join(cell[\"source\"])\n",
" if re.search(r\"^#\\|export\", src, re.M):\n",
" out.append(src.replace(\"#|export\", \"\").strip() + \"\\n\\n\")\n",
"\n",
"pathlib.Path(\"app.py\").write_text(\"\".join(out), encoding=\"utf-8\")\n",
"\n",
"print(\"Exported app.py\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|