Sungmin Son commited on
Commit
7575b43
1 Parent(s): 12ecde9
Files changed (2) hide show
  1. Untitled-1.ipynb +246 -0
  2. model.pkl +3 -0
Untitled-1.ipynb ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|default_exp app.py\n",
10
+ "#|export\n",
11
+ "import gradio as gr\n",
12
+ "from fastai.vision.all import *\n",
13
+ "def is_cat(x): return x[0].isupper()"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 5,
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "import pathlib\n",
23
+ "temp = pathlib.PosixPath\n",
24
+ "pathlib.PosixPath = pathlib.WindowsPath"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 7,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "#|export\n",
34
+ "model_path = Path('model.pkl')\n",
35
+ "learn = load_learner(model_path)"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 8,
41
+ "metadata": {},
42
+ "outputs": [
43
+ {
44
+ "data": {
45
+ "text/html": [
46
+ "\n",
47
+ "<style>\n",
48
+ " /* Turns off some styling */\n",
49
+ " progress {\n",
50
+ " /* gets rid of default border in Firefox and Opera. */\n",
51
+ " border: none;\n",
52
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
53
+ " background-size: auto;\n",
54
+ " }\n",
55
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
56
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
57
+ " }\n",
58
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
59
+ " background: #F44336;\n",
60
+ " }\n",
61
+ "</style>\n"
62
+ ],
63
+ "text/plain": [
64
+ "<IPython.core.display.HTML object>"
65
+ ]
66
+ },
67
+ "metadata": {},
68
+ "output_type": "display_data"
69
+ },
70
+ {
71
+ "data": {
72
+ "text/html": [],
73
+ "text/plain": [
74
+ "<IPython.core.display.HTML object>"
75
+ ]
76
+ },
77
+ "metadata": {},
78
+ "output_type": "display_data"
79
+ },
80
+ {
81
+ "data": {
82
+ "text/plain": [
83
+ "('False', tensor(0), tensor([9.9983e-01, 1.6505e-04]))"
84
+ ]
85
+ },
86
+ "execution_count": 8,
87
+ "metadata": {},
88
+ "output_type": "execute_result"
89
+ }
90
+ ],
91
+ "source": [
92
+ "im = PILImage.create('dog.jpg')\n",
93
+ "im.thumbnail((192,192))\n",
94
+ "learn.predict(im)"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 9,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "#|export\n",
104
+ "categories = ('dog', 'cat')\n",
105
+ "\n",
106
+ "def classify_image(img):\n",
107
+ " pred,idx,probs = learn.predict(img)\n",
108
+ " return dict(zip(categories, map(float,probs)))\n"
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": 10,
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "data": {
118
+ "text/html": [
119
+ "\n",
120
+ "<style>\n",
121
+ " /* Turns off some styling */\n",
122
+ " progress {\n",
123
+ " /* gets rid of default border in Firefox and Opera. */\n",
124
+ " border: none;\n",
125
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
126
+ " background-size: auto;\n",
127
+ " }\n",
128
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
129
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
130
+ " }\n",
131
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
132
+ " background: #F44336;\n",
133
+ " }\n",
134
+ "</style>\n"
135
+ ],
136
+ "text/plain": [
137
+ "<IPython.core.display.HTML object>"
138
+ ]
139
+ },
140
+ "metadata": {},
141
+ "output_type": "display_data"
142
+ },
143
+ {
144
+ "data": {
145
+ "text/html": [],
146
+ "text/plain": [
147
+ "<IPython.core.display.HTML object>"
148
+ ]
149
+ },
150
+ "metadata": {},
151
+ "output_type": "display_data"
152
+ },
153
+ {
154
+ "data": {
155
+ "text/plain": [
156
+ "{'dog': 0.9998348951339722, 'cat': 0.00016504859377164394}"
157
+ ]
158
+ },
159
+ "execution_count": 10,
160
+ "metadata": {},
161
+ "output_type": "execute_result"
162
+ }
163
+ ],
164
+ "source": [
165
+ "classify_image(im)"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 11,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "name": "stdout",
175
+ "output_type": "stream",
176
+ "text": [
177
+ "Running on local URL: http://127.0.0.1:7860\n",
178
+ "\n",
179
+ "To create a public link, set `share=True` in `launch()`.\n"
180
+ ]
181
+ },
182
+ {
183
+ "data": {
184
+ "text/html": [
185
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
186
+ ],
187
+ "text/plain": [
188
+ "<IPython.core.display.HTML object>"
189
+ ]
190
+ },
191
+ "metadata": {},
192
+ "output_type": "display_data"
193
+ },
194
+ {
195
+ "data": {
196
+ "text/plain": []
197
+ },
198
+ "execution_count": 11,
199
+ "metadata": {},
200
+ "output_type": "execute_result"
201
+ }
202
+ ],
203
+ "source": [
204
+ "#|export\n",
205
+ "gr.Interface(fn = classify_image, \n",
206
+ " inputs=\"image\", \n",
207
+ " outputs=\"label\", \n",
208
+ " title = \"Dog or Cat\", \n",
209
+ " description=\"Sample workflow\", \n",
210
+ " examples = ['dog.jpg']\n",
211
+ " ).launch()"
212
+ ]
213
+ },
214
+ {
215
+ "cell_type": "code",
216
+ "execution_count": 16,
217
+ "metadata": {},
218
+ "outputs": [],
219
+ "source": [
220
+ "import nbdev\n",
221
+ "nbdev.export.nb_export('Untitled-1.ipynb', 'app.py')"
222
+ ]
223
+ }
224
+ ],
225
+ "metadata": {
226
+ "kernelspec": {
227
+ "display_name": "Python 3",
228
+ "language": "python",
229
+ "name": "python3"
230
+ },
231
+ "language_info": {
232
+ "codemirror_mode": {
233
+ "name": "ipython",
234
+ "version": 3
235
+ },
236
+ "file_extension": ".py",
237
+ "mimetype": "text/x-python",
238
+ "name": "python",
239
+ "nbconvert_exporter": "python",
240
+ "pygments_lexer": "ipython3",
241
+ "version": "3.10.0"
242
+ }
243
+ },
244
+ "nbformat": 4,
245
+ "nbformat_minor": 2
246
+ }
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac3241764fa6f9b4b1533c718a17447f93bf07fabe9a7aef2abc1b1e44144c21
3
+ size 47064830