# import gradio as gr # # def greet(name): # return "Hello " + name + "!!" # # demo = gr.Interface(fn=greet, inputs="text", outputs="text") # demo.launch(share=True) # AUTOGENERATED! DO NOT EDIT! File to edit: inference-face-crop-model.ipynb. # %% auto 0 __all__ = ['learner', 'categories', 'classify_image'] # %% inference-face-crop-model.ipynb 10 from fastai.vision.all import * import gradio as gr learner = load_learner('./face-crop-model.pkl') categories = ('happy', 'other') def classify_image(img): img = img["composite"] # print(img.shape) img = img[:,:, :3] pred, idx, probs = learner.predict(img) return dict(zip(categories, map(float, probs))) with gr.Blocks() as demo: image_edit = gr.ImageEditor(type="numpy", crop_size="1:1.2", canvas_size=(300, 300)) # image = gr.Image() label = gr.Label() examples = ['happy.png', "happy2.png", "happy3.png", "happy4.png", 'other.png', 'other2.png', 'other3.png', 'other4.png', 'other5.png',] intf = gr.Interface(fn=classify_image, inputs=image_edit, outputs=label, examples=examples, description="Use crop button to resize around the face for best results") # intf.launch(inline=False) demo.launch(share=True)