Spaces:
Sleeping
Sleeping
Utkarsh736
commited on
Commit
•
0c62e78
1
Parent(s):
61f769a
[Fix] system posixpath runtime error
Browse files- Bearify_nb.ipynb +21 -38
- app/app.py +15 -10
Bearify_nb.ipynb
CHANGED
@@ -29,8 +29,11 @@
|
|
29 |
"outputs": [],
|
30 |
"source": [
|
31 |
"#|export\n",
|
32 |
-
"
|
33 |
-
"import
|
|
|
|
|
|
|
34 |
]
|
35 |
},
|
36 |
{
|
@@ -71,36 +74,23 @@
|
|
71 |
"outputs": [],
|
72 |
"source": [
|
73 |
"#|export\n",
|
74 |
-
"
|
75 |
-
"
|
76 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
]
|
78 |
},
|
79 |
{
|
80 |
"cell_type": "code",
|
81 |
"execution_count": 5,
|
82 |
-
"metadata": {
|
83 |
-
"id": "Ko1vxtuzACNo"
|
84 |
-
},
|
85 |
-
"outputs": [],
|
86 |
-
"source": [
|
87 |
-
"#|export\n",
|
88 |
-
"learn = load_learner('bear_model.pkl')"
|
89 |
-
]
|
90 |
-
},
|
91 |
-
{
|
92 |
-
"cell_type": "code",
|
93 |
-
"execution_count": 11,
|
94 |
-
"metadata": {},
|
95 |
-
"outputs": [],
|
96 |
-
"source": [
|
97 |
-
"#|export\n",
|
98 |
-
"pathlib.PosixPath = temp"
|
99 |
-
]
|
100 |
-
},
|
101 |
-
{
|
102 |
-
"cell_type": "code",
|
103 |
-
"execution_count": 7,
|
104 |
"metadata": {
|
105 |
"colab": {
|
106 |
"base_uri": "https://localhost:8080/",
|
@@ -139,14 +129,7 @@
|
|
139 |
},
|
140 |
{
|
141 |
"data": {
|
142 |
-
"text/html": [
|
143 |
-
"\n",
|
144 |
-
" <div>\n",
|
145 |
-
" <progress value='0' class='' max='1' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
|
146 |
-
" 0.00% [0/1 00:00<?]\n",
|
147 |
-
" </div>\n",
|
148 |
-
" "
|
149 |
-
],
|
150 |
"text/plain": [
|
151 |
"<IPython.core.display.HTML object>"
|
152 |
]
|
@@ -160,7 +143,7 @@
|
|
160 |
"('black', tensor(0), tensor([9.9997e-01, 2.5549e-05, 4.9422e-07]))"
|
161 |
]
|
162 |
},
|
163 |
-
"execution_count":
|
164 |
"metadata": {},
|
165 |
"output_type": "execute_result"
|
166 |
}
|
@@ -339,7 +322,7 @@
|
|
339 |
},
|
340 |
{
|
341 |
"cell_type": "code",
|
342 |
-
"execution_count":
|
343 |
"metadata": {},
|
344 |
"outputs": [
|
345 |
{
|
@@ -383,7 +366,7 @@
|
|
383 |
"name": "python",
|
384 |
"nbconvert_exporter": "python",
|
385 |
"pygments_lexer": "ipython3",
|
386 |
-
"version": "3.
|
387 |
}
|
388 |
},
|
389 |
"nbformat": 4,
|
|
|
29 |
"outputs": [],
|
30 |
"source": [
|
31 |
"#|export\n",
|
32 |
+
"import os\n",
|
33 |
+
"import pathlib\n",
|
34 |
+
"\n",
|
35 |
+
"import gradio as gr\n",
|
36 |
+
"from fastai.vision.all import *"
|
37 |
]
|
38 |
},
|
39 |
{
|
|
|
74 |
"outputs": [],
|
75 |
"source": [
|
76 |
"#|export\n",
|
77 |
+
"\n",
|
78 |
+
"# Check the operating system\n",
|
79 |
+
"if os.name == 'nt': # 'nt' is the name for Windows NT (Windows)\n",
|
80 |
+
" temp = pathlib.PosixPath\n",
|
81 |
+
" pathlib.PosixPath = pathlib.WindowsPath\n",
|
82 |
+
"\n",
|
83 |
+
"# Load the learner model\n",
|
84 |
+
"learn = load_learner('bear_model.pkl')\n",
|
85 |
+
"\n",
|
86 |
+
"# Restore the original PosixPath if running on Windows\n",
|
87 |
+
"if os.name == 'nt':\n",
|
88 |
+
" pathlib.PosixPath = temp"
|
89 |
]
|
90 |
},
|
91 |
{
|
92 |
"cell_type": "code",
|
93 |
"execution_count": 5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
"metadata": {
|
95 |
"colab": {
|
96 |
"base_uri": "https://localhost:8080/",
|
|
|
129 |
},
|
130 |
{
|
131 |
"data": {
|
132 |
+
"text/html": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
"text/plain": [
|
134 |
"<IPython.core.display.HTML object>"
|
135 |
]
|
|
|
143 |
"('black', tensor(0), tensor([9.9997e-01, 2.5549e-05, 4.9422e-07]))"
|
144 |
]
|
145 |
},
|
146 |
+
"execution_count": 5,
|
147 |
"metadata": {},
|
148 |
"output_type": "execute_result"
|
149 |
}
|
|
|
322 |
},
|
323 |
{
|
324 |
"cell_type": "code",
|
325 |
+
"execution_count": 6,
|
326 |
"metadata": {},
|
327 |
"outputs": [
|
328 |
{
|
|
|
366 |
"name": "python",
|
367 |
"nbconvert_exporter": "python",
|
368 |
"pygments_lexer": "ipython3",
|
369 |
+
"version": "3.10.9"
|
370 |
}
|
371 |
},
|
372 |
"nbformat": 4,
|
app/app.py
CHANGED
@@ -1,31 +1,36 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../Bearify_nb.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['
|
5 |
|
6 |
# %% ../Bearify_nb.ipynb 2
|
7 |
-
|
|
|
|
|
8 |
import gradio as gr
|
|
|
9 |
|
10 |
# %% ../Bearify_nb.ipynb 4
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
#
|
16 |
learn = load_learner('bear_model.pkl')
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
20 |
|
21 |
-
# %% ../Bearify_nb.ipynb
|
22 |
categories = ('Black', 'Grizzly', 'Teddy')
|
23 |
|
24 |
def classify_image(img):
|
25 |
pred, idx, probs = learn.predict(img)
|
26 |
return dict(zip(categories, map(float, probs)))
|
27 |
|
28 |
-
# %% ../Bearify_nb.ipynb
|
29 |
image = gr.Image()
|
30 |
labels = gr.Label()
|
31 |
examples = ['Images/teddy.jpg', 'Images/grizzly.jpg', 'Images/black.jpeg']
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../Bearify_nb.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'labels', 'examples', 'intf', 'classify_image']
|
5 |
|
6 |
# %% ../Bearify_nb.ipynb 2
|
7 |
+
import os
|
8 |
+
import pathlib
|
9 |
+
|
10 |
import gradio as gr
|
11 |
+
from fastai.vision.all import *
|
12 |
|
13 |
# %% ../Bearify_nb.ipynb 4
|
14 |
+
# Check the operating system
|
15 |
+
if os.name == 'nt': # 'nt' is the name for Windows NT (Windows)
|
16 |
+
temp = pathlib.PosixPath
|
17 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
18 |
|
19 |
+
# Load the learner model
|
20 |
learn = load_learner('bear_model.pkl')
|
21 |
|
22 |
+
# Restore the original PosixPath if running on Windows
|
23 |
+
if os.name == 'nt':
|
24 |
+
pathlib.PosixPath = temp
|
25 |
|
26 |
+
# %% ../Bearify_nb.ipynb 6
|
27 |
categories = ('Black', 'Grizzly', 'Teddy')
|
28 |
|
29 |
def classify_image(img):
|
30 |
pred, idx, probs = learn.predict(img)
|
31 |
return dict(zip(categories, map(float, probs)))
|
32 |
|
33 |
+
# %% ../Bearify_nb.ipynb 8
|
34 |
image = gr.Image()
|
35 |
labels = gr.Label()
|
36 |
examples = ['Images/teddy.jpg', 'Images/grizzly.jpg', 'Images/black.jpeg']
|