mjishu commited on
Commit
23379b1
·
verified ·
1 Parent(s): 6aaf148

changed posix and windows path

Browse files
Files changed (1) hide show
  1. app.py +41 -30
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
- learn = load_learner('model.pkl')
15
-
16
-
17
- # %% app.ipynb 6
18
- options = ("grizzly", "black", "teddy")
19
-
20
- def classify_img(img):
21
- pred,idx,probs = learn.predict(img)
22
- return dict(zip(options, map(float, probs)))
23
-
24
- # %% app.ipynb 8
25
- image = gr.Image()
26
- label = gr.Label()
27
- examples = ["brown_bear.jpg", "grizzly_bear.jpg", "teddy_bear.jpg"]
28
-
29
- intf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples)
30
- intf.launch(inline=False)
 
 
 
 
 
 
 
 
 
 
 
 
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)