File size: 1,133 Bytes
3602056
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import *
import gradio as gr

path = Path()
path.ls(file_exts='.pkl')
learn = load_learner(path/'model.pkl')

labels = {
        "cirrus": "Cirrus (Federwolke)",
        "cirrocumulus": "Cirrocumulus (kleine SchΓ€fchenwolke)",
        "cirrostratus": "Cirrostratus (hohe Schleierwolke)",
        "altocumulus": "Altocumulus (große SchÀfchenwolke)",
        "altostratus": "Altostratus (mittelhohe Schichtwolke)",
        "stratocumulus": "Stratocumulus (Haufenschichtwolke)",
        "stratus": "Stratus (tiefe Schichtwolke)",
        "cumulus": "Cumulus (Haufenwolke)",
        "nimbostratus": "Nimbostratus (Regenwolke)",
        "cumulonimbus": "Cumulonimbus (Gewitterwolke)"
        }

def predict_cloud_class(img):
  cloudtype,_,probs = learn.predict(PILImage.create(img))
  return {labels[learn.dls.vocab[i]]: float(probs[i]) for i in range(len(learn.dls.vocab))}

image = gr.inputs.Image()
label = gr.outputs.Label(num_top_classes=5)
gr.Interface(fn=predict_cloud_class, inputs=image, outputs=label,examples=["test_cirrus.jpg","test_cumulus.jpg","test_altocumulus.jpg"]).launch(server_name="0.0.0.0")