rafaared commited on
Commit
0e25d70
·
1 Parent(s): 056b7ab

fix gradio on linux

Browse files
Files changed (1) hide show
  1. app.py +6 -15
app.py CHANGED
@@ -1,24 +1,15 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
3
  import pathlib
4
- import fastai.learner
5
-
6
- def custom_load_learner(fname, cpu=True, pickle_module=pickle):
7
- """Load a Learner from file in `fname` and ensure it's using a platform-independent path."""
8
- map_loc = None if torch.cuda.is_available() and not cpu else 'cpu'
9
- try:
10
- res = torch.load(fname, map_location=map_loc, pickle_module=pickle_module)
11
- except ModuleNotFoundError as e:
12
- raise ImportError(f"{e}. To load the model on a different device, you may need to install the fastai library.")
13
-
14
- if 'WindowsPath' in str(type(res.path)):
15
- res.path = pathlib.Path(res.path)
16
-
17
- return res
18
 
19
  def is_cat(x): return x[0].isupper()
20
 
21
- learn = custom_load_learner('model.pkl')
22
 
23
  categories = ('dog', 'cat')
24
 
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
  import pathlib
4
+
5
+
6
+ plt = platform.system()
7
+ if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
8
+
 
 
 
 
 
 
 
 
 
9
 
10
  def is_cat(x): return x[0].isupper()
11
 
12
+ learn = load_learner('model.pkl')
13
 
14
  categories = ('dog', 'cat')
15