File size: 740 Bytes
56d3e17
 
 
 
 
 
 
 
 
 
f0f8316
379c283
 
56d3e17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379c283
56d3e17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""dogs_cats.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1M-mzhZdFQ2XWBSbLCuKzrmLsm0aLEYxQ

## Gradio Pets
"""
from fastai.vision.all import *
import gradio as gr

def is_cat(x): return x[0].isupper()


learn= load_learner('model.pk1')

categories= ('Dog', 'Cat')


def classify_image(img):
  pred,idx,probs= learn.predict(img)
  return dict(zip(categories, map(float, probs)))

im=PILImage.create('dog.jpg')
im.thumbnail((192,192))
im

learn.predict(im)

classify_image(im)

examples= ['dog.jpg', 'cat.jpg']

gr.Interface(fn=classify_image, inputs=[gr.Image(type="pil")], outputs=[gr.Label(num_top_classes=2)], examples=examples).launch()