jay-k commited on
Commit
3d3e822
1 Parent(s): 421fd55

Trying out cat classifier

Browse files
Files changed (3) hide show
  1. app.py +38 -0
  2. cats_1.jpeg +0 -0
  3. image_model.pkl +3 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+
4
+ def is_cat(x): return x[0].isupper()
5
+
6
+ learn = load_learner('./image_model.pkl')
7
+
8
+ labels = learn.dls.vocab
9
+
10
+ def predict(img):
11
+ img = PILImage.create(img)
12
+ pred,pred_idx,probs = learn.predict(img)
13
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
14
+
15
+ # All Gradio interfaces are created by constructing a gradio.Interface() object
16
+ # The Interface() object takes in the function that we want to make an
17
+ # interface for (usually an ML model inference function)
18
+ # 'inputs' components (the number of input components should match
19
+ # the number of parameters of the provided function)
20
+ # 'outputs' components (the number of output components should match
21
+ # the number of values returned by the provided function)
22
+ title = "Dog Cat Classifier"
23
+ description = "A dog cat classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
24
+ article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
25
+ examples = ['./cats_1.jpeg']
26
+ interpretation='default'
27
+ enable_queue=True
28
+
29
+ gr.Interface(
30
+ fn=predict,
31
+ inputs=gr.inputs.Image(shape=(512, 512)),
32
+ outputs=gr.outputs.Label(num_top_classes=3),
33
+ title=title,
34
+ description=description,
35
+ article=article,
36
+ examples=examples,
37
+ interpretation=interpretation,
38
+ enable_queue=enable_queue).launch()
cats_1.jpeg ADDED
image_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad47ceda19b36f48dec9bbbe0f1cabd3e1fbacf855fde22c7e70eedc76540371
3
+ size 47065195