Spaces:
Runtime error
Runtime error
try using nbdev (WIP)
Browse files- photo-checker.ipynb +189 -1
photo-checker.ipynb
CHANGED
@@ -46,6 +46,16 @@
|
|
46 |
"from fastai.vision.widgets import *"
|
47 |
]
|
48 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
{
|
50 |
"cell_type": "code",
|
51 |
"execution_count": 7,
|
@@ -571,10 +581,11 @@
|
|
571 |
},
|
572 |
{
|
573 |
"cell_type": "code",
|
574 |
-
"execution_count":
|
575 |
"metadata": {},
|
576 |
"outputs": [],
|
577 |
"source": [
|
|
|
578 |
"learn = load_learner('photos.pkl')"
|
579 |
]
|
580 |
},
|
@@ -1128,6 +1139,183 @@
|
|
1128 |
"!pip install voila\n",
|
1129 |
"!jupyter serverextension enable --sys-prefix voila"
|
1130 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1131 |
}
|
1132 |
],
|
1133 |
"metadata": {
|
|
|
46 |
"from fastai.vision.widgets import *"
|
47 |
]
|
48 |
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": 1,
|
52 |
+
"metadata": {},
|
53 |
+
"outputs": [],
|
54 |
+
"source": [
|
55 |
+
"#|export\n",
|
56 |
+
"from fastai.vision.all import *"
|
57 |
+
]
|
58 |
+
},
|
59 |
{
|
60 |
"cell_type": "code",
|
61 |
"execution_count": 7,
|
|
|
581 |
},
|
582 |
{
|
583 |
"cell_type": "code",
|
584 |
+
"execution_count": 2,
|
585 |
"metadata": {},
|
586 |
"outputs": [],
|
587 |
"source": [
|
588 |
+
"#|export\n",
|
589 |
"learn = load_learner('photos.pkl')"
|
590 |
]
|
591 |
},
|
|
|
1139 |
"!pip install voila\n",
|
1140 |
"!jupyter serverextension enable --sys-prefix voila"
|
1141 |
]
|
1142 |
+
},
|
1143 |
+
{
|
1144 |
+
"cell_type": "code",
|
1145 |
+
"execution_count": 6,
|
1146 |
+
"metadata": {},
|
1147 |
+
"outputs": [],
|
1148 |
+
"source": [
|
1149 |
+
"#|export\n",
|
1150 |
+
"labels = learn.dls.vocab"
|
1151 |
+
]
|
1152 |
+
},
|
1153 |
+
{
|
1154 |
+
"cell_type": "code",
|
1155 |
+
"execution_count": 5,
|
1156 |
+
"metadata": {},
|
1157 |
+
"outputs": [
|
1158 |
+
{
|
1159 |
+
"data": {
|
1160 |
+
"text/plain": [
|
1161 |
+
"['bad', 'good']"
|
1162 |
+
]
|
1163 |
+
},
|
1164 |
+
"execution_count": 5,
|
1165 |
+
"metadata": {},
|
1166 |
+
"output_type": "execute_result"
|
1167 |
+
}
|
1168 |
+
],
|
1169 |
+
"source": [
|
1170 |
+
"labels"
|
1171 |
+
]
|
1172 |
+
},
|
1173 |
+
{
|
1174 |
+
"cell_type": "code",
|
1175 |
+
"execution_count": 8,
|
1176 |
+
"metadata": {},
|
1177 |
+
"outputs": [],
|
1178 |
+
"source": [
|
1179 |
+
"#|export\n",
|
1180 |
+
"def classify_image(img):\n",
|
1181 |
+
"\timg = PILImage.create(img)\n",
|
1182 |
+
"\tpred,idx,probs = learn.predict(img)\n",
|
1183 |
+
"\treturn dict(zip(labels, map(float, probs)))"
|
1184 |
+
]
|
1185 |
+
},
|
1186 |
+
{
|
1187 |
+
"cell_type": "code",
|
1188 |
+
"execution_count": 9,
|
1189 |
+
"metadata": {},
|
1190 |
+
"outputs": [
|
1191 |
+
{
|
1192 |
+
"name": "stderr",
|
1193 |
+
"output_type": "stream",
|
1194 |
+
"text": [
|
1195 |
+
"/usr/local/lib/python3.10/dist-packages/gradio/inputs.py:256: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
1196 |
+
" warnings.warn(\n",
|
1197 |
+
"/usr/local/lib/python3.10/dist-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
1198 |
+
" warnings.warn(value)\n",
|
1199 |
+
"/usr/local/lib/python3.10/dist-packages/gradio/outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
1200 |
+
" warnings.warn(\n",
|
1201 |
+
"/usr/local/lib/python3.10/dist-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
1202 |
+
" warnings.warn(value)\n",
|
1203 |
+
"/usr/local/lib/python3.10/dist-packages/gradio/deprecation.py:40: UserWarning: `enable_queue` is deprecated in `Interface()`, please use it within `launch()` instead.\n",
|
1204 |
+
" warnings.warn(value)\n"
|
1205 |
+
]
|
1206 |
+
},
|
1207 |
+
{
|
1208 |
+
"name": "stdout",
|
1209 |
+
"output_type": "stream",
|
1210 |
+
"text": [
|
1211 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
1212 |
+
"\n",
|
1213 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
1214 |
+
]
|
1215 |
+
},
|
1216 |
+
{
|
1217 |
+
"data": {
|
1218 |
+
"text/html": [
|
1219 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
1220 |
+
],
|
1221 |
+
"text/plain": [
|
1222 |
+
"<IPython.core.display.HTML object>"
|
1223 |
+
]
|
1224 |
+
},
|
1225 |
+
"metadata": {},
|
1226 |
+
"output_type": "display_data"
|
1227 |
+
},
|
1228 |
+
{
|
1229 |
+
"data": {
|
1230 |
+
"text/plain": [
|
1231 |
+
"(<gradio.routes.App at 0x7f4a2139bac0>, 'http://127.0.0.1:7860/', None)"
|
1232 |
+
]
|
1233 |
+
},
|
1234 |
+
"execution_count": 9,
|
1235 |
+
"metadata": {},
|
1236 |
+
"output_type": "execute_result"
|
1237 |
+
},
|
1238 |
+
{
|
1239 |
+
"data": {
|
1240 |
+
"text/html": [
|
1241 |
+
"\n",
|
1242 |
+
"<style>\n",
|
1243 |
+
" /* Turns off some styling */\n",
|
1244 |
+
" progress {\n",
|
1245 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
1246 |
+
" border: none;\n",
|
1247 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
1248 |
+
" background-size: auto;\n",
|
1249 |
+
" }\n",
|
1250 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
1251 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
1252 |
+
" }\n",
|
1253 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
1254 |
+
" background: #F44336;\n",
|
1255 |
+
" }\n",
|
1256 |
+
"</style>\n"
|
1257 |
+
],
|
1258 |
+
"text/plain": [
|
1259 |
+
"<IPython.core.display.HTML object>"
|
1260 |
+
]
|
1261 |
+
},
|
1262 |
+
"metadata": {},
|
1263 |
+
"output_type": "display_data"
|
1264 |
+
},
|
1265 |
+
{
|
1266 |
+
"data": {
|
1267 |
+
"text/html": [],
|
1268 |
+
"text/plain": [
|
1269 |
+
"<IPython.core.display.HTML object>"
|
1270 |
+
]
|
1271 |
+
},
|
1272 |
+
"metadata": {},
|
1273 |
+
"output_type": "display_data"
|
1274 |
+
}
|
1275 |
+
],
|
1276 |
+
"source": [
|
1277 |
+
"#|export\n",
|
1278 |
+
"import gradio as gr\n",
|
1279 |
+
"\n",
|
1280 |
+
"iface = gr.Interface(\n",
|
1281 |
+
"\ttitle = \"Photo Checker\",\n",
|
1282 |
+
"\tdescription = \"\"\"This project checks which of our family photos are \"good\" or \"bad\". We have nearly 80,000 photos, so it's not practical to sort them out by hand. I want to exclude screenshots, photos of computer screens, photos of papers, images with lots of text, and very blurry images. I used this to separate the good photos to use for a random slide show on our TV. The trained model achieves around 99% accuracy on the validation set.\"\"\",\n",
|
1283 |
+
"\tfn = classify_image,\n",
|
1284 |
+
"\tinputs = gr.inputs.Image(shape = (512,512)),\n",
|
1285 |
+
"\toutputs = gr.outputs.Label(num_top_classes = 3),\n",
|
1286 |
+
"\texamples = list(map(str, get_image_files('eg'))),\n",
|
1287 |
+
"\tinterpretation='default',\n",
|
1288 |
+
"\tenable_queue=True,\n",
|
1289 |
+
")\n",
|
1290 |
+
"\n",
|
1291 |
+
"iface.launch()"
|
1292 |
+
]
|
1293 |
+
},
|
1294 |
+
{
|
1295 |
+
"cell_type": "code",
|
1296 |
+
"execution_count": 1,
|
1297 |
+
"metadata": {},
|
1298 |
+
"outputs": [
|
1299 |
+
{
|
1300 |
+
"name": "stderr",
|
1301 |
+
"output_type": "stream",
|
1302 |
+
"text": [
|
1303 |
+
"/usr/local/lib/python3.10/dist-packages/nbdev/export.py:54: UserWarning: Notebook 'photo-checker.ipynb' uses `#|export` without `#|default_exp` cell.\n",
|
1304 |
+
"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n",
|
1305 |
+
"See https://nbdev.fast.ai/getting_started.html for more information.\n",
|
1306 |
+
" warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n"
|
1307 |
+
]
|
1308 |
+
}
|
1309 |
+
],
|
1310 |
+
"source": [
|
1311 |
+
"from nbdev.export import nb_export\n",
|
1312 |
+
"nb_export('photo-checker.ipynb')"
|
1313 |
+
]
|
1314 |
+
},
|
1315 |
+
{
|
1316 |
+
"cell_type": "raw",
|
1317 |
+
"metadata": {},
|
1318 |
+
"source": []
|
1319 |
}
|
1320 |
],
|
1321 |
"metadata": {
|