File size: 977 Bytes
a3e0e46
 
 
 
 
 
 
bc89923
 
a3e0e46
 
 
 
 
 
 
 
 
 
 
f3f6004
ecd60a1
a3e0e46
 
 
 
 
f3f6004
 
 
a3e0e46
 
 
 
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
34
from fastai.vision.all import *
import gradio as gr
import pathlib, os

categories = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip']

def classify_image(img):
    if os.name == 'posix': # workaround for Linux
        pathlib.WindowsPath = pathlib.PosixPath 

    learn = load_learner('flowers.pkl')
    pred,idx,probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = [ 
    'dandelion+seeds.jpg',
    'common-dandelion-seeds-medical-herb-taraxacum-officinale.jpg',
    'dandelion-seedhead.jpg',
    'dandelion.jpg',
    'how-to-draw-sunflower.jpg',
    'sunflower.jpg',
    'sunflower1.jpg',
    'tulip-drawing.jpg',
    'broken-tulip-flower.jpg',
    'rose01.jpg',
    'rose02-blue.jpg',
    'top-25-most-beautiful-daisy-flowers.jpg',
    'daisy-varieties.jpg'
 ]

iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
iface.launch()