Brandon Rowlett commited on
Commit
0f44c0e
1 Parent(s): e071a45

turning on dogs vs cats classifier

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