# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. # %% auto 0 __all__ = ['title', 'description', 'learners', 'models', 'image', 'model', 'label', 'example_images', 'example_models', 'intf', 'classify_image'] # %% app.ipynb 1 from fastai.vision.all import * import gradio as gr title = "FastAI - Big Cats Classifier" description = "Classify big cats using all Resnet models available pre-trained in FastAI" # %% app.ipynb 2 learners = { "resnet-18" : 'models/resnet18-model.pkl', "resnet-34" : 'models/resnet34-model.pkl', "resnet-50" : 'models/resnet50-model.pkl', "resnet-101": 'models/resnet101-model.pkl', "resnet-152": 'models/resnet152-model.pkl' } models = list(learners.keys()) # %% app.ipynb 3 def classify_image(img, model_file="resnet-101"): learn = load_learner(learners[model_file]) pred,idx,probs = learn.predict(img) print(pred, idx, probs) return dict(zip(learn.dls.vocab, map(float, probs))) # %% app.ipynb 5 image = gr.inputs.Image(shape=(192.192)) model = gr.inputs.Dropdown(choices=models) label = gr.outputs.Label() example_images = [ 'cheetah.jpg', 'jaguar.jpg', 'tiger.jpg', 'cougar.jpg', 'lion.jpg', 'african leopard.jpg', 'clouded leopard.jpg', 'snow leopard.jpg' ] example_models = [] #list(learners.values()) intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description ) if __name__ == "__main__": intf.launch(debug=True, inline=False)