File size: 912 Bytes
ef773d2
 
3d3a72d
 
ef773d2
 
 
 
 
 
 
 
3d3a72d
ef773d2
 
 
 
 
 
 
8af97a5
a214ff8
 
8af97a5
ef773d2
 
 
 
 
 
 
 
8827d4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastai.vision.all import *
from fastai.vision.all import load_learner
import gradio as gr

fruit_labels = ('Apple', 'Apricot', 'Avocado',
                'Banana', 'Blueberry',
                'Carambola', 'Cherry', 'Fig',
                'Grape', 'Kiwi', 'Lemon',
                'Lychee', 'Mango',
                'Orange', 'Papaya',
                'Pear', 'Pineapple',
                'Raspberry', 'Strawberry', 'Watermelon')

model=load_learner("model/fruit_model_v6.pkl")

def recognize_image(image):
  pred, idx, probs = model.predict(image)
  print(pred)
  return dict(zip(fruit_labels, map(float, probs)))


image = gr.Image()
label = gr.Label()

examples = [
    'test_images/test_0.jpg',
    'test_images/test_1.jpg',
    'test_images/test_2.jpg',
    'test_images/test_4.jpeg'
]

iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
iface.launch(inline=False)