Spaces:
Sleeping
Sleeping
README.md file updated
Browse files- .DS_Store +0 -0
- .gitattributes +1 -0
- .gitignore +1 -0
- .gradio/certificate.pem +31 -0
- README.md +3 -0
- app.ipynb +335 -0
- app.py +41 -4
- models/cap_recognizer_v0.pkl +3 -0
- requirements.txt +2 -0
- test_images/unknown_00.jpg +0 -0
- test_images/unknown_01.jpg +0 -0
- test_images/unknown_02.jpg +0 -0
- test_images/unknown_03.jpg +0 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* 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
|
|
|
|
|
|
| 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 |
+
models/* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
myvenv/
|
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR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
|
| 18 |
+
rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
|
| 19 |
+
HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
|
| 20 |
+
hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
|
| 21 |
+
ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
|
| 22 |
+
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
|
| 23 |
+
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
| 24 |
+
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
| 25 |
+
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
|
@@ -12,3 +12,6 @@ short_description: Deploying an image classification project.
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
gradio app URL: https://huggingface.co/spaces/fayez94/cap-recognizer
|
app.ipynb
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"metadata": {
|
| 7 |
+
"id": "Sq8K13e0F5fx"
|
| 8 |
+
},
|
| 9 |
+
"outputs": [],
|
| 10 |
+
"source": [
|
| 11 |
+
"#The line #!default_exp app is typically used in fastai's nbdev library, which is used for creating Python libraries from Jupyter notebooks.\n",
|
| 12 |
+
"\n",
|
| 13 |
+
"#!default_exp app"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"cell_type": "markdown",
|
| 18 |
+
"metadata": {
|
| 19 |
+
"id": "rAQBAIwXGa65"
|
| 20 |
+
},
|
| 21 |
+
"source": [
|
| 22 |
+
"#Cap recognizer"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"cell_type": "code",
|
| 27 |
+
"execution_count": 1,
|
| 28 |
+
"metadata": {
|
| 29 |
+
"id": "DgI4y7YPGdEL"
|
| 30 |
+
},
|
| 31 |
+
"outputs": [],
|
| 32 |
+
"source": [
|
| 33 |
+
"!pip install -Uqq fastai gradio nbdev"
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"cell_type": "code",
|
| 38 |
+
"execution_count": null,
|
| 39 |
+
"metadata": {},
|
| 40 |
+
"outputs": [
|
| 41 |
+
{
|
| 42 |
+
"ename": "ModuleNotFoundError",
|
| 43 |
+
"evalue": "No module named 'fastai'",
|
| 44 |
+
"output_type": "error",
|
| 45 |
+
"traceback": [
|
| 46 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 47 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
| 48 |
+
"Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mfastai\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(fastai\u001b[38;5;241m.\u001b[39m__version__)\n",
|
| 49 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'fastai'"
|
| 50 |
+
]
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"source": [
|
| 54 |
+
"import fastai\n",
|
| 55 |
+
"print(fastai.__version__)\n"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "code",
|
| 60 |
+
"execution_count": 4,
|
| 61 |
+
"metadata": {},
|
| 62 |
+
"outputs": [
|
| 63 |
+
{
|
| 64 |
+
"ename": "ModuleNotFoundError",
|
| 65 |
+
"evalue": "No module named 'fastai'",
|
| 66 |
+
"output_type": "error",
|
| 67 |
+
"traceback": [
|
| 68 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 69 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
| 70 |
+
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mfastai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mall\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n",
|
| 71 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'fastai'"
|
| 72 |
+
]
|
| 73 |
+
}
|
| 74 |
+
],
|
| 75 |
+
"source": [
|
| 76 |
+
"from fastai.vision.all import *"
|
| 77 |
+
]
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"cell_type": "code",
|
| 81 |
+
"execution_count": 10,
|
| 82 |
+
"metadata": {},
|
| 83 |
+
"outputs": [
|
| 84 |
+
{
|
| 85 |
+
"ename": "ModuleNotFoundError",
|
| 86 |
+
"evalue": "No module named 'fastai'",
|
| 87 |
+
"output_type": "error",
|
| 88 |
+
"traceback": [
|
| 89 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 90 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
| 91 |
+
"Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mfastai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mall\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m load_learner\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mgradio\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mgr\u001b[39;00m\n",
|
| 92 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'fastai'"
|
| 93 |
+
]
|
| 94 |
+
}
|
| 95 |
+
],
|
| 96 |
+
"source": [
|
| 97 |
+
"from fastai.vision.all import load_learner\n",
|
| 98 |
+
"import gradio as gr"
|
| 99 |
+
]
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"cell_type": "code",
|
| 103 |
+
"execution_count": 11,
|
| 104 |
+
"metadata": {
|
| 105 |
+
"id": "v83ndxlVHoWj"
|
| 106 |
+
},
|
| 107 |
+
"outputs": [
|
| 108 |
+
{
|
| 109 |
+
"ename": "NameError",
|
| 110 |
+
"evalue": "name 'load_learner' is not defined",
|
| 111 |
+
"output_type": "error",
|
| 112 |
+
"traceback": [
|
| 113 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 114 |
+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
| 115 |
+
"Cell \u001b[0;32mIn[11], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#!export\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mload_learner\u001b[49m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodels/cap_recognizer_v0.pkl\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
| 116 |
+
"\u001b[0;31mNameError\u001b[0m: name 'load_learner' is not defined"
|
| 117 |
+
]
|
| 118 |
+
}
|
| 119 |
+
],
|
| 120 |
+
"source": [
|
| 121 |
+
"#!export\n",
|
| 122 |
+
"model = load_learner(\"models/cap_recognizer_v0.pkl\")"
|
| 123 |
+
]
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"cell_type": "code",
|
| 127 |
+
"execution_count": null,
|
| 128 |
+
"metadata": {
|
| 129 |
+
"id": "5E15Hum7IXkU"
|
| 130 |
+
},
|
| 131 |
+
"outputs": [],
|
| 132 |
+
"source": [
|
| 133 |
+
"#|export\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"cap_labels = [\n",
|
| 136 |
+
" 'balaclava cap',\n",
|
| 137 |
+
" 'baseball cap',\n",
|
| 138 |
+
" 'beanie cap',\n",
|
| 139 |
+
" 'boater hat',\n",
|
| 140 |
+
" 'bowler hat',\n",
|
| 141 |
+
" 'bucket hat',\n",
|
| 142 |
+
" 'cowboy hat',\n",
|
| 143 |
+
" 'fedora cap',\n",
|
| 144 |
+
" 'flat cap',\n",
|
| 145 |
+
" 'ivy cap',\n",
|
| 146 |
+
" 'kepi cap',\n",
|
| 147 |
+
" 'newsboy cap',\n",
|
| 148 |
+
" 'pork pie hat',\n",
|
| 149 |
+
" 'rasta cap',\n",
|
| 150 |
+
" 'sun hat',\n",
|
| 151 |
+
" 'taqiyah cap',\n",
|
| 152 |
+
" 'top hat',\n",
|
| 153 |
+
" 'trucker cap',\n",
|
| 154 |
+
" 'turban cap',\n",
|
| 155 |
+
" 'visor cap'\n",
|
| 156 |
+
"]\n",
|
| 157 |
+
"\n"
|
| 158 |
+
]
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"cell_type": "code",
|
| 162 |
+
"execution_count": 17,
|
| 163 |
+
"metadata": {
|
| 164 |
+
"id": "70xb8V6tJQAU"
|
| 165 |
+
},
|
| 166 |
+
"outputs": [],
|
| 167 |
+
"source": [
|
| 168 |
+
"img = PILImage.create(\"test_images/unknown_01.jpg\")\n",
|
| 169 |
+
"img.thumbnail((128,128))"
|
| 170 |
+
]
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"cell_type": "code",
|
| 174 |
+
"execution_count": 18,
|
| 175 |
+
"metadata": {
|
| 176 |
+
"colab": {
|
| 177 |
+
"base_uri": "https://localhost:8080/",
|
| 178 |
+
"height": 357
|
| 179 |
+
},
|
| 180 |
+
"id": "cGpRTaZWJhKt",
|
| 181 |
+
"outputId": "08497a21-13a9-4c76-f1c0-7af5a5df3fa3"
|
| 182 |
+
},
|
| 183 |
+
"outputs": [
|
| 184 |
+
{
|
| 185 |
+
"data": {
|
| 186 |
+
"text/html": [
|
| 187 |
+
"\n",
|
| 188 |
+
"<style>\n",
|
| 189 |
+
" /* Turns off some styling */\n",
|
| 190 |
+
" progress {\n",
|
| 191 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 192 |
+
" border: none;\n",
|
| 193 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 194 |
+
" background-size: auto;\n",
|
| 195 |
+
" }\n",
|
| 196 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 197 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 198 |
+
" }\n",
|
| 199 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 200 |
+
" background: #F44336;\n",
|
| 201 |
+
" }\n",
|
| 202 |
+
"</style>\n"
|
| 203 |
+
],
|
| 204 |
+
"text/plain": [
|
| 205 |
+
"<IPython.core.display.HTML object>"
|
| 206 |
+
]
|
| 207 |
+
},
|
| 208 |
+
"metadata": {},
|
| 209 |
+
"output_type": "display_data"
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"data": {
|
| 213 |
+
"text/html": [],
|
| 214 |
+
"text/plain": [
|
| 215 |
+
"<IPython.core.display.HTML object>"
|
| 216 |
+
]
|
| 217 |
+
},
|
| 218 |
+
"metadata": {},
|
| 219 |
+
"output_type": "display_data"
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"data": {
|
| 223 |
+
"text/plain": [
|
| 224 |
+
"{'balaclava cap': 0.0001849675754783675,\n",
|
| 225 |
+
" 'baseball cap': 6.271898018894717e-05,\n",
|
| 226 |
+
" 'beanie cap': 0.99442058801651,\n",
|
| 227 |
+
" 'boater hat': 5.3084555418081436e-08,\n",
|
| 228 |
+
" 'bowler hat': 2.4172715029635583e-07,\n",
|
| 229 |
+
" 'bucket hat': 1.0174167073273566e-05,\n",
|
| 230 |
+
" 'cowboy hat': 8.527808148528493e-08,\n",
|
| 231 |
+
" 'fedora cap': 3.8955821679564906e-08,\n",
|
| 232 |
+
" 'flat cap': 2.141284539902699e-06,\n",
|
| 233 |
+
" 'ivy cap': 2.632383711898001e-06,\n",
|
| 234 |
+
" 'kepi cap': 0.00014104695583228022,\n",
|
| 235 |
+
" 'newsboy cap': 1.075521777238464e-05,\n",
|
| 236 |
+
" 'pork pie hat': 3.110138635520343e-08,\n",
|
| 237 |
+
" 'rasta cap': 3.2799041946418583e-05,\n",
|
| 238 |
+
" 'sun hat': 1.9477438399917446e-06,\n",
|
| 239 |
+
" 'taqiyah cap': 8.358875493286178e-05,\n",
|
| 240 |
+
" 'top hat': 3.8565694637782144e-08,\n",
|
| 241 |
+
" 'trucker cap': 4.3577329051913694e-05,\n",
|
| 242 |
+
" 'turban cap': 0.004263813607394695,\n",
|
| 243 |
+
" 'visor cap': 0.0007387499208562076}"
|
| 244 |
+
]
|
| 245 |
+
},
|
| 246 |
+
"execution_count": 18,
|
| 247 |
+
"metadata": {},
|
| 248 |
+
"output_type": "execute_result"
|
| 249 |
+
}
|
| 250 |
+
],
|
| 251 |
+
"source": [
|
| 252 |
+
"recognize_image(img)"
|
| 253 |
+
]
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"cell_type": "code",
|
| 257 |
+
"execution_count": 19,
|
| 258 |
+
"metadata": {
|
| 259 |
+
"colab": {
|
| 260 |
+
"base_uri": "https://localhost:8080/"
|
| 261 |
+
},
|
| 262 |
+
"id": "ZerTaI5OPCGx",
|
| 263 |
+
"outputId": "75d2223d-f318-4e32-a3ec-ac3fc6217534"
|
| 264 |
+
},
|
| 265 |
+
"outputs": [
|
| 266 |
+
{
|
| 267 |
+
"name": "stdout",
|
| 268 |
+
"output_type": "stream",
|
| 269 |
+
"text": [
|
| 270 |
+
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
|
| 271 |
+
"* Running on public URL: https://29d0fcc78c958c8fd7.gradio.live\n",
|
| 272 |
+
"\n",
|
| 273 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"
|
| 274 |
+
]
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
"data": {
|
| 278 |
+
"text/plain": []
|
| 279 |
+
},
|
| 280 |
+
"execution_count": 19,
|
| 281 |
+
"metadata": {},
|
| 282 |
+
"output_type": "execute_result"
|
| 283 |
+
}
|
| 284 |
+
],
|
| 285 |
+
"source": [
|
| 286 |
+
"#!export\n",
|
| 287 |
+
"\n",
|
| 288 |
+
"image = gr.Image()\n",
|
| 289 |
+
"label = gr.Label()\n",
|
| 290 |
+
"examples = [\n",
|
| 291 |
+
" 'test_images/unknown_00.jpg',\n",
|
| 292 |
+
" 'test_images/unknown_01.jpg',\n",
|
| 293 |
+
" 'test_images/unknown_02.jpg',\n",
|
| 294 |
+
" 'test_images/unknown_03.jpg']\n",
|
| 295 |
+
"\n",
|
| 296 |
+
"\n",
|
| 297 |
+
"demo = gr.Interface(fn=recognize_image, inputs=\"image\", outputs=\"label\", examples = examples)\n",
|
| 298 |
+
"demo.launch(inline = False, share = True)"
|
| 299 |
+
]
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"cell_type": "markdown",
|
| 303 |
+
"metadata": {
|
| 304 |
+
"id": "uEfA2Pjmfl-e"
|
| 305 |
+
},
|
| 306 |
+
"source": [
|
| 307 |
+
"#Notebook to python script export\n",
|
| 308 |
+
"done it manually"
|
| 309 |
+
]
|
| 310 |
+
}
|
| 311 |
+
],
|
| 312 |
+
"metadata": {
|
| 313 |
+
"colab": {
|
| 314 |
+
"provenance": []
|
| 315 |
+
},
|
| 316 |
+
"kernelspec": {
|
| 317 |
+
"display_name": "Python 3",
|
| 318 |
+
"name": "python3"
|
| 319 |
+
},
|
| 320 |
+
"language_info": {
|
| 321 |
+
"codemirror_mode": {
|
| 322 |
+
"name": "ipython",
|
| 323 |
+
"version": 3
|
| 324 |
+
},
|
| 325 |
+
"file_extension": ".py",
|
| 326 |
+
"mimetype": "text/x-python",
|
| 327 |
+
"name": "python",
|
| 328 |
+
"nbconvert_exporter": "python",
|
| 329 |
+
"pygments_lexer": "ipython3",
|
| 330 |
+
"version": "3.9.6"
|
| 331 |
+
}
|
| 332 |
+
},
|
| 333 |
+
"nbformat": 4,
|
| 334 |
+
"nbformat_minor": 0
|
| 335 |
+
}
|
app.py
CHANGED
|
@@ -1,7 +1,44 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import load_learner
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
cap_labels = [
|
| 5 |
+
'balaclava cap',
|
| 6 |
+
'baseball cap',
|
| 7 |
+
'beanie cap',
|
| 8 |
+
'boater hat',
|
| 9 |
+
'bowler hat',
|
| 10 |
+
'bucket hat',
|
| 11 |
+
'cowboy hat',
|
| 12 |
+
'fedora cap',
|
| 13 |
+
'flat cap',
|
| 14 |
+
'ivy cap',
|
| 15 |
+
'kepi cap',
|
| 16 |
+
'newsboy cap',
|
| 17 |
+
'pork pie hat',
|
| 18 |
+
'rasta cap',
|
| 19 |
+
'sun hat',
|
| 20 |
+
'taqiyah cap',
|
| 21 |
+
'top hat',
|
| 22 |
+
'trucker cap',
|
| 23 |
+
'turban cap',
|
| 24 |
+
'visor cap'
|
| 25 |
+
]
|
| 26 |
|
| 27 |
+
model = load_learner("models/cap_recognizer_v0.pkl")
|
| 28 |
+
|
| 29 |
+
def recognize_image(image):
|
| 30 |
+
pred, idx, probs = model.predict(image)
|
| 31 |
+
return dict(zip(cap_labels, map(float,probs)))
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
image = gr.Image()
|
| 35 |
+
label = gr.Label()
|
| 36 |
+
examples = [
|
| 37 |
+
'test_images/unknown_00.jpg',
|
| 38 |
+
'test_images/unknown_01.jpg',
|
| 39 |
+
'test_images/unknown_02.jpg',
|
| 40 |
+
'test_images/unknown_03.jpg']
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
demo = gr.Interface(fn=recognize_image, inputs="image", outputs="label", examples = examples)
|
| 44 |
+
demo.launch(inline = False, share = True)
|
models/cap_recognizer_v0.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e9e0e407f17e1d15373b84f28d83e7d1aaedb46cb4358575baea40da9ce8d38c
|
| 3 |
+
size 87664098
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai==2.7.18
|
| 2 |
+
gradio==5.16.0
|
test_images/unknown_00.jpg
ADDED
|
test_images/unknown_01.jpg
ADDED
|
test_images/unknown_02.jpg
ADDED
|
test_images/unknown_03.jpg
ADDED
|