{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "792363ad-e816-4530-a791-45217b524f85",
"metadata": {},
"outputs": [],
"source": [
"# This is an app written inside a notebook using ipywidgets"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "dff9a851-3ea1-4a16-b6d6-a3da19b8e648",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/dmartinec/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py:34: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020\n",
" warnings.warn(\n"
]
}
],
"source": [
"from fastai.vision.all import *\n",
"import ipywidgets as widgets\n",
"from ipywidgets import VBox"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c650f97a-db36-4d65-9ba9-f5f5d3420386",
"metadata": {},
"outputs": [],
"source": [
"# Copied from https://n90l9ahmyv.clg07azjl.paperspacegradient.com/lab/tree/bear_multicat.ipynb\n",
"\n",
"# from parent_label\n",
"def get_y(o):\n",
" parent_name = Path(o).parent.name\n",
" if parent_name in bear_types:\n",
" return [parent_name]\n",
" return []"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0bdb2376-3b03-45cf-b146-c8e3be66fc53",
"metadata": {},
"outputs": [],
"source": [
"learn_inf = load_learner('bear_multicat.pkl') #'export.pkl')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "90a2f2b1-216e-41aa-9fb2-ee371b0aad6e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"((#1) ['grizzly'],\n",
" tensor([False, True, False]),\n",
" tensor([4.8684e-04, 1.0000e+00, 2.7510e-03]))"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn_inf.predict('images/grizzly.jpg')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "979c1b0e-54ed-4f2a-b720-452428634458",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "63f9d2e1e09a4fc886dd3b7998e2f50e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FileUpload(value=(), description='Upload')"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#hide_output\n",
"btn_upload = widgets.FileUpload()\n",
"btn_upload"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "2980e772-5a8c-4e98-9a6b-e79d32f2f90b",
"metadata": {},
"outputs": [
{
"data": {
"image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACAAIADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOE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R9ayReXS523Mwy284c8t6/WmLNKm7bI67/vYYjd9aAO1h8L6XP4tutPVLkQWt/b2mzOTIrOVZieo4HasrUPChsNN+3ver5UiB4VMTbmyqtg4zt4bg9Dg9Kwhd3KytKtxKJG+84c5P1NDXVwyMjXEpRgAVLnBA6flQBDRRRQAUUUUAFFFFABRRRQBf0fUI9MvmuJYTMjQTQlA2378bJnPtuzWpL4z1G4mimuIreWSIMqFgwAU5IGAccFjg9R61zlFAHRXHjG/u7qW4mgt2kmjaKQjcu5C+8DhuMNyCOeBnNYVxMJ5fM8pIzgAhc8nueSeT1qKigAooooAKKKKACiiigAooooAKKKKACiip7IWpvYBemQWu8eaYsbgvfGe9AEFW7bS728i823gLpnGQQOavBPDmCDNqJJxg7EGPnOe/93H4g1FMuhiCXyZL0yhf3W5VwWyfvegxjpmk79AXmVrnS72zi824gKJnGSQeaqVsFfDwKjfqBG5dxAX7uF3Ae+d+PwpSnh3ads1/nDYJVf74x/45n8cUK/UGY1FS3IgFzL9lMhg3HyzIAG29s44zUVMAooooAKKKKACiiigAooooAKKKKACitFn0bHyw3oOO8i/4Uu/Ref3F77fvF/woAzaK0S+j8YgvMYOT5i9e3b6UI+jhvnhvSuT0dQcc47fT9aAM6ig4zx0ooAKKKKACiiigD//Z",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAAASRklEQVR4Ae3cCWxVRRcH8PbR0rJIgQIKArK4QRERVBAQZBNR3BBXBLfgbjCuRBM+I4pGjQkxalyiYFy/iLjhCm4ogriAC264IC7siogUStvvV8Y8azX52meL78W5ebmZO3eWM/9z5sw55868rKx4RQQiAhGBiEBEICIQEYgIRAQiAhGBiEBEICIQEYgIRATSEoHs7OysLL+s/Jzcls0KJELOtntW88YNCxrnbyO8okxGXImMoPJ3Issly4vat7hm/MDO7VpsY4YhZJeXlw/ep8PEsX2bN20cmPF7lZiqXQR6F7W+95IhvXZvs61Z6PvlnDhkj5vP7dOusKHMikkSrzpAoALrHru1nDl5aNEuhaH97OyE3xH9Oj44aWiz35RPxYSog95jk1mJnHo5//3PoAlHFyUS9erVyw2QtG7e6PWpI4b0ai/TD/qJRCbxICdzOFs2oHvrXh3KN/2c+/KU/pvLy6fPXvXAnE9H9WtbmLdhZM/mE0e33bg5ce+c756Yu8w6kSnjyiAGZBV1KsjL2jyoKCer/BeqZ/KYjktXburarn7T/JJj++aXbS02L7qM67R6Xcm8j77NFAaYrRlz5efl5mQnSkqzSsqyN5dmNay3bliPZoS9rKx885atJWWJ4pLypvU39OkmM2OuTGLAmp+KSytszG2maHZWIrsB7NduLKX6y7J/0zlbyxPrN2zJGPi32XCZQm32rHnLFy/Pa5yX3yAnsUN+/VW/lj+zcNXMeevWFuc1yc2V2Sgvd9HynFnz6Z+MEawMs9jatyo4bXjHdi1z120snTF3xYIlK6mgHrsWjh7QrnXTestWFU97duk3azdlc80yZx3OlBkQ6KwqMVbjPw6AkqqS88f38SkiEBGICEQEIgIRgYhARCAiEBGICEQEIgIRgYhARCAiEBGICEQEIgIRgYhARCAiEBGICEQEIgKZhkD8FJ4ax1LcP2MDbF5enq2AyV4x4NBDDx0wYEAyp6aJXr16jR49OjVGNm/e/LTTTmvVqlVq1auQWs1G9t1331GjRlWzcJUuko8pMqBZs2b333///vvvn2yorKxst912O+yww5I51UmcddZZe+21VyjZpEmT448/3lGL6lSsUuaXX3457rjj2rZtW/3qZ5xxRrdu3aq045FsXXbZZY0bN/7zqyo5+fn5Y8aMqZJZ08cUN+euXbv2xx9/XL16dehvzz337NGjBzHcuHFjo0aNhg8fnpubu2TJkg8++ECBESNG7LHHHl9//XWLFi3uueeevn377rjjjiUlJQsWLBg2bJiS33333bp169T9+eefd9111wMPPPCNN9446qij3nnnnaKiorvvvnuXXXbBJ9C89dZbZslrr722Zs0aHcnx6vHHH9+yZcv69eu7d++u7sMPP+wRDZjx+uuvm5dfffXVm2++2bVr12+++Wbo0KEPPPBA06ZNhwwZ0rBhQ13379+fFOv9pZdeUqVTp05ezZs3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JLbQJ7Ak3WZQ+XIcaCX79iLarxiOi8q0eR3ojgerrmRgEtxpKgfn7F+XacOoo5Oq27YeWg5HgtNnHkRKIgIRgYhARCAiEBGICEQEIgIRgYhARCAiEBGICEQE/g0IpFEwLsAt/CkGJzIqcCagLxQqqCkCKhwtU0KmuJtgnE8ConIhYCf6Ly1y51EBaeWFpp1pDWmtKe+VP5Nwkjt9WJtG3wOAIsLs381h5K/Z/B2HMLLgqP/Gk+P/wSSgKf7sCDzEPQptwlTgE7jg1oLYp88D/ijC35H5ACD6LyYqRKqwFhSeNm2a1iID/hoBf/kAd2j6owEl/BMBYSfXosdwF6B2It6fpPhfPaBjhv8mIM5mg2ImB36YAWRfMa9MJv/7Ju0VRnqLDQr/dd8xFwIkNOIQEYgI/JsQ+B+uxHHAmnlHeQAAAABJRU5ErkJggg==",
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"file_content = btn_upload.value[-1]['content']\n",
"file_bytes = io.BytesIO(file_content)\n",
"img = PILImage.create(file_bytes)\n",
"img.to_thumb(128)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "2d0ea83d-1702-4396-9cb8-943b677e131f",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "86d6461fd6024df0a839db9eeeac68d7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#hide_output\n",
"out_pl = widgets.Output()\n",
"out_pl.clear_output()\n",
"with out_pl: display(img.to_thumb(128,128))\n",
"out_pl"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0d57ecfb-379b-4d4d-b631-78b79ea7f9ed",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'pred' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[13], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#hide_output\u001b[39;00m\n\u001b[1;32m 2\u001b[0m lbl_pred \u001b[38;5;241m=\u001b[39m widgets\u001b[38;5;241m.\u001b[39mLabel()\n\u001b[0;32m----> 3\u001b[0m lbl_pred\u001b[38;5;241m.\u001b[39mvalue \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mPrediction: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpred\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m; Probability: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mprobs[pred_idx]\u001b[38;5;132;01m:\u001b[39;00m\u001b[38;5;124m.04f\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 4\u001b[0m lbl_pred\n",
"\u001b[0;31mNameError\u001b[0m: name 'pred' is not defined"
]
}
],
"source": [
"#hide_output\n",
"lbl_pred = widgets.Label()\n",
"lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
"lbl_pred"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "b535f1ed-cbca-4038-b84f-ae6c98585f79",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "906634c0be2440438b6d4da7f6c8bde1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Classify', style=ButtonStyle())"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#hide_output\n",
"btn_run = widgets.Button(description='Classify')\n",
"btn_run"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ea25374d-c685-4c42-ae09-4df5c442742b",
"metadata": {},
"outputs": [],
"source": [
"def on_click_classify(change):\n",
" file_content = btn_upload.value[-1]['content']\n",
" file_bytes = io.BytesIO(file_content)\n",
" img = PILImage.create(file_bytes)\n",
" out_pl.clear_output()\n",
" with out_pl: display(img.to_thumb(128,128))\n",
" pred,pred_idx,probs = learn_inf.predict(img)\n",
" lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
"\n",
"btn_run.on_click(on_click_classify)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "c31b5f0b-6234-46bb-a7ea-6510d6e2bacb",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e5fb4cefa9b841229b70b248615b2478",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Label(value='Select your bear!'), FileUpload(value=({'name': 'text.png', 'type': 'image/png', '…"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#hide_output\n",
"VBox([widgets.Label('Select your bear!'), \n",
" btn_upload, btn_run, out_pl, lbl_pred])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "452ffe22-1fa6-4b67-bc2e-eb03cd60598c",
"metadata": {},
"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.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}