Spaces:
Runtime error
Runtime error
Commit
·
d438454
1
Parent(s):
50d70f3
Update model path relative
Browse files- nbs/app.ipynb +54 -41
- nbs/app.py +17 -2
nbs/app.ipynb
CHANGED
|
@@ -35,7 +35,7 @@
|
|
| 35 |
},
|
| 36 |
{
|
| 37 |
"cell_type": "code",
|
| 38 |
-
"execution_count":
|
| 39 |
"id": "39544176-83a1-4bcb-bdc3-c8acb8a2ba84",
|
| 40 |
"metadata": {
|
| 41 |
"scrolled": true
|
|
@@ -44,12 +44,15 @@
|
|
| 44 |
"source": [
|
| 45 |
"#|export\n",
|
| 46 |
"from fastai.vision.all import *\n",
|
| 47 |
-
"import gradio as gr"
|
|
|
|
|
|
|
|
|
|
| 48 |
]
|
| 49 |
},
|
| 50 |
{
|
| 51 |
"cell_type": "code",
|
| 52 |
-
"execution_count":
|
| 53 |
"id": "38301e4e-11fc-4f1e-909f-58759b8d9e8d",
|
| 54 |
"metadata": {
|
| 55 |
"scrolled": true
|
|
@@ -57,18 +60,29 @@
|
|
| 57 |
"outputs": [],
|
| 58 |
"source": [
|
| 59 |
"#|export\n",
|
| 60 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
]
|
| 62 |
},
|
| 63 |
{
|
| 64 |
"cell_type": "code",
|
| 65 |
-
"execution_count":
|
| 66 |
"id": "905035bc-6dd2-45ba-aee8-b77a5b519a04",
|
| 67 |
"metadata": {},
|
| 68 |
"outputs": [],
|
| 69 |
"source": [
|
| 70 |
"#|export\n",
|
| 71 |
-
"categories =
|
| 72 |
"\n",
|
| 73 |
"def classify_image(img):\n",
|
| 74 |
" pred,idx,probs = learn.predict(img)\n",
|
|
@@ -77,7 +91,7 @@
|
|
| 77 |
},
|
| 78 |
{
|
| 79 |
"cell_type": "code",
|
| 80 |
-
"execution_count":
|
| 81 |
"id": "e77f8a97-e73f-4c3b-a73d-a958689ff1a6",
|
| 82 |
"metadata": {},
|
| 83 |
"outputs": [
|
|
@@ -85,7 +99,7 @@
|
|
| 85 |
"name": "stdout",
|
| 86 |
"output_type": "stream",
|
| 87 |
"text": [
|
| 88 |
-
"* Running on local URL: http://127.0.0.1:
|
| 89 |
"\n",
|
| 90 |
"To create a public link, set `share=True` in `launch()`.\n"
|
| 91 |
]
|
|
@@ -94,41 +108,10 @@
|
|
| 94 |
"data": {
|
| 95 |
"text/plain": []
|
| 96 |
},
|
| 97 |
-
"execution_count":
|
| 98 |
"metadata": {},
|
| 99 |
"output_type": "execute_result"
|
| 100 |
-
}
|
| 101 |
-
],
|
| 102 |
-
"source": [
|
| 103 |
-
"#|export\n",
|
| 104 |
-
"image = gr.Image(type=\"pil\")\n",
|
| 105 |
-
"label = gr.Label()\n",
|
| 106 |
-
"examples = ['black_bear.jpg', 'grizzly_bear.jpg', 'teddy_bear.jpg']\n",
|
| 107 |
-
"\n",
|
| 108 |
-
"intf = gr.Interface(\n",
|
| 109 |
-
" fn=classify_image, \n",
|
| 110 |
-
" inputs=image, \n",
|
| 111 |
-
" outputs=label, \n",
|
| 112 |
-
" examples=examples\n",
|
| 113 |
-
")\n",
|
| 114 |
-
"\n",
|
| 115 |
-
"intf.launch(inline=False)"
|
| 116 |
-
]
|
| 117 |
-
},
|
| 118 |
-
{
|
| 119 |
-
"cell_type": "markdown",
|
| 120 |
-
"id": "3a379ae5-65ff-476a-ba6d-3c1edc6878b3",
|
| 121 |
-
"metadata": {},
|
| 122 |
-
"source": [
|
| 123 |
-
"## export python file from the notebook"
|
| 124 |
-
]
|
| 125 |
-
},
|
| 126 |
-
{
|
| 127 |
-
"cell_type": "code",
|
| 128 |
-
"execution_count": 8,
|
| 129 |
-
"id": "af0ec285-9e53-49f0-be57-12d4e1fc1a3c",
|
| 130 |
-
"metadata": {},
|
| 131 |
-
"outputs": [
|
| 132 |
{
|
| 133 |
"data": {
|
| 134 |
"text/html": [
|
|
@@ -204,6 +187,36 @@
|
|
| 204 |
"output_type": "display_data"
|
| 205 |
}
|
| 206 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
"source": [
|
| 208 |
"import nbdev\n",
|
| 209 |
"\n",
|
|
|
|
| 35 |
},
|
| 36 |
{
|
| 37 |
"cell_type": "code",
|
| 38 |
+
"execution_count": 12,
|
| 39 |
"id": "39544176-83a1-4bcb-bdc3-c8acb8a2ba84",
|
| 40 |
"metadata": {
|
| 41 |
"scrolled": true
|
|
|
|
| 44 |
"source": [
|
| 45 |
"#|export\n",
|
| 46 |
"from fastai.vision.all import *\n",
|
| 47 |
+
"import gradio as gr\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"import pathlib\n",
|
| 50 |
+
"import os"
|
| 51 |
]
|
| 52 |
},
|
| 53 |
{
|
| 54 |
"cell_type": "code",
|
| 55 |
+
"execution_count": 13,
|
| 56 |
"id": "38301e4e-11fc-4f1e-909f-58759b8d9e8d",
|
| 57 |
"metadata": {
|
| 58 |
"scrolled": true
|
|
|
|
| 60 |
"outputs": [],
|
| 61 |
"source": [
|
| 62 |
"#|export\n",
|
| 63 |
+
"\n",
|
| 64 |
+
"path = pathlib.Path('.')\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"try: \n",
|
| 67 |
+
" path = pathlib.Path(__file__).parent.resolve()\n",
|
| 68 |
+
"except NameError: \n",
|
| 69 |
+
" if 'SPACE_ID' in os.environ: \n",
|
| 70 |
+
" path = pathlib.Path('nbs') \n",
|
| 71 |
+
"\n",
|
| 72 |
+
"model_path = path / 'model.pkl'\n",
|
| 73 |
+
"\n",
|
| 74 |
+
"learn = load_learner(model_path)"
|
| 75 |
]
|
| 76 |
},
|
| 77 |
{
|
| 78 |
"cell_type": "code",
|
| 79 |
+
"execution_count": 14,
|
| 80 |
"id": "905035bc-6dd2-45ba-aee8-b77a5b519a04",
|
| 81 |
"metadata": {},
|
| 82 |
"outputs": [],
|
| 83 |
"source": [
|
| 84 |
"#|export\n",
|
| 85 |
+
"categories = learn.dls.vocab\n",
|
| 86 |
"\n",
|
| 87 |
"def classify_image(img):\n",
|
| 88 |
" pred,idx,probs = learn.predict(img)\n",
|
|
|
|
| 91 |
},
|
| 92 |
{
|
| 93 |
"cell_type": "code",
|
| 94 |
+
"execution_count": 15,
|
| 95 |
"id": "e77f8a97-e73f-4c3b-a73d-a958689ff1a6",
|
| 96 |
"metadata": {},
|
| 97 |
"outputs": [
|
|
|
|
| 99 |
"name": "stdout",
|
| 100 |
"output_type": "stream",
|
| 101 |
"text": [
|
| 102 |
+
"* Running on local URL: http://127.0.0.1:7861\n",
|
| 103 |
"\n",
|
| 104 |
"To create a public link, set `share=True` in `launch()`.\n"
|
| 105 |
]
|
|
|
|
| 108 |
"data": {
|
| 109 |
"text/plain": []
|
| 110 |
},
|
| 111 |
+
"execution_count": 15,
|
| 112 |
"metadata": {},
|
| 113 |
"output_type": "execute_result"
|
| 114 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
{
|
| 116 |
"data": {
|
| 117 |
"text/html": [
|
|
|
|
| 187 |
"output_type": "display_data"
|
| 188 |
}
|
| 189 |
],
|
| 190 |
+
"source": [
|
| 191 |
+
"#|export\n",
|
| 192 |
+
"image = gr.Image(type=\"pil\")\n",
|
| 193 |
+
"label = gr.Label()\n",
|
| 194 |
+
"examples = ['black_bear.jpg', 'grizzly_bear.jpg', 'teddy_bear.jpg']\n",
|
| 195 |
+
"\n",
|
| 196 |
+
"intf = gr.Interface(\n",
|
| 197 |
+
" fn=classify_image, \n",
|
| 198 |
+
" inputs=image, \n",
|
| 199 |
+
" outputs=label, \n",
|
| 200 |
+
" examples=examples\n",
|
| 201 |
+
")\n",
|
| 202 |
+
"\n",
|
| 203 |
+
"intf.launch(inline=False)"
|
| 204 |
+
]
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"cell_type": "markdown",
|
| 208 |
+
"id": "3a379ae5-65ff-476a-ba6d-3c1edc6878b3",
|
| 209 |
+
"metadata": {},
|
| 210 |
+
"source": [
|
| 211 |
+
"## export python file from the notebook"
|
| 212 |
+
]
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"cell_type": "code",
|
| 216 |
+
"execution_count": 16,
|
| 217 |
+
"id": "af0ec285-9e53-49f0-be57-12d4e1fc1a3c",
|
| 218 |
+
"metadata": {},
|
| 219 |
+
"outputs": [],
|
| 220 |
"source": [
|
| 221 |
"import nbdev\n",
|
| 222 |
"\n",
|
nbs/app.py
CHANGED
|
@@ -1,14 +1,29 @@
|
|
| 1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
| 2 |
|
| 3 |
# %% auto 0
|
| 4 |
-
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
|
| 5 |
|
| 6 |
# %% app.ipynb 3
|
| 7 |
from fastai.vision.all import *
|
| 8 |
import gradio as gr
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
# %% app.ipynb 4
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# %% app.ipynb 5
|
| 14 |
categories = ('Black','Grizzly','Teddy')
|
|
|
|
| 1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
| 2 |
|
| 3 |
# %% auto 0
|
| 4 |
+
__all__ = ['path', 'model_path', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
|
| 5 |
|
| 6 |
# %% app.ipynb 3
|
| 7 |
from fastai.vision.all import *
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
+
import pathlib
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
# %% app.ipynb 4
|
| 14 |
+
path = pathlib.Path('.')
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
path = pathlib.Path(__file__).parent.resolve()
|
| 18 |
+
except NameError:
|
| 19 |
+
if 'SPACE_ID' in os.environ:
|
| 20 |
+
path = pathlib.Path('nbs')
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Construct the final path to the model
|
| 24 |
+
model_path = path / 'model.pkl'
|
| 25 |
+
|
| 26 |
+
learn = load_learner('./nbs/model.pkl')
|
| 27 |
|
| 28 |
# %% app.ipynb 5
|
| 29 |
categories = ('Black','Grizzly','Teddy')
|