Spaces:
Runtime error
Runtime error
Download app.py from rebolforces/jcastles: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/spaces/rebolforces/jcastles/resolve/main/app.py
- Command line
-
hf download hf://spaces/rebolforces/jcastles/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rebolforces/jcastles/resolve/main/app.py
2.36 kB
| 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=''' | |
| <p>There are many hundreds of castle sites scattered across Japan, for this demo we have trained on just 9 <a href="https://en.wikipedia.org/wiki/Tenshu">Tenshu.</a> | |
| Images sourced from my own collection and Bing Image Search. | |
| <br>Learn more about Japanese Castles and their history at | |
| <a href='https://jcastle.info/' target='_blank'>Jcastle - Guide to Japanese Castles</a>. | |
| <ul> | |
| <li><a href='https://jcastle.info/view/Hiroshima_Castle' target='_blank'>Hiroshima</a></li> | |
| <li><a href='https://jcastle.info/view/Marugame_Castle' target='_blank'>Marugame</a></li> | |
| <li><a href='https://jcastle.info/view/Matsue_Castle' target='_blank'>Matsue</a></li> | |
| <li><a href='https://jcastle.info/view/Matsumae_Castle' target='_blank'>Matsumae</a></li> | |
| <li><a href='https://jcastle.info/view/Matsumoto_Castle' target='_blank'>Matsumoto</a></li> | |
| <li><a href='https://jcastle.info/view/Nagoya_Castle' target='_blank'>Nagoya</a></li> | |
| <li><a href='https://jcastle.info/view/Okayama_Castle' target='_blank'>Okayama</a></li> | |
| <li><a href='https://jcastle.info/view/Osaka_Castle' target='_blank'>Osaka</a></li> | |
| <li><a href='https://jcastle.info/view/Shimabara_Castle' target='_blank'>Shimabara</a></li> | |
| </ul> | |
| </p> | |
| <p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Tanisq Abraham's Blog post</a> | |
| </p> | |
| </p>''' | |
| interpretation='default' #'default' None | |
| 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) | |