Jessica Walkenhorst commited on
Commit
72e97d4
1 Parent(s): 8b8b82b

Initial app

Browse files
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Ugly Duckling Magic Mirror
3
- emoji: 📉
4
  colorFrom: purple
5
  colorTo: blue
6
  sdk: gradio
 
1
  ---
2
  title: Ugly Duckling Magic Mirror
3
+ emoji: 🪞🦢
4
  colorFrom: purple
5
  colorTo: blue
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.learner import load_learner
2
+ import gradio as gr
3
+
4
+ MODELPATH = Path().cwd().parent/'model'/'cygnet-vs-duckling.pkl'
5
+ EXAMPLEPATH = Path().cwd().parent/'example-images'
6
+
7
+ learn = load_learner(MODELPATH)
8
+ categories = learn.dls.vocab
9
+
10
+ def classify_image(image):
11
+ _, _, probs = learn.predict(image)
12
+ return dict(zip(categories, map(float, probs)))
13
+
14
+ title = 'Mirror, mirror on the wall am I a duckling or a cygnet after all?'
15
+ description = """Hans Christian Andersen's tale of the ugly duckling tells us about the sad youth of a cygnet acidentally being brought up in a family of ducks and being ostrized for its ugliness.\n But what if the poor cygnet had a magic mirror to tell it that it was in fact a young swan after all? Machine learning to the rescue!"""
16
+
17
+ examples = EXAMPLEPATH.glob('*.jpg')
18
+
19
+ app = gr.Interface(fn=classify_image,
20
+ inputs=gr.components.Image(),
21
+ outputs=gr.components.Label(),
22
+ examples=examples,
23
+ title=title,
24
+ description=description,
25
+ allow_flagging='never')
26
+
27
+ app.launch()
example-images/duckling.jpg ADDED
model/cygnet-vs-duckling.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cd5da63d0ef57c6a6d1a5e3de87e90a4a74a7bd8f31d08f000aa0cfc8aef9bc
3
+ size 46961569