GV05/pets
0
1import gradio as gr2from fastai.vision.all import *3"""4Hello world gradio5 6def greet(name):7 return "Hello " + name + "!!"8 9iface = gr.Interface(fn=greet, inputs="text", outputs="text")10iface.launch()11"""12 13learn = load_learner('pet_model.pkl')14 15categories = ('Abyssinian', 'Bengal', 'Birman', 'Bombay', 'British_Shorthair', 'Egyptian_Mau', 'Maine_Coon', 'Persian', 'Ragdoll', 'Russian_Blue', 'Siamese', 'Sphynx', 'american_bulldog', 'american_pit_bull_terrier', 'basset_hound', 'beagle', 'boxer', 'chihuahua', 'english_cocker_spaniel', 'english_setter', 'german_shorthaired', 'great_pyrenees', 'havanese', 'japanese_chin', 'keeshond', 'leonberger', 'miniature_pinscher', 'newfoundland', 'pomeranian', 'pug', 'saint_bernard', 'samoyed', 'scottish_terrier', 'shiba_inu', 'staffordshire_bull_terrier', 'wheaten_terrier', 'yorkshire_terrier')16 17def classify_image(img):18 _ ,_ ,probs = learn.predict(img)19 return dict(zip(categories, map(float, probs)))20 21image = gr.inputs.Image(shape=(192,192))22label = gr.outputs.Label()23examples = ['bengal.jpg', 'pug.jpg']24 25intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)26intf.launch(inline=False)27 