File size: 817 Bytes
47031ed
adf4963
47031ed
e6877e8
 
 
 
adf4963
41e632f
47031ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6877e8
7d198bf
47031ed
 
 
 
 
 
 
 
 
 
f93a188
adf4963
 
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
35
36
37
38
39
40
41
42
from fastai.vision import *
import gradio as gr
from pathlib import Path
from fastbook import load_learner

model_path = Path('models')
image_path = Path('images')

learn = load_learner(model_path/'cloudmodel.pk1')

categories = (
  'Cirrus', 
  'Cirrostratus',
  'Cirrocumulus',
  'Altostratus',
  'Altocumulus',
  'Stratus',
  'Stratocumulus',
  'Nimbostratus',
  'Cumulus',
  'Cumulonimbus',
  'Lenticular'
)

image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()

learn = load_learner(model_path/'cloudmodel.pkl')
examples = [image_path / f"{c}.jpg" for c in categories]

def classify_image(img):
   pred,idx,probs = learn.predict(img)
   return dict(zip(categories, map(float, probs)))


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

iface.launch()