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="
" 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()