nkhimin commited on
Commit
4d52199
·
1 Parent(s): 55cf0b2

added categorization

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -18,11 +18,11 @@ learn = load_learner("model-export.pkl")
18
 
19
  labels = learn.dls.vocab
20
 
21
-
22
- def predict(img):
23
  img = PILImage.create(img)
24
- pred, pred_idx, probs = learn.predict(img)
25
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
26
 
27
 
28
  title = "Pet Breed Classifier"
@@ -33,7 +33,7 @@ allowed_extensions = {'.png', '.jpg', '.jpeg', '.bmp', '.gif'}
33
  examples = [file for file in path.iterdir() if file.suffix.lower() in allowed_extensions]
34
 
35
  gr.Interface(
36
- fn=predict,
37
  inputs="image",
38
  outputs="label",
39
  title=title,
 
18
 
19
  labels = learn.dls.vocab
20
 
21
+ categories = ('Dog', 'Cat')
22
+ def classify_image(img):
23
  img = PILImage.create(img)
24
+ pred,idx,probs = learn.predict(img)
25
+ return dict(zip(categories, map(float,probs)))
26
 
27
 
28
  title = "Pet Breed Classifier"
 
33
  examples = [file for file in path.iterdir() if file.suffix.lower() in allowed_extensions]
34
 
35
  gr.Interface(
36
+ fn=classify_image,
37
  inputs="image",
38
  outputs="label",
39
  title=title,