from fast.ai.vision.all import * import gradio as gr # def greet(name): # return "Hello " + name + "!!" # iface = gr.Interface(fn=greet, inputs="text", outputs="text") # iface.launch() # from: # https://course.fast.ai/Lessons/lesson2.html # https://github.com/fastai/fastbook/blob/master/02_production.ipynb #learn_inf = load_learner(path/'export.pkl') #learn_inf.predict('images/grizzly.jpg') #learn_inf.dls.vocab # model created from: https://www.kaggle.com/code/zachwormgoor/stock-photo-recognizer learn = load_learner('model.pkl') categories = ('stock', 'amateur') def classify(img): pred,idx,probs = learn.predict(img) return dict(zip(categories, map(float,probs))) image = gr.inputs.Image(shape=(192, 192)) label = gr.outputs.Label() examples = ['stock.jpg', 'amateur.jpg', 'unsure.jpg'] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) intf.launch(inline=False)