File size: 5,295 Bytes
d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ca7f933 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ca7f933 d67ffd8 ca7f933 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 3dd6c82 d67ffd8 3dd6c82 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 ac9ad30 d67ffd8 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2c1a0cda-918c-4bcb-abb1-3afeb823add8",
"metadata": {},
"outputs": [],
"source": [
"#| default_exp app"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "baaff5aa-0845-4184-90de-533fec9fc366",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"#|export\n",
"from fastbook import search_images_ddg\n",
"from fastdownload import download_url\n",
"from fastai.vision.all import *\n",
"import gradio as gr\n",
"import torch"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "0bfbf2a5-a46a-4a47-b982-4e36d8418c0c",
"metadata": {},
"outputs": [],
"source": [
"#def greet(name):\n",
"# return \"Hello \" + name + \"!!\""
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "c725868e-a654-4ea7-9a2f-78bee1491e72",
"metadata": {},
"outputs": [],
"source": [
"#iface = gr.Interface(fn=greet, inputs=\"text\", outputs=\"text\")\n",
"#iface.launch(share=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b908abcb-2973-48d5-89ec-0f02b75b9ed3",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"img = PILImage.create('grizzly.jpg')\n",
"img.thumbnail((192,192))\n",
"img"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "9db1bbb9-b033-472f-b971-416b7756568c",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'model.pkl'"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#|export\n",
"path = Path()\n",
"filename = path.ls(file_exts='.pkl')\n",
"filename[0].name"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40e4ac20-e52f-4e4a-b6a8-6ad2816a3415",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"#|export\n",
"learn = load_learner(filename[0].name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7dba9619-034f-476d-a7c4-5f4511ed18ce",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"%time learn.predict(img)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "74f92818-e648-4198-a061-308aebf61989",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"\n",
"searches = (\"grizzly bears\",\"black bears\",\"teddy bears\")\n",
"\n",
"def classify_image(img):\n",
" pred,idx,probs = learn.predict(img)\n",
" return dict(zip(searches, map(float,probs)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "634686dd-4306-4888-8792-699d95f2782c",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"%time classify_image(img)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "33d12cfc-68eb-4666-8bd7-b7617eec65cd",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"\n",
"title = \"FastAi demo\"\n",
"description = \"This demo is the original\"\n",
"examples = [\"grizzly.jpg\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5dfdfd51-32bd-4364-a41a-a391962e72c6",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"\n",
"\n",
"demo = gr.Interface(\n",
" fn=classify_image,\n",
" inputs=\"image\",\n",
" outputs=\"label\",\n",
" title=title,\n",
" description=description,\n",
" examples = examples)\n",
"demo.launch()"
]
},
{
"cell_type": "markdown",
"id": "ac141816-1577-41bb-bd91-dc79682896de",
"metadata": {},
"source": [
"## export"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "5f14dab3-e6c3-4768-a8e0-8b7355c50929",
"metadata": {},
"outputs": [],
"source": [
"from nbdev.export import *"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "1998fe76-7137-4f3a-b1b2-69f202bc0f49",
"metadata": {},
"outputs": [],
"source": [
"nb_export('app.ipynb',lib_path=Path())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0cfad669-4502-49f8-8dca-3fc7c5ea0525",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|