changed posix and windows path
Browse files
app.py
CHANGED
@@ -1,30 +1,41 @@
|
|
1 |
-
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
-
|
3 |
-
# %% auto 0
|
4 |
-
__all__ = ['learn', 'options', 'image', 'label', 'examples', 'intf', 'whichBear', 'classify_img']
|
5 |
-
|
6 |
-
# %% app.ipynb 2
|
7 |
-
from fastai.vision.all import *
|
8 |
-
import gradio as gr
|
9 |
-
|
10 |
-
|
11 |
-
def whichBear(x): return x[0].isBear()
|
12 |
-
|
13 |
-
# %% app.ipynb 4
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'options', 'image', 'label', 'examples', 'intf', 'whichBear', 'classify_img']
|
5 |
+
|
6 |
+
# %% app.ipynb 2
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
|
11 |
+
def whichBear(x): return x[0].isBear()
|
12 |
+
|
13 |
+
# %% app.ipynb 4
|
14 |
+
original_posix_path = pathlib.PosixPath
|
15 |
+
|
16 |
+
# Replace PosixPath with WindowsPath for loading the model if on a POSIX system
|
17 |
+
if platform.system().lower() != "windows":
|
18 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
19 |
+
|
20 |
+
# Load the learner
|
21 |
+
learn = load_learner("model.pkl")
|
22 |
+
|
23 |
+
# Restore the original PosixPath class
|
24 |
+
if platform.system().lower() != "windows":
|
25 |
+
pathlib.PosixPath = original_posix_path
|
26 |
+
|
27 |
+
|
28 |
+
# %% app.ipynb 6
|
29 |
+
options = ("grizzly", "black", "teddy")
|
30 |
+
|
31 |
+
def classify_img(img):
|
32 |
+
pred,idx,probs = learn.predict(img)
|
33 |
+
return dict(zip(options, map(float, probs)))
|
34 |
+
|
35 |
+
# %% app.ipynb 8
|
36 |
+
image = gr.Image()
|
37 |
+
label = gr.Label()
|
38 |
+
examples = ["brown_bear.jpg", "grizzly_bear.jpg", "teddy_bear.jpg"]
|
39 |
+
|
40 |
+
intf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples)
|
41 |
+
intf.launch(inline=False)
|