Spaces:
Runtime error
Runtime error
rebolforces
commited on
Commit
•
ed57d4d
1
Parent(s):
71ee2bb
Upload app.py
Browse files
app.py
CHANGED
@@ -8,4 +8,38 @@ labels = learn.dls.vocab
|
|
8 |
def predict(img):
|
9 |
img = PILImage.create(img)
|
10 |
pred,pred_idx,probs = learn.predict(img)
|
11 |
-
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def predict(img):
|
9 |
img = PILImage.create(img)
|
10 |
pred,pred_idx,probs = learn.predict(img)
|
11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
12 |
+
|
13 |
+
title = "Japanese Castle (Tenshu) Classifier"
|
14 |
+
description = '''A castle classifier trained on a small set of Japanese Castles with fastai.
|
15 |
+
Demo for Gradio and HuggingFace Spaces. Based on blog and demo from Tanisq Abraham. Example images below are from jcastle.info.'''
|
16 |
+
|
17 |
+
# link
|
18 |
+
article='''
|
19 |
+
<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>
|
20 |
+
Images sourced from my own collection and Bing Image Search.
|
21 |
+
<br>Learn more about Japanese Castles and their history at
|
22 |
+
<a href='https://jcastle.info/' target='_blank'>Jcastle - Guide to Japanese Castles</a>.
|
23 |
+
<ul>
|
24 |
+
<li><a href='https://jcastle.info/view/Hiroshima_Castle' target='_blank'>Hiroshima</a></li>
|
25 |
+
<li><a href='https://jcastle.info/view/Marugame_Castle' target='_blank'>Marugame</a></li>
|
26 |
+
<li><a href='https://jcastle.info/view/Matsue_Castle' target='_blank'>Matsue</a></li>
|
27 |
+
<li><a href='https://jcastle.info/view/Matsumae_Castle' target='_blank'>Matsumae</a></li>
|
28 |
+
<li><a href='https://jcastle.info/view/Matsumoto_Castle' target='_blank'>Matsumoto</a></li>
|
29 |
+
<li><a href='https://jcastle.info/view/Nagoya_Castle' target='_blank'>Nagoya</a></li>
|
30 |
+
<li><a href='https://jcastle.info/view/Okayama_Castle' target='_blank'>Okayama</a></li>
|
31 |
+
<li><a href='https://jcastle.info/view/Osaka_Castle' target='_blank'>Osaka</a></li>
|
32 |
+
<li><a href='https://jcastle.info/view/Shimabara_Castle' target='_blank'>Shimabara</a></li>
|
33 |
+
</ul>
|
34 |
+
|
35 |
+
</p>
|
36 |
+
<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Tanisq Abraham's Blog post</a>
|
37 |
+
</p>
|
38 |
+
</p>'''
|
39 |
+
|
40 |
+
interpretation='default'
|
41 |
+
examples = ['osaka.jpg','matsumoto.jpg','nagoya.jpg','okayama.jpg','shimabara.jpg']
|
42 |
+
enable_queue=True
|
43 |
+
share = False
|
44 |
+
|
45 |
+
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)
|