yerx commited on
Commit
fb92045
1 Parent(s): e90f041

adding model

Browse files
Files changed (6) hide show
  1. app.ipynb +157 -0
  2. app.py +17 -4
  3. cat.webp +0 -0
  4. cat1.jpeg +0 -0
  5. dog.jpeg +0 -0
  6. dog1.webp +0 -0
app.ipynb ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "0fa79b4a",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp app"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "id": "489a7e57",
16
+ "metadata": {},
17
+ "source": [
18
+ "# Dogs v Cats"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "id": "f0ff3631",
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "#|export\n",
29
+ "from fastai.vision.all import *\n",
30
+ "import gradio as gr\n",
31
+ "\n",
32
+ "def is_cat(x): return x[0].isupper()"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": null,
38
+ "id": "84312fd2",
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "im = PILImage.create('dog.jpg')\n",
43
+ "im.thumbnail((192, 192))\n",
44
+ "im"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": null,
50
+ "id": "c0e23187",
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "#|export\n",
55
+ "learn = load_learner('model.pkl')"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": null,
61
+ "id": "8c19e825",
62
+ "metadata": {},
63
+ "outputs": [],
64
+ "source": [
65
+ "learn.predict(im)"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": null,
71
+ "id": "d678926b",
72
+ "metadata": {},
73
+ "outputs": [],
74
+ "source": [
75
+ "#|export\n",
76
+ "categories = ('Dog', 'Cat')\n",
77
+ "\n",
78
+ "def classify_image(img):\n",
79
+ " pred,idx,probs = learn.predict(img)\n",
80
+ " return dict(zip(categories, map(float,probs)))"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": null,
86
+ "id": "13fbf93e",
87
+ "metadata": {},
88
+ "outputs": [],
89
+ "source": [
90
+ "classify_image(im)"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": null,
96
+ "id": "a76c0b35",
97
+ "metadata": {},
98
+ "outputs": [],
99
+ "source": [
100
+ "#|export\n",
101
+ "image = gr.inputs.Image(shape=(192, 192))\n",
102
+ "label = gr.outputs.Label()\n",
103
+ "examples = ['/kaggle/input/dogvcat/dog.jpeg', '/kaggle/input/dogvcat/cat.webp', '/kaggle/input/dogvcat/cat1.jpeg']\n",
104
+ "\n",
105
+ "# create gradio interface\n",
106
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
107
+ "intf.launch(inline=False)"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "markdown",
112
+ "id": "465ea051",
113
+ "metadata": {},
114
+ "source": [
115
+ "# export"
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "execution_count": null,
121
+ "id": "5809c2f8",
122
+ "metadata": {},
123
+ "outputs": [],
124
+ "source": [
125
+ "# import a package to convert notebook into py file\n",
126
+ "import nbdev\n",
127
+ "nbdev.export.nb_export('app.ipynb', 'app')"
128
+ ]
129
+ }
130
+ ],
131
+ "metadata": {
132
+ "kernelspec": {
133
+ "display_name": "Python 3.x",
134
+ "language": "python",
135
+ "name": "python3"
136
+ },
137
+ "language_info": {
138
+ "codemirror_mode": {
139
+ "name": "ipython",
140
+ "version": 3
141
+ },
142
+ "file_extension": ".py",
143
+ "mimetype": "text/x-python",
144
+ "name": "python",
145
+ "nbconvert_exporter": "python",
146
+ "pygments_lexer": "ipython3",
147
+ "version": "3"
148
+ },
149
+ "vscode": {
150
+ "interpreter": {
151
+ "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
152
+ }
153
+ }
154
+ },
155
+ "nbformat": 4,
156
+ "nbformat_minor": 5
157
+ }
app.py CHANGED
@@ -1,7 +1,20 @@
 
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
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ def is_cat(x): return x[0].isupper()
 
5
 
6
+ learn = load_learner('model.pkl')
7
+
8
+ categories = ('Dog', 'Cat')
9
+
10
+ def classify_image(img):
11
+ pred,idx,probs = learn.predict(img)
12
+ return dict(zip(categories, map(float,probs)))
13
+
14
+ image = gr.inputs.Image(shape=(192, 192))
15
+ label = gr.outputs.Label()
16
+ examples = ['dog.jpeg', 'cat.webp', 'cat1.jpeg']
17
+
18
+ # create gradio interface
19
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
20
+ intf.launch(inline=False)
cat.webp ADDED
cat1.jpeg ADDED
dog.jpeg ADDED
dog1.webp ADDED