AItool commited on
Commit
b6384f9
·
verified ·
1 Parent(s): 5702361

pasted from history

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,30 +1,35 @@
1
- __all__ = ['is_real', 'learn', 'virtual staging', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
2
  import pathlib
3
-
 
4
  #|export
5
  #fastai has to be available, i.e. fastai folder
6
  from fastai.vision.all import *
7
  import gradio as gr
 
 
 
 
8
 
9
  def is_real(x): return x[0].isupper()
10
 
11
- # Cell
12
  learn = load_learner('model.pkl')
13
 
14
  #|export
15
  categories =('Virtual Staging','Real')
16
 
17
  def classify_image(img):
18
- pred,idx,probs = learn.predict(img)
19
  return dict(zip(categories,map(float,probs)))
20
 
21
  #*** We have to cast to float above because KAGGLE does not return number on the answer it returns tensors, and Gradio does not deal with numpy so we have to cast to float
22
 
23
  #|export
24
-
 
25
  image = gr.inputs.Image(shape=(192,192))
26
  label = gr.outputs.Label()
27
  examples = ['virtual.jpg','real.jpg']
28
 
29
  intf = gr.Interface(fn=classify_image,inputs=image,outputs=label,examples=examples)
30
- intf.launch(inline=False)
 
 
1
  import pathlib
2
+ temp = pathlib.PosixPath
3
+ pathlib.PosixPath = pathlib.WindowsPath
4
  #|export
5
  #fastai has to be available, i.e. fastai folder
6
  from fastai.vision.all import *
7
  import gradio as gr
8
+ import pickle
9
+
10
+ with open('./model.pkl', 'rb') as f:
11
+ model = pickle.load(f)
12
 
13
  def is_real(x): return x[0].isupper()
14
 
15
+ #|export
16
  learn = load_learner('model.pkl')
17
 
18
  #|export
19
  categories =('Virtual Staging','Real')
20
 
21
  def classify_image(img):
22
+ pred,idx,probs = learn.predict(im)
23
  return dict(zip(categories,map(float,probs)))
24
 
25
  #*** We have to cast to float above because KAGGLE does not return number on the answer it returns tensors, and Gradio does not deal with numpy so we have to cast to float
26
 
27
  #|export
28
+ #import gradio as gr
29
+ import gradio as gr
30
  image = gr.inputs.Image(shape=(192,192))
31
  label = gr.outputs.Label()
32
  examples = ['virtual.jpg','real.jpg']
33
 
34
  intf = gr.Interface(fn=classify_image,inputs=image,outputs=label,examples=examples)
35
+ intf.launch(inline=False)