rebolforces commited on
Commit
c415b70
1 Parent(s): 317d055

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -45
app.py CHANGED
@@ -1,45 +1,45 @@
1
- import gradio as gr
2
- from fastai.vision.all import *
3
- import skimage
4
-
5
- learn = load_learner('export-castles.pkl')
6
-
7
- 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))}
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)
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
+
5
+ learn = load_learner('export-castles.pkl')
6
+
7
+ 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))}
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=None #'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)