MlKiller commited on
Commit
a17e43d
·
verified ·
1 Parent(s): 8c46262

Create dog_vs_cat.py

Browse files
Files changed (1) hide show
  1. dog_vs_cat.py +0 -58
dog_vs_cat.py CHANGED
@@ -1,58 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """Dog Vs Cat.ipynb
3
-
4
- Automatically generated by Colab.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1_3DbuTTvb83jCX-oa6nmg4bMAAyuPNdo
8
- """
9
-
10
- !pip install gradio
11
- !pip install fastbook
12
- !pip install -U duckduckgo_search
13
- !pip install --upgrade duckduckgo-search
14
-
15
- """# Dogs vs Cats"""
16
-
17
- from fastbook import *
18
- from fastai.vision.all import *
19
- import gradio as gr
20
-
21
- def is_cat(x) : return x[0].isupper
22
-
23
- urls = search_images_ddg('dog', max_images=1)
24
- dest = 'images/dogs.jpg'
25
- download_url(dest = dest, url=urls[0], show_progress=False)
26
-
27
- urls = search_images_ddg('cat', max_images=1)
28
- dest = 'images/cats.jpg'
29
- download_url(dest = dest, url=urls[0], show_progress=False)
30
-
31
- urls = search_images_ddg('animal', max_images=1)
32
- dest = 'images/dunno.jpg'
33
- download_url(dest = dest, url=urls[0], show_progress=False)
34
-
35
- im = PILImage.create('images/dogs.jpg')
36
- im.thumbnail((192,192))
37
- im
38
-
39
- learn = load_learner('model.pkl')
40
- learn.predict(im)
41
-
42
- categories = ('Dog','Cat')
43
-
44
- def classify_images(img):
45
- pred, idx, probs = learn.predict(img)
46
- return dict(zip(categories, map(float,probs)))
47
-
48
- classify_images(im)
49
-
50
- intf = gr.Interface(
51
- fn=classify_images,
52
- inputs=gr.Image(),
53
- outputs=gr.Label(),
54
- examples=['images/dogs.jpg', 'images/cats.jpg', 'images/dunno.jpg']
55
- )
56
-
57
- intf.launch()
58
-