Martin Lédl commited on
Commit
bfd0d2d
1 Parent(s): 27b66cc

Add app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../pet-classifier-test.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
5
+
6
+ # %% ../pet-classifier-test.ipynb 1
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+ from huggingface_hub import hf_hub_download
10
+
11
+ def is_cat(x): return x[0].isupper()
12
+
13
+ # %% ../pet-classifier-test.ipynb 3
14
+ learn = load_learner(hf_hub_download(repo_id='sledik/doggy-catty', filename='model.pkl'))
15
+
16
+ # %% ../pet-classifier-test.ipynb 5
17
+ categories = ('Dog', 'Cat')
18
+ def classify_image(img):
19
+ pred, idx, probs = learn.predict(img)
20
+ return dict(zip(categories, map(float, probs)))
21
+
22
+ # %% ../pet-classifier-test.ipynb 7
23
+ image = gr.Image()
24
+ label = gr.Label()
25
+ #examples = ['image-2.png', 'image-5.png', 'dog-puppy.jpg', 'German-Shepherd-dog-Alsatian.jpg.webp']
26
+ examples = []
27
+
28
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
29
+ intf.launch(inline=False)