import gradio as gr from fastai.vision.all import * import skimage learn = load_learner('export-castles.pkl') labels = learn.dls.vocab def predict(img): img = PILImage.create(img) pred,pred_idx,probs = learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} title = "Japanese Castle (Tenshu) Classifier" description = '''A castle classifier trained on a small set of Japanese Castles with fastai. Demo for Gradio and HuggingFace Spaces. Based on blog and demo from Tanisq Abraham. Example images below are from jcastle.info.''' # link article='''

There are many hundreds of castle sites scattered across Japan, for this demo we have trained on just 9 Tenshu. Images sourced from my own collection and Bing Image Search.
Learn more about Japanese Castles and their history at Jcastle - Guide to Japanese Castles.

Tanisq Abraham's Blog post

''' interpretation=None #'default' examples = ['osaka.jpg','matsumoto.jpg','nagoya.jpg','okayama.jpg','shimabara.jpg'] enable_queue=True share = False gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=9),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch(share=share)