brawl7787 commited on
Commit ·
2d2db50
0
Parent(s):
Initial clean commit with LFS
Browse files- .gitattributes +36 -0
- README.md +12 -0
- ToAI.pk1 +3 -0
- app.ipynb +821 -0
- app.py +57 -0
- requirements.txt +13 -0
- toai.bin +3 -0
- will_smithAI.jpg +0 -0
- will_smithMaybe.webp +0 -0
- will_smithReal.jpeg +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.pk1 filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AIorNot
|
| 3 |
+
emoji: 😻
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.2.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.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|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "e6520fa6",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"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."
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "markdown",
|
| 13 |
+
"id": "92cd1441",
|
| 14 |
+
"metadata": {},
|
| 15 |
+
"source": [
|
| 16 |
+
"this will set the default module name, so that any exported functions or classes will go into a file called app.py"
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"cell_type": "code",
|
| 21 |
+
"execution_count": 14,
|
| 22 |
+
"id": "b47015bb",
|
| 23 |
+
"metadata": {},
|
| 24 |
+
"outputs": [],
|
| 25 |
+
"source": [
|
| 26 |
+
"#|default_exp app"
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"cell_type": "code",
|
| 31 |
+
"execution_count": 8,
|
| 32 |
+
"id": "e454e29a",
|
| 33 |
+
"metadata": {},
|
| 34 |
+
"outputs": [
|
| 35 |
+
{
|
| 36 |
+
"name": "stdout",
|
| 37 |
+
"output_type": "stream",
|
| 38 |
+
"text": [
|
| 39 |
+
"c:\\Users\\holyw\\AppData\\Local\\Programs\\Python\\Python311\\python.exe\n"
|
| 40 |
+
]
|
| 41 |
+
}
|
| 42 |
+
],
|
| 43 |
+
"source": [
|
| 44 |
+
"import sys\n",
|
| 45 |
+
"print(sys.executable)"
|
| 46 |
+
]
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"cell_type": "markdown",
|
| 50 |
+
"id": "54d1eae5",
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"source": [
|
| 53 |
+
"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."
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"cell_type": "code",
|
| 58 |
+
"execution_count": 9,
|
| 59 |
+
"id": "6049aced",
|
| 60 |
+
"metadata": {},
|
| 61 |
+
"outputs": [
|
| 62 |
+
{
|
| 63 |
+
"name": "stdout",
|
| 64 |
+
"output_type": "stream",
|
| 65 |
+
"text": [
|
| 66 |
+
"Requirement already satisfied: fastai in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (2.7.14)\n",
|
| 67 |
+
"Requirement already satisfied: gradio in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (6.2.0)\n",
|
| 68 |
+
"Requirement already satisfied: icrawler in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.6.10)\n",
|
| 69 |
+
"Requirement already satisfied: pip in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (23.2.1)\n",
|
| 70 |
+
"Requirement already satisfied: packaging in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from fastai) (25.0)\n",
|
| 71 |
+
"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",
|
| 72 |
+
"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",
|
| 73 |
+
"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",
|
| 74 |
+
"Requirement already satisfied: matplotlib in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (3.10.8)\n",
|
| 75 |
+
"Requirement already satisfied: pandas in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (2.3.3)\n",
|
| 76 |
+
"Requirement already satisfied: requests in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (2.32.5)\n",
|
| 77 |
+
"Requirement already satisfied: pyyaml in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (6.0.3)\n",
|
| 78 |
+
"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",
|
| 79 |
+
"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",
|
| 80 |
+
"Requirement already satisfied: scikit-learn in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (1.8.0)\n",
|
| 81 |
+
"Requirement already satisfied: scipy in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (1.16.3)\n",
|
| 82 |
+
"Requirement already satisfied: spacy<4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastai) (3.8.11)\n",
|
| 83 |
+
"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",
|
| 84 |
+
"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",
|
| 85 |
+
"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",
|
| 86 |
+
"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",
|
| 87 |
+
"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",
|
| 88 |
+
"Requirement already satisfied: ffmpy in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (1.0.0)\n",
|
| 89 |
+
"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",
|
| 90 |
+
"Requirement already satisfied: groovy~=0.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.1.2)\n",
|
| 91 |
+
"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",
|
| 92 |
+
"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",
|
| 93 |
+
"Requirement already satisfied: jinja2<4.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (3.1.6)\n",
|
| 94 |
+
"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",
|
| 95 |
+
"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",
|
| 96 |
+
"Requirement already satisfied: orjson~=3.0 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (3.11.5)\n",
|
| 97 |
+
"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",
|
| 98 |
+
"Requirement already satisfied: pydub in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from gradio) (0.25.1)\n",
|
| 99 |
+
"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",
|
| 100 |
+
"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",
|
| 101 |
+
"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",
|
| 102 |
+
"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",
|
| 103 |
+
"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",
|
| 104 |
+
"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",
|
| 105 |
+
"Requirement already satisfied: typing-extensions~=4.0 in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from gradio) (4.15.0)\n",
|
| 106 |
+
"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",
|
| 107 |
+
"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",
|
| 108 |
+
"Requirement already satisfied: beautifulsoup4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from icrawler) (4.14.3)\n",
|
| 109 |
+
"Requirement already satisfied: bs4 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from icrawler) (0.0.2)\n",
|
| 110 |
+
"Requirement already satisfied: lxml in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from icrawler) (6.0.2)\n",
|
| 111 |
+
"Requirement already satisfied: six in c:\\users\\holyw\\appdata\\roaming\\python\\python311\\site-packages (from icrawler) (1.17.0)\n",
|
| 112 |
+
"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",
|
| 113 |
+
"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",
|
| 114 |
+
"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",
|
| 115 |
+
"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",
|
| 116 |
+
"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",
|
| 117 |
+
"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",
|
| 118 |
+
"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",
|
| 119 |
+
"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",
|
| 120 |
+
"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",
|
| 121 |
+
"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",
|
| 122 |
+
"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",
|
| 123 |
+
"Requirement already satisfied: pytz>=2020.1 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pandas->fastai) (2025.2)\n",
|
| 124 |
+
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pandas->fastai) (2025.3)\n",
|
| 125 |
+
"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",
|
| 126 |
+
"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",
|
| 127 |
+
"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",
|
| 128 |
+
"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",
|
| 129 |
+
"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",
|
| 130 |
+
"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",
|
| 131 |
+
"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",
|
| 132 |
+
"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",
|
| 133 |
+
"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",
|
| 134 |
+
"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",
|
| 135 |
+
"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",
|
| 136 |
+
"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",
|
| 137 |
+
"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",
|
| 138 |
+
"Requirement already satisfied: setuptools in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4->fastai) (65.5.0)\n",
|
| 139 |
+
"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",
|
| 140 |
+
"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",
|
| 141 |
+
"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",
|
| 142 |
+
"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",
|
| 143 |
+
"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",
|
| 144 |
+
"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",
|
| 145 |
+
"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",
|
| 146 |
+
"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",
|
| 147 |
+
"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",
|
| 148 |
+
"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",
|
| 149 |
+
"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",
|
| 150 |
+
"Requirement already satisfied: pyparsing>=3 in c:\\users\\holyw\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib->fastai) (3.3.1)\n",
|
| 151 |
+
"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",
|
| 152 |
+
"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",
|
| 153 |
+
"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",
|
| 154 |
+
"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",
|
| 155 |
+
"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",
|
| 156 |
+
"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",
|
| 157 |
+
"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",
|
| 158 |
+
"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",
|
| 159 |
+
"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",
|
| 160 |
+
"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",
|
| 161 |
+
"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",
|
| 162 |
+
"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"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"name": "stderr",
|
| 167 |
+
"output_type": "stream",
|
| 168 |
+
"text": [
|
| 169 |
+
"\n",
|
| 170 |
+
"[notice] A new release of pip is available: 23.2.1 -> 25.3\n",
|
| 171 |
+
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
|
| 172 |
+
]
|
| 173 |
+
}
|
| 174 |
+
],
|
| 175 |
+
"source": [
|
| 176 |
+
"import sys\n",
|
| 177 |
+
"!{sys.executable} -m pip install fastai gradio icrawler\n"
|
| 178 |
+
]
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"cell_type": "code",
|
| 182 |
+
"execution_count": 10,
|
| 183 |
+
"id": "0033302b",
|
| 184 |
+
"metadata": {},
|
| 185 |
+
"outputs": [],
|
| 186 |
+
"source": [
|
| 187 |
+
"#|export\n",
|
| 188 |
+
"from fastai.vision.all import load_learner"
|
| 189 |
+
]
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"cell_type": "code",
|
| 193 |
+
"execution_count": 11,
|
| 194 |
+
"id": "6571ebb8",
|
| 195 |
+
"metadata": {},
|
| 196 |
+
"outputs": [],
|
| 197 |
+
"source": [
|
| 198 |
+
"#|export\n",
|
| 199 |
+
"import gradio as gr"
|
| 200 |
+
]
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"cell_type": "markdown",
|
| 204 |
+
"id": "2bcd5faa",
|
| 205 |
+
"metadata": {},
|
| 206 |
+
"source": [
|
| 207 |
+
"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."
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"cell_type": "code",
|
| 212 |
+
"execution_count": null,
|
| 213 |
+
"id": "1bb0d81a",
|
| 214 |
+
"metadata": {},
|
| 215 |
+
"outputs": [
|
| 216 |
+
{
|
| 217 |
+
"name": "stderr",
|
| 218 |
+
"output_type": "stream",
|
| 219 |
+
"text": [
|
| 220 |
+
"2026-01-12 16:51:08,982 - INFO - icrawler.crawler - start crawling...\n",
|
| 221 |
+
"2026-01-12 16:51:08,996 - INFO - icrawler.crawler - starting 1 feeder threads...\n",
|
| 222 |
+
"2026-01-12 16:51:08,997 - INFO - feeder - thread feeder-001 exit\n",
|
| 223 |
+
"2026-01-12 16:51:09,015 - INFO - icrawler.crawler - starting 1 parser threads...\n",
|
| 224 |
+
"2026-01-12 16:51:09,031 - INFO - icrawler.crawler - starting 1 downloader threads...\n",
|
| 225 |
+
"2026-01-12 16:51:10,482 - INFO - parser - parsing result page https://www.bing.com/images/async?q=guayaquill&first=0\n",
|
| 226 |
+
"2026-01-12 16:51:12,130 - INFO - downloader - image #1\thttps://pic3.zhimg.com/v2-08529379c3b246bd4a36008ec9c1312a_r.jpg\n",
|
| 227 |
+
"2026-01-12 16:51:13,184 - INFO - downloader - downloaded images reach max num, thread downloader-001 is ready to exit\n",
|
| 228 |
+
"2026-01-12 16:51:13,184 - INFO - downloader - thread downloader-001 exit\n",
|
| 229 |
+
"2026-01-12 16:51:14,041 - INFO - icrawler.crawler - Crawling task done!\n"
|
| 230 |
+
]
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"name": "stderr",
|
| 234 |
+
"output_type": "stream",
|
| 235 |
+
"text": [
|
| 236 |
+
"2026-01-12 16:51:14,626 - INFO - parser - downloaded image reached max num, thread parser-001 is ready to exit\n",
|
| 237 |
+
"2026-01-12 16:51:14,630 - INFO - parser - thread parser-001 exit\n"
|
| 238 |
+
]
|
| 239 |
+
}
|
| 240 |
+
],
|
| 241 |
+
"source": [
|
| 242 |
+
"from icrawler.builtin import BingImageCrawler\n",
|
| 243 |
+
"crawler = BingImageCrawler()\n",
|
| 244 |
+
"crawler.crawl(keyword='guayaquill', max_num=1)"
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"cell_type": "markdown",
|
| 249 |
+
"id": "371034dd",
|
| 250 |
+
"metadata": {},
|
| 251 |
+
"source": [
|
| 252 |
+
"Now we load the model in our files that was exported from another project"
|
| 253 |
+
]
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"cell_type": "code",
|
| 257 |
+
"execution_count": 13,
|
| 258 |
+
"id": "1ff86656",
|
| 259 |
+
"metadata": {},
|
| 260 |
+
"outputs": [
|
| 261 |
+
{
|
| 262 |
+
"data": {
|
| 263 |
+
"text/plain": [
|
| 264 |
+
"Sequential(\n",
|
| 265 |
+
" (0): Sequential(\n",
|
| 266 |
+
" (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)\n",
|
| 267 |
+
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 268 |
+
" (2): ReLU(inplace=True)\n",
|
| 269 |
+
" (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)\n",
|
| 270 |
+
" (4): Sequential(\n",
|
| 271 |
+
" (0): BasicBlock(\n",
|
| 272 |
+
" (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 273 |
+
" (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 274 |
+
" (relu): ReLU(inplace=True)\n",
|
| 275 |
+
" (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 276 |
+
" (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 277 |
+
" )\n",
|
| 278 |
+
" (1): BasicBlock(\n",
|
| 279 |
+
" (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 280 |
+
" (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 281 |
+
" (relu): ReLU(inplace=True)\n",
|
| 282 |
+
" (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 283 |
+
" (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 284 |
+
" )\n",
|
| 285 |
+
" )\n",
|
| 286 |
+
" (5): Sequential(\n",
|
| 287 |
+
" (0): BasicBlock(\n",
|
| 288 |
+
" (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
|
| 289 |
+
" (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 290 |
+
" (relu): ReLU(inplace=True)\n",
|
| 291 |
+
" (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 292 |
+
" (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 293 |
+
" (downsample): Sequential(\n",
|
| 294 |
+
" (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
|
| 295 |
+
" (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 296 |
+
" )\n",
|
| 297 |
+
" )\n",
|
| 298 |
+
" (1): BasicBlock(\n",
|
| 299 |
+
" (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 300 |
+
" (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 301 |
+
" (relu): ReLU(inplace=True)\n",
|
| 302 |
+
" (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 303 |
+
" (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 304 |
+
" )\n",
|
| 305 |
+
" )\n",
|
| 306 |
+
" (6): Sequential(\n",
|
| 307 |
+
" (0): BasicBlock(\n",
|
| 308 |
+
" (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
|
| 309 |
+
" (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 310 |
+
" (relu): ReLU(inplace=True)\n",
|
| 311 |
+
" (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 312 |
+
" (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 313 |
+
" (downsample): Sequential(\n",
|
| 314 |
+
" (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
|
| 315 |
+
" (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 316 |
+
" )\n",
|
| 317 |
+
" )\n",
|
| 318 |
+
" (1): BasicBlock(\n",
|
| 319 |
+
" (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 320 |
+
" (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 321 |
+
" (relu): ReLU(inplace=True)\n",
|
| 322 |
+
" (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 323 |
+
" (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 324 |
+
" )\n",
|
| 325 |
+
" )\n",
|
| 326 |
+
" (7): Sequential(\n",
|
| 327 |
+
" (0): BasicBlock(\n",
|
| 328 |
+
" (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)\n",
|
| 329 |
+
" (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 330 |
+
" (relu): ReLU(inplace=True)\n",
|
| 331 |
+
" (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 332 |
+
" (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 333 |
+
" (downsample): Sequential(\n",
|
| 334 |
+
" (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)\n",
|
| 335 |
+
" (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 336 |
+
" )\n",
|
| 337 |
+
" )\n",
|
| 338 |
+
" (1): BasicBlock(\n",
|
| 339 |
+
" (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 340 |
+
" (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 341 |
+
" (relu): ReLU(inplace=True)\n",
|
| 342 |
+
" (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
|
| 343 |
+
" (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 344 |
+
" )\n",
|
| 345 |
+
" )\n",
|
| 346 |
+
" )\n",
|
| 347 |
+
" (1): Sequential(\n",
|
| 348 |
+
" (0): AdaptiveConcatPool2d(\n",
|
| 349 |
+
" (ap): AdaptiveAvgPool2d(output_size=1)\n",
|
| 350 |
+
" (mp): AdaptiveMaxPool2d(output_size=1)\n",
|
| 351 |
+
" )\n",
|
| 352 |
+
" (1): fastai.layers.Flatten(full=False)\n",
|
| 353 |
+
" (2): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 354 |
+
" (3): Dropout(p=0.25, inplace=False)\n",
|
| 355 |
+
" (4): Linear(in_features=1024, out_features=512, bias=False)\n",
|
| 356 |
+
" (5): ReLU(inplace=True)\n",
|
| 357 |
+
" (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
|
| 358 |
+
" (7): Dropout(p=0.5, inplace=False)\n",
|
| 359 |
+
" (8): Linear(in_features=512, out_features=2, bias=False)\n",
|
| 360 |
+
" )\n",
|
| 361 |
+
")"
|
| 362 |
+
]
|
| 363 |
+
},
|
| 364 |
+
"execution_count": 13,
|
| 365 |
+
"metadata": {},
|
| 366 |
+
"output_type": "execute_result"
|
| 367 |
+
}
|
| 368 |
+
],
|
| 369 |
+
"source": [
|
| 370 |
+
"#|export\n",
|
| 371 |
+
"from fastai.vision.all import *\n",
|
| 372 |
+
"import numpy as np\n",
|
| 373 |
+
"import torch\n",
|
| 374 |
+
"\n",
|
| 375 |
+
"dummy_img = PILImage.create(np.zeros((224,224,3), dtype=np.uint8))\n",
|
| 376 |
+
"\n",
|
| 377 |
+
"dblock = DataBlock(\n",
|
| 378 |
+
" blocks=(ImageBlock, CategoryBlock(vocab=['class_0', 'class_1'])),\n",
|
| 379 |
+
" get_items=lambda _: [dummy_img],\n",
|
| 380 |
+
" get_y=lambda _: 'class_0',\n",
|
| 381 |
+
" item_tfms=Resize(224)\n",
|
| 382 |
+
")\n",
|
| 383 |
+
"\n",
|
| 384 |
+
"dls = dblock.dataloaders(source=None, bs=1, device='cpu')\n",
|
| 385 |
+
"\n",
|
| 386 |
+
"learn = vision_learner(\n",
|
| 387 |
+
" dls,\n",
|
| 388 |
+
" resnet18,\n",
|
| 389 |
+
" n_out=2,\n",
|
| 390 |
+
" pretrained=False,\n",
|
| 391 |
+
" normalize=False\n",
|
| 392 |
+
")\n",
|
| 393 |
+
"\n",
|
| 394 |
+
"learn.model.load_state_dict(\n",
|
| 395 |
+
" torch.load(\"toai.bin\", map_location=\"cpu\")\n",
|
| 396 |
+
")\n",
|
| 397 |
+
"\n",
|
| 398 |
+
"learn.model.eval()\n"
|
| 399 |
+
]
|
| 400 |
+
},
|
| 401 |
+
{
|
| 402 |
+
"cell_type": "code",
|
| 403 |
+
"execution_count": 14,
|
| 404 |
+
"id": "0867517f",
|
| 405 |
+
"metadata": {},
|
| 406 |
+
"outputs": [
|
| 407 |
+
{
|
| 408 |
+
"data": {
|
| 409 |
+
"text/plain": [
|
| 410 |
+
"<All keys matched successfully>"
|
| 411 |
+
]
|
| 412 |
+
},
|
| 413 |
+
"execution_count": 14,
|
| 414 |
+
"metadata": {},
|
| 415 |
+
"output_type": "execute_result"
|
| 416 |
+
}
|
| 417 |
+
],
|
| 418 |
+
"source": [
|
| 419 |
+
"state_dict = torch.load('toai.bin', map_location='cpu')\n",
|
| 420 |
+
"learn.model.load_state_dict(state_dict)"
|
| 421 |
+
]
|
| 422 |
+
},
|
| 423 |
+
{
|
| 424 |
+
"cell_type": "markdown",
|
| 425 |
+
"id": "55673fd4",
|
| 426 |
+
"metadata": {},
|
| 427 |
+
"source": [
|
| 428 |
+
"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."
|
| 429 |
+
]
|
| 430 |
+
},
|
| 431 |
+
{
|
| 432 |
+
"cell_type": "code",
|
| 433 |
+
"execution_count": 15,
|
| 434 |
+
"id": "d228b33f",
|
| 435 |
+
"metadata": {},
|
| 436 |
+
"outputs": [],
|
| 437 |
+
"source": [
|
| 438 |
+
"#|export\n",
|
| 439 |
+
"from fastai.vision.all import PILImage\n",
|
| 440 |
+
"from PIL import Image\n",
|
| 441 |
+
"import requests\n",
|
| 442 |
+
"from io import BytesIO\n",
|
| 443 |
+
"\n",
|
| 444 |
+
"categories = ['AI Generated', 'Not AI Generated']\n",
|
| 445 |
+
"\n",
|
| 446 |
+
"def classify_image(img):\n",
|
| 447 |
+
"\n",
|
| 448 |
+
" fastai_img = PILImage.create(img)\n",
|
| 449 |
+
" pred, pred_idx, probs = learn.predict(fastai_img)\n",
|
| 450 |
+
"\n",
|
| 451 |
+
" return dict(zip(categories, map(float, probs)))"
|
| 452 |
+
]
|
| 453 |
+
},
|
| 454 |
+
{
|
| 455 |
+
"cell_type": "markdown",
|
| 456 |
+
"id": "54ef7eb7",
|
| 457 |
+
"metadata": {},
|
| 458 |
+
"source": [
|
| 459 |
+
"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."
|
| 460 |
+
]
|
| 461 |
+
},
|
| 462 |
+
{
|
| 463 |
+
"cell_type": "code",
|
| 464 |
+
"execution_count": null,
|
| 465 |
+
"id": "aec9f6e4",
|
| 466 |
+
"metadata": {},
|
| 467 |
+
"outputs": [
|
| 468 |
+
{
|
| 469 |
+
"name": "stderr",
|
| 470 |
+
"output_type": "stream",
|
| 471 |
+
"text": [
|
| 472 |
+
"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",
|
| 473 |
+
"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",
|
| 474 |
+
"2026-01-12 16:56:21,314 - INFO - httpx - HTTP Request: GET https://api.gradio.app/pkg-version \"HTTP/1.1 200 OK\"\n",
|
| 475 |
+
"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",
|
| 476 |
+
"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",
|
| 477 |
+
"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",
|
| 478 |
+
"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",
|
| 479 |
+
"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"
|
| 480 |
+
]
|
| 481 |
+
},
|
| 482 |
+
{
|
| 483 |
+
"name": "stdout",
|
| 484 |
+
"output_type": "stream",
|
| 485 |
+
"text": [
|
| 486 |
+
"* Running on local URL: http://127.0.0.1:7861\n"
|
| 487 |
+
]
|
| 488 |
+
},
|
| 489 |
+
{
|
| 490 |
+
"name": "stderr",
|
| 491 |
+
"output_type": "stream",
|
| 492 |
+
"text": [
|
| 493 |
+
"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",
|
| 494 |
+
"2026-01-12 16:56:28,498 - INFO - httpx - HTTP Request: HEAD http://127.0.0.1:7861/ \"HTTP/1.1 200 OK\"\n"
|
| 495 |
+
]
|
| 496 |
+
},
|
| 497 |
+
{
|
| 498 |
+
"name": "stdout",
|
| 499 |
+
"output_type": "stream",
|
| 500 |
+
"text": [
|
| 501 |
+
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 502 |
+
]
|
| 503 |
+
},
|
| 504 |
+
{
|
| 505 |
+
"data": {
|
| 506 |
+
"text/html": [
|
| 507 |
+
"<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>"
|
| 508 |
+
],
|
| 509 |
+
"text/plain": [
|
| 510 |
+
"<IPython.core.display.HTML object>"
|
| 511 |
+
]
|
| 512 |
+
},
|
| 513 |
+
"metadata": {},
|
| 514 |
+
"output_type": "display_data"
|
| 515 |
+
},
|
| 516 |
+
{
|
| 517 |
+
"data": {
|
| 518 |
+
"text/plain": []
|
| 519 |
+
},
|
| 520 |
+
"execution_count": 17,
|
| 521 |
+
"metadata": {},
|
| 522 |
+
"output_type": "execute_result"
|
| 523 |
+
},
|
| 524 |
+
{
|
| 525 |
+
"name": "stderr",
|
| 526 |
+
"output_type": "stream",
|
| 527 |
+
"text": [
|
| 528 |
+
"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"
|
| 529 |
+
]
|
| 530 |
+
},
|
| 531 |
+
{
|
| 532 |
+
"data": {
|
| 533 |
+
"text/html": [
|
| 534 |
+
"\n",
|
| 535 |
+
"<style>\n",
|
| 536 |
+
" /* Turns off some styling */\n",
|
| 537 |
+
" progress {\n",
|
| 538 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 539 |
+
" border: none;\n",
|
| 540 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 541 |
+
" background-size: auto;\n",
|
| 542 |
+
" }\n",
|
| 543 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 544 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 545 |
+
" }\n",
|
| 546 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 547 |
+
" background: #F44336;\n",
|
| 548 |
+
" }\n",
|
| 549 |
+
"</style>\n"
|
| 550 |
+
],
|
| 551 |
+
"text/plain": [
|
| 552 |
+
"<IPython.core.display.HTML object>"
|
| 553 |
+
]
|
| 554 |
+
},
|
| 555 |
+
"metadata": {},
|
| 556 |
+
"output_type": "display_data"
|
| 557 |
+
},
|
| 558 |
+
{
|
| 559 |
+
"data": {
|
| 560 |
+
"text/html": [],
|
| 561 |
+
"text/plain": [
|
| 562 |
+
"<IPython.core.display.HTML object>"
|
| 563 |
+
]
|
| 564 |
+
},
|
| 565 |
+
"metadata": {},
|
| 566 |
+
"output_type": "display_data"
|
| 567 |
+
},
|
| 568 |
+
{
|
| 569 |
+
"data": {
|
| 570 |
+
"text/html": [
|
| 571 |
+
"\n",
|
| 572 |
+
"<style>\n",
|
| 573 |
+
" /* Turns off some styling */\n",
|
| 574 |
+
" progress {\n",
|
| 575 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 576 |
+
" border: none;\n",
|
| 577 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 578 |
+
" background-size: auto;\n",
|
| 579 |
+
" }\n",
|
| 580 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 581 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 582 |
+
" }\n",
|
| 583 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 584 |
+
" background: #F44336;\n",
|
| 585 |
+
" }\n",
|
| 586 |
+
"</style>\n"
|
| 587 |
+
],
|
| 588 |
+
"text/plain": [
|
| 589 |
+
"<IPython.core.display.HTML object>"
|
| 590 |
+
]
|
| 591 |
+
},
|
| 592 |
+
"metadata": {},
|
| 593 |
+
"output_type": "display_data"
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"data": {
|
| 597 |
+
"text/html": [],
|
| 598 |
+
"text/plain": [
|
| 599 |
+
"<IPython.core.display.HTML object>"
|
| 600 |
+
]
|
| 601 |
+
},
|
| 602 |
+
"metadata": {},
|
| 603 |
+
"output_type": "display_data"
|
| 604 |
+
},
|
| 605 |
+
{
|
| 606 |
+
"data": {
|
| 607 |
+
"text/html": [
|
| 608 |
+
"\n",
|
| 609 |
+
"<style>\n",
|
| 610 |
+
" /* Turns off some styling */\n",
|
| 611 |
+
" progress {\n",
|
| 612 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 613 |
+
" border: none;\n",
|
| 614 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 615 |
+
" background-size: auto;\n",
|
| 616 |
+
" }\n",
|
| 617 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 618 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 619 |
+
" }\n",
|
| 620 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 621 |
+
" background: #F44336;\n",
|
| 622 |
+
" }\n",
|
| 623 |
+
"</style>\n"
|
| 624 |
+
],
|
| 625 |
+
"text/plain": [
|
| 626 |
+
"<IPython.core.display.HTML object>"
|
| 627 |
+
]
|
| 628 |
+
},
|
| 629 |
+
"metadata": {},
|
| 630 |
+
"output_type": "display_data"
|
| 631 |
+
},
|
| 632 |
+
{
|
| 633 |
+
"data": {
|
| 634 |
+
"text/html": [],
|
| 635 |
+
"text/plain": [
|
| 636 |
+
"<IPython.core.display.HTML object>"
|
| 637 |
+
]
|
| 638 |
+
},
|
| 639 |
+
"metadata": {},
|
| 640 |
+
"output_type": "display_data"
|
| 641 |
+
},
|
| 642 |
+
{
|
| 643 |
+
"data": {
|
| 644 |
+
"text/html": [
|
| 645 |
+
"\n",
|
| 646 |
+
"<style>\n",
|
| 647 |
+
" /* Turns off some styling */\n",
|
| 648 |
+
" progress {\n",
|
| 649 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 650 |
+
" border: none;\n",
|
| 651 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 652 |
+
" background-size: auto;\n",
|
| 653 |
+
" }\n",
|
| 654 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 655 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 656 |
+
" }\n",
|
| 657 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 658 |
+
" background: #F44336;\n",
|
| 659 |
+
" }\n",
|
| 660 |
+
"</style>\n"
|
| 661 |
+
],
|
| 662 |
+
"text/plain": [
|
| 663 |
+
"<IPython.core.display.HTML object>"
|
| 664 |
+
]
|
| 665 |
+
},
|
| 666 |
+
"metadata": {},
|
| 667 |
+
"output_type": "display_data"
|
| 668 |
+
},
|
| 669 |
+
{
|
| 670 |
+
"data": {
|
| 671 |
+
"text/html": [],
|
| 672 |
+
"text/plain": [
|
| 673 |
+
"<IPython.core.display.HTML object>"
|
| 674 |
+
]
|
| 675 |
+
},
|
| 676 |
+
"metadata": {},
|
| 677 |
+
"output_type": "display_data"
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"data": {
|
| 681 |
+
"text/html": [
|
| 682 |
+
"\n",
|
| 683 |
+
"<style>\n",
|
| 684 |
+
" /* Turns off some styling */\n",
|
| 685 |
+
" progress {\n",
|
| 686 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 687 |
+
" border: none;\n",
|
| 688 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 689 |
+
" background-size: auto;\n",
|
| 690 |
+
" }\n",
|
| 691 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 692 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 693 |
+
" }\n",
|
| 694 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 695 |
+
" background: #F44336;\n",
|
| 696 |
+
" }\n",
|
| 697 |
+
"</style>\n"
|
| 698 |
+
],
|
| 699 |
+
"text/plain": [
|
| 700 |
+
"<IPython.core.display.HTML object>"
|
| 701 |
+
]
|
| 702 |
+
},
|
| 703 |
+
"metadata": {},
|
| 704 |
+
"output_type": "display_data"
|
| 705 |
+
},
|
| 706 |
+
{
|
| 707 |
+
"data": {
|
| 708 |
+
"text/html": [],
|
| 709 |
+
"text/plain": [
|
| 710 |
+
"<IPython.core.display.HTML object>"
|
| 711 |
+
]
|
| 712 |
+
},
|
| 713 |
+
"metadata": {},
|
| 714 |
+
"output_type": "display_data"
|
| 715 |
+
}
|
| 716 |
+
],
|
| 717 |
+
"source": [
|
| 718 |
+
"#|export\n",
|
| 719 |
+
"interface = gr.Interface(fn=classify_image, inputs=gr.Image(type=\"pil\", image_mode=\"RGB\"), \n",
|
| 720 |
+
" outputs=gr.Label(),\n",
|
| 721 |
+
" examples=[\"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D.jpeg\", \n",
|
| 722 |
+
" \"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_dall-e.jpeg\",\n",
|
| 723 |
+
" \"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_gemini.jpg\"],\n",
|
| 724 |
+
" cache_examples=False,\n",
|
| 725 |
+
" title=\"AI or Not AI Image Classifier\",\n",
|
| 726 |
+
" description=\"Upload an image to determine if it is AI generated or not.\")\n",
|
| 727 |
+
"interface.launch(inline=True)"
|
| 728 |
+
]
|
| 729 |
+
},
|
| 730 |
+
{
|
| 731 |
+
"cell_type": "markdown",
|
| 732 |
+
"id": "037d94b1",
|
| 733 |
+
"metadata": {},
|
| 734 |
+
"source": [
|
| 735 |
+
"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",
|
| 736 |
+
"\n",
|
| 737 |
+
"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 "
|
| 738 |
+
]
|
| 739 |
+
},
|
| 740 |
+
{
|
| 741 |
+
"cell_type": "code",
|
| 742 |
+
"execution_count": 18,
|
| 743 |
+
"id": "8f808c25",
|
| 744 |
+
"metadata": {},
|
| 745 |
+
"outputs": [
|
| 746 |
+
{
|
| 747 |
+
"name": "stdout",
|
| 748 |
+
"output_type": "stream",
|
| 749 |
+
"text": [
|
| 750 |
+
"Found existing installation: fastcore 1.11.3\n",
|
| 751 |
+
"Uninstalling fastcore-1.11.3:\n",
|
| 752 |
+
" Successfully uninstalled fastcore-1.11.3\n",
|
| 753 |
+
"Collecting fastcore\n",
|
| 754 |
+
" Using cached fastcore-1.11.3-py3-none-any.whl.metadata (3.7 kB)\n",
|
| 755 |
+
"Requirement already satisfied: packaging in c:\\users\\holyw\\appdata\\local\\programs\\python\\python313\\lib\\site-packages (from fastcore) (25.0)\n",
|
| 756 |
+
"Using cached fastcore-1.11.3-py3-none-any.whl (89 kB)\n",
|
| 757 |
+
"Installing collected packages: fastcore\n",
|
| 758 |
+
"Successfully installed fastcore-1.11.3\n"
|
| 759 |
+
]
|
| 760 |
+
}
|
| 761 |
+
],
|
| 762 |
+
"source": [
|
| 763 |
+
"!pip uninstall fastcore -y\n",
|
| 764 |
+
"!pip install fastcore"
|
| 765 |
+
]
|
| 766 |
+
},
|
| 767 |
+
{
|
| 768 |
+
"cell_type": "code",
|
| 769 |
+
"execution_count": 19,
|
| 770 |
+
"id": "c9b230fd",
|
| 771 |
+
"metadata": {},
|
| 772 |
+
"outputs": [
|
| 773 |
+
{
|
| 774 |
+
"name": "stdout",
|
| 775 |
+
"output_type": "stream",
|
| 776 |
+
"text": [
|
| 777 |
+
"Exported app.py\n"
|
| 778 |
+
]
|
| 779 |
+
}
|
| 780 |
+
],
|
| 781 |
+
"source": [
|
| 782 |
+
"# Export only cells marked with \"#|export\"\n",
|
| 783 |
+
"import json, re, pathlib\n",
|
| 784 |
+
"\n",
|
| 785 |
+
"nb = json.load(open(\"app.ipynb\", \"r\", encoding=\"utf-8\"))\n",
|
| 786 |
+
"out = []\n",
|
| 787 |
+
"\n",
|
| 788 |
+
"for cell in nb[\"cells\"]:\n",
|
| 789 |
+
" if cell[\"cell_type\"] == \"code\":\n",
|
| 790 |
+
" src = \"\".join(cell[\"source\"])\n",
|
| 791 |
+
" if re.search(r\"^#\\|export\", src, re.M):\n",
|
| 792 |
+
" out.append(src.replace(\"#|export\", \"\").strip() + \"\\n\\n\")\n",
|
| 793 |
+
"\n",
|
| 794 |
+
"pathlib.Path(\"app.py\").write_text(\"\".join(out), encoding=\"utf-8\")\n",
|
| 795 |
+
"\n",
|
| 796 |
+
"print(\"Exported app.py\")\n"
|
| 797 |
+
]
|
| 798 |
+
}
|
| 799 |
+
],
|
| 800 |
+
"metadata": {
|
| 801 |
+
"kernelspec": {
|
| 802 |
+
"display_name": "Python 3",
|
| 803 |
+
"language": "python",
|
| 804 |
+
"name": "python3"
|
| 805 |
+
},
|
| 806 |
+
"language_info": {
|
| 807 |
+
"codemirror_mode": {
|
| 808 |
+
"name": "ipython",
|
| 809 |
+
"version": 3
|
| 810 |
+
},
|
| 811 |
+
"file_extension": ".py",
|
| 812 |
+
"mimetype": "text/x-python",
|
| 813 |
+
"name": "python",
|
| 814 |
+
"nbconvert_exporter": "python",
|
| 815 |
+
"pygments_lexer": "ipython3",
|
| 816 |
+
"version": "3.11.5"
|
| 817 |
+
}
|
| 818 |
+
},
|
| 819 |
+
"nbformat": 4,
|
| 820 |
+
"nbformat_minor": 5
|
| 821 |
+
}
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import load_learner
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from fastai.vision.all import *
|
| 6 |
+
import numpy as np
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
dummy_img = PILImage.create(np.zeros((224,224,3), dtype=np.uint8))
|
| 10 |
+
|
| 11 |
+
dblock = DataBlock(
|
| 12 |
+
blocks=(ImageBlock, CategoryBlock(vocab=['class_0', 'class_1'])),
|
| 13 |
+
get_items=lambda _: [dummy_img],
|
| 14 |
+
get_y=lambda _: 'class_0',
|
| 15 |
+
item_tfms=Resize(224)
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
dls = dblock.dataloaders(source=None, bs=1, device='cpu')
|
| 19 |
+
|
| 20 |
+
learn = vision_learner(
|
| 21 |
+
dls,
|
| 22 |
+
resnet18,
|
| 23 |
+
n_out=2,
|
| 24 |
+
pretrained=False,
|
| 25 |
+
normalize=False
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
learn.model.load_state_dict(
|
| 29 |
+
torch.load("toai.bin", map_location="cpu")
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
learn.model.eval()
|
| 33 |
+
|
| 34 |
+
from fastai.vision.all import PILImage
|
| 35 |
+
from PIL import Image
|
| 36 |
+
import requests
|
| 37 |
+
from io import BytesIO
|
| 38 |
+
|
| 39 |
+
categories = ['AI Generated', 'Not AI Generated']
|
| 40 |
+
|
| 41 |
+
def classify_image(img):
|
| 42 |
+
|
| 43 |
+
fastai_img = PILImage.create(img)
|
| 44 |
+
pred, pred_idx, probs = learn.predict(fastai_img)
|
| 45 |
+
|
| 46 |
+
return dict(zip(categories, map(float, probs)))
|
| 47 |
+
|
| 48 |
+
interface = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil", image_mode="RGB"),
|
| 49 |
+
outputs=gr.Label(),
|
| 50 |
+
examples=["https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D.jpeg",
|
| 51 |
+
"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_dall-e.jpeg",
|
| 52 |
+
"https://huggingface.co/datasets/brawl7787/example_img/resolve/main/william_D_gemini.jpg"],
|
| 53 |
+
cache_examples=False,
|
| 54 |
+
title="AI or Not AI Image Classifier",
|
| 55 |
+
description="Upload an image to determine if it is AI generated or not.")
|
| 56 |
+
interface.launch(inline=True)
|
| 57 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai<2.8.0
|
| 2 |
+
fastcore
|
| 3 |
+
fastprogress
|
| 4 |
+
fasttransform
|
| 5 |
+
torch>=2.2.0
|
| 6 |
+
torchvision>=0.17.0
|
| 7 |
+
ipython
|
| 8 |
+
cloudpickle
|
| 9 |
+
numpy<2
|
| 10 |
+
pillow
|
| 11 |
+
requests
|
| 12 |
+
gradio
|
| 13 |
+
ipython
|
toai.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:efb33581129ca79f8b7dfdc112f2eb3d3de147fecd0f02120e40bf79612bd4fc
|
| 3 |
+
size 46904146
|
will_smithAI.jpg
ADDED
|
will_smithMaybe.webp
ADDED
|
will_smithReal.jpeg
ADDED
|