File size: 1,546 Bytes
b98f3e7
d9c1348
 
b98f3e7
d9c1348
 
b98f3e7
d9c1348
 
 
 
 
 
 
 
 
 
 
 
0ddebba
 
 
 
d9c1348
c82d0ec
 
 
 
d9c1348
0ddebba
d9c1348
 
 
 
 
 
 
 
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
import gradio as gr
from fastai.vision.all import *
import skimage

# TODO: put the export.pkl in the dir, I guesss
learn = load_learner('export.pkl')

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

# TODO: looks like i have to add in a few examples as well
# "article" is a link at the bottom fo the demo -- the original author put a link to blog post
title = "Cloud Classifier"
description = "A cloud classifier trained on resnet18 and ~300 clouds from duck duck go with fastai. Created as a Lesson 2 assignment in the Practical Deep Learning course."
# article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
examples = ['lenticular.jpg', 'kelvin-helmholtz.jpg', 'mammatus.jpg']

# these args are apparently outdated; my app is not loading on hf with them
#interpretation='default'
#enable_queue=True

# this is apparently a fix for current gradio
inputs=gr.Image(type="pil")
outputs=gr.Label(num_top_classes=3)

# i just separated this out into two lines the way the example has instead of the way the tutorial suggested
cloud_inference_app = gr.Interface(fn=predict,inputs=inputs,outputs=outputs,title=title,description=description,examples=examples)
cloud_inference_app.launch()


#def greet(name):
#    return "Hello " + name + "!!"

#demo = gr.Interface(fn=greet, inputs="text", outputs="text")
#demo.launch()