NicolasvonRotz commited on
Commit
89e0eb8
·
1 Parent(s): 9c4c3c4
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -1,24 +1,18 @@
1
- __all__ = ['models', 'image', 'label', 'examples', 'intf']
2
-
3
  import gradio as gr
4
  from fastai.vision.all import load_learner
5
 
6
- models = [
7
- load_learner('model-color.pkl'),
8
- load_learner('bricks-model.pkl')
9
- ]
10
 
11
- def classify_image(img):
12
- results = {}
13
- for i, learn in enumerate(models):
14
- categories = learn.dls.vocab
15
- pred, idx, probs = learn.predict(img)
16
- results[f'model{i+1}'] = dict(zip(categories, map(float,probs)))
17
- return results
18
 
19
  image = gr.inputs.Image(shape=(256, 256))
20
- label = gr.outputs.Label()
21
- examples = []
22
 
23
- intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
24
- intf.launch(inline=False)
 
 
 
1
  import gradio as gr
2
  from fastai.vision.all import load_learner
3
 
4
+ def classify_image_color(img):
5
+ learn_color = load_learner('lego-bricks-detecter-model-color.pkl')
6
+ pred,_,probs = learn_color.predict(img)
7
+ return dict(zip(learn_color.dls.vocab, map(float,probs)))
8
 
9
+ def classify_image_shape(img):
10
+ learn_shape = load_learner('lego-bricks-detecter-model-shape.pkl')
11
+ pred,_,probs = learn_shape.predict(img)
12
+ return dict(zip(learn_shape.dls.vocab, map(float,probs)))
 
 
 
13
 
14
  image = gr.inputs.Image(shape=(256, 256))
15
+ label = gr.outputs.Label(num_top_classes=3)
 
16
 
17
+ intf = gr.Interface(fn=[classify_image_color, classify_image_shape], inputs=image, outputs=label, examples="", title="Lego Brick Classifier", layout="vertical")
18
+ intf.launch(share=True)