Jonathan Chen commited on
Commit
b2874ce
1 Parent(s): 1da75cd

feat: cat dog model

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -1,12 +1,29 @@
 
1
  from fastai.vision.all import *
2
 
 
 
 
3
  learn = load_learner('model.pkl')
4
 
5
  labels = learn.dls.vocab
 
 
6
  def predict(img):
7
  img = PILImage.create(img)
8
- pred,pred_idx,probs = learn.predict(img)
9
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
10
 
11
- import gradio as gr
12
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  from fastai.vision.all import *
3
 
4
+ def is_cat(x): return x[0].isupper()
5
+
6
+
7
  learn = load_learner('model.pkl')
8
 
9
  labels = learn.dls.vocab
10
+
11
+
12
  def predict(img):
13
  img = PILImage.create(img)
14
+ pred, pred_idx, probs = learn.predict(img)
15
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
 
17
+
18
+ title = "Cat or Dog Classifier"
19
+ # description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
20
+ # article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
21
+ # examples = ['siamese.jpg']
22
+ interpretation = 'default'
23
+ enable_queue = True
24
+
25
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3),
26
+ title=title,
27
+ # description=description, article=article, examples=examples,
28
+ interpretation=interpretation,
29
+ enable_queue=enable_queue).launch()