from fastbook import * from fastai.vision.all import * import gradio as gr import re def classify_gender(path): pattern = r"^man" match = re.search(pattern, Path(path).name) if match is not None and match.group() is not None: if "man" in match.group(): return "man" return "woman" learn = load_learner("model.pkl") genders = ("man", "woman") def classify_image(img): pred, idx, probs = learn.predict(img) return dict(zip(genders, map(float, probs))) image = gr.Image() label = gr.Label() intf = gr.Interface(fn = classify_image, inputs = image, outputs = label) intf.launch(inline = False, share = True)