Jay Suh commited on
Commit
9fd0800
1 Parent(s): df50d76

Deploy to Hugging Face

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. export.pkl +3 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: Deployment.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'inf', 'get_y', 'classify_images']
5
+
6
+ # %% Deployment.ipynb 2
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+
10
+ def get_y(path):
11
+ return parent_label(path).split(' and ')
12
+
13
+ # %% Deployment.ipynb 3
14
+ learn = load_learner('export.pkl')
15
+
16
+ # %% Deployment.ipynb 8
17
+ categories = learn.dls.vocab
18
+ def classify_images(img):
19
+ """classifies images and returns the probabilities on each categories."""
20
+ pred, pred_idx, probs = learn.predict(img)
21
+ return dict(zip(categories, map(float, probs)))
22
+
23
+ # %% Deployment.ipynb 10
24
+ image = gr.inputs.Image(shape=(192, 192))
25
+ label = gr.outputs.Label()
26
+ # If you have more or less examples, edit this list.
27
+ examples = ['apple.jpg', 'orange.jpg', 'pear.jpg', 'apple and orange.jpg',
28
+ 'pear and orange.jpg', 'apple and pear.jpg', 'apple and pear and orange.jpg',
29
+ 'random images.jpg']
30
+
31
+ inf = gr.Interface(fn=classify_images, inputs=image, outputs=label, examples=examples)
32
+ inf.launch(inline=False)
export.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06605e95bcb706a65b252f6af93629c61c1691919303fd5997a344fb1a9de8bf
3
+ size 46984683