danielcodex commited on
Commit
6b57833
1 Parent(s): 382ac21

first model to prod

Browse files
Files changed (8) hide show
  1. .gitattributes +1 -0
  2. README.md +3 -3
  3. app.py +29 -0
  4. cat.jpg +3 -0
  5. dog.jpg +3 -0
  6. first_prod/__init__.py +1 -0
  7. learning.ipynb +480 -0
  8. model.pkl +3 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ *.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: First Prod
3
- emoji: 🐨
4
- colorFrom: purple
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.13.0
8
  app_file: app.py
 
1
  ---
2
  title: First Prod
3
+ emoji: 💻
4
+ colorFrom: red
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.13.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../learning.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
5
+
6
+ # %% ../learning.ipynb 1
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+
10
+ def is_cat(x: str): return x[0].isupper()
11
+
12
+ # %% ../learning.ipynb 3
13
+ learn = load_learner("model.pkl")
14
+
15
+ # %% ../learning.ipynb 7
16
+ categories = ("Dog", "Cat")
17
+
18
+ def classify_image(img):
19
+ pred, idx, probs = learn.predict(img)
20
+ return dict(zip(categories, probs))
21
+
22
+ # %% ../learning.ipynb 8
23
+ image = gr.inputs.Image(shape=(192, 192))
24
+ label = gr.outputs.Label()
25
+ examples = ["dog.jpg", "cat.jpg"]
26
+
27
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
28
+ intf.launch(inline=False, share=True)
29
+
cat.jpg ADDED

Git LFS Details

  • SHA256: 5172258042f51940f51d33725c9ac83fa32b2185b3c29c6a13c7ff7f1a9161c3
  • Pointer size: 131 Bytes
  • Size of remote file: 999 kB
dog.jpg ADDED

Git LFS Details

  • SHA256: f94666695eccf7e84ce18c2a4b34c667a66727801843aad759b72d4fa07093c1
  • Pointer size: 132 Bytes
  • Size of remote file: 1.41 MB
first_prod/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ __version__ = "0.0.1"
learning.ipynb ADDED
@@ -0,0 +1,480 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|default_exp app"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 10,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "#|export\n",
19
+ "from fastai.vision.all import *\n",
20
+ "import gradio as gr\n",
21
+ "\n",
22
+ "def is_cat(x: str): return x[0].isupper()"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 2,
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "im = PILImage.create(\"dog.jpg\")"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 11,
37
+ "metadata": {},
38
+ "outputs": [],
39
+ "source": [
40
+ "#|export\n",
41
+ "learn = load_learner(\"model.pkl\")"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 4,
47
+ "metadata": {},
48
+ "outputs": [
49
+ {
50
+ "data": {
51
+ "text/html": [
52
+ "\n",
53
+ "<style>\n",
54
+ " /* Turns off some styling */\n",
55
+ " progress {\n",
56
+ " /* gets rid of default border in Firefox and Opera. */\n",
57
+ " border: none;\n",
58
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
59
+ " background-size: auto;\n",
60
+ " }\n",
61
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
62
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
63
+ " }\n",
64
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
65
+ " background: #F44336;\n",
66
+ " }\n",
67
+ "</style>\n"
68
+ ],
69
+ "text/plain": [
70
+ "<IPython.core.display.HTML object>"
71
+ ]
72
+ },
73
+ "metadata": {},
74
+ "output_type": "display_data"
75
+ },
76
+ {
77
+ "data": {
78
+ "text/html": [],
79
+ "text/plain": [
80
+ "<IPython.core.display.HTML object>"
81
+ ]
82
+ },
83
+ "metadata": {},
84
+ "output_type": "display_data"
85
+ },
86
+ {
87
+ "data": {
88
+ "text/plain": [
89
+ "('True', TensorBase(1), TensorBase([2.0341e-14, 1.0000e+00]))"
90
+ ]
91
+ },
92
+ "execution_count": 4,
93
+ "metadata": {},
94
+ "output_type": "execute_result"
95
+ }
96
+ ],
97
+ "source": [
98
+ "learn.predict(\"cat.jpg\")"
99
+ ]
100
+ },
101
+ {
102
+ "attachments": {},
103
+ "cell_type": "markdown",
104
+ "metadata": {},
105
+ "source": [
106
+ "## this is how we will get the answer"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "execution_count": 5,
112
+ "metadata": {},
113
+ "outputs": [
114
+ {
115
+ "data": {
116
+ "text/html": [
117
+ "\n",
118
+ "<style>\n",
119
+ " /* Turns off some styling */\n",
120
+ " progress {\n",
121
+ " /* gets rid of default border in Firefox and Opera. */\n",
122
+ " border: none;\n",
123
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
124
+ " background-size: auto;\n",
125
+ " }\n",
126
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
127
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
128
+ " }\n",
129
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
130
+ " background: #F44336;\n",
131
+ " }\n",
132
+ "</style>\n"
133
+ ],
134
+ "text/plain": [
135
+ "<IPython.core.display.HTML object>"
136
+ ]
137
+ },
138
+ "metadata": {},
139
+ "output_type": "display_data"
140
+ },
141
+ {
142
+ "data": {
143
+ "text/html": [],
144
+ "text/plain": [
145
+ "<IPython.core.display.HTML object>"
146
+ ]
147
+ },
148
+ "metadata": {},
149
+ "output_type": "display_data"
150
+ },
151
+ {
152
+ "data": {
153
+ "text/plain": [
154
+ "{'dog': 2.0341067629640712e-14, 'cat': 1.0}"
155
+ ]
156
+ },
157
+ "execution_count": 5,
158
+ "metadata": {},
159
+ "output_type": "execute_result"
160
+ }
161
+ ],
162
+ "source": [
163
+ "pred, idx, probs = learn.predict(\"cat.jpg\")\n",
164
+ "a = [\"dog\", \"cat\"]\n",
165
+ "dict(zip(a,map(float, probs)))"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 12,
171
+ "metadata": {},
172
+ "outputs": [],
173
+ "source": [
174
+ "#|export\n",
175
+ "categories = (\"Dog\", \"Cat\")\n",
176
+ "\n",
177
+ "def classify_image(img):\n",
178
+ " pred, idx, probs = learn.predict(img)\n",
179
+ " return dict(zip(categories, map(float, probs)))"
180
+ ]
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "execution_count": 13,
185
+ "metadata": {},
186
+ "outputs": [
187
+ {
188
+ "name": "stderr",
189
+ "output_type": "stream",
190
+ "text": [
191
+ "/home/danielcodex/.local/lib/python3.9/site-packages/gradio/inputs.py:256: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
192
+ " warnings.warn(\n",
193
+ "/home/danielcodex/.local/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
194
+ " warnings.warn(value)\n",
195
+ "/home/danielcodex/.local/lib/python3.9/site-packages/gradio/outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
196
+ " warnings.warn(\n",
197
+ "/home/danielcodex/.local/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
198
+ " warnings.warn(value)\n"
199
+ ]
200
+ },
201
+ {
202
+ "name": "stdout",
203
+ "output_type": "stream",
204
+ "text": [
205
+ "Running on local URL: http://127.0.0.1:7861\n",
206
+ "\n",
207
+ "To create a public link, set `share=True` in `launch()`.\n"
208
+ ]
209
+ },
210
+ {
211
+ "data": {
212
+ "text/plain": []
213
+ },
214
+ "execution_count": 13,
215
+ "metadata": {},
216
+ "output_type": "execute_result"
217
+ }
218
+ ],
219
+ "source": [
220
+ "#|export\n",
221
+ "image = gr.inputs.Image(shape=(192, 192))\n",
222
+ "label = gr.outputs.Label()\n",
223
+ "examples = [\"dog.jpg\", \"cat.jpg\"]\n",
224
+ "\n",
225
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
226
+ "intf.launch(inline=False)\n"
227
+ ]
228
+ },
229
+ {
230
+ "cell_type": "code",
231
+ "execution_count": 17,
232
+ "metadata": {},
233
+ "outputs": [
234
+ {
235
+ "name": "stdout",
236
+ "output_type": "stream",
237
+ "text": [
238
+ "export successful\n"
239
+ ]
240
+ },
241
+ {
242
+ "data": {
243
+ "text/html": [
244
+ "\n",
245
+ "<style>\n",
246
+ " /* Turns off some styling */\n",
247
+ " progress {\n",
248
+ " /* gets rid of default border in Firefox and Opera. */\n",
249
+ " border: none;\n",
250
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
251
+ " background-size: auto;\n",
252
+ " }\n",
253
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
254
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
255
+ " }\n",
256
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
257
+ " background: #F44336;\n",
258
+ " }\n",
259
+ "</style>\n"
260
+ ],
261
+ "text/plain": [
262
+ "<IPython.core.display.HTML object>"
263
+ ]
264
+ },
265
+ "metadata": {},
266
+ "output_type": "display_data"
267
+ },
268
+ {
269
+ "data": {
270
+ "text/html": [],
271
+ "text/plain": [
272
+ "<IPython.core.display.HTML object>"
273
+ ]
274
+ },
275
+ "metadata": {},
276
+ "output_type": "display_data"
277
+ },
278
+ {
279
+ "data": {
280
+ "text/html": [
281
+ "\n",
282
+ "<style>\n",
283
+ " /* Turns off some styling */\n",
284
+ " progress {\n",
285
+ " /* gets rid of default border in Firefox and Opera. */\n",
286
+ " border: none;\n",
287
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
288
+ " background-size: auto;\n",
289
+ " }\n",
290
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
291
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
292
+ " }\n",
293
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
294
+ " background: #F44336;\n",
295
+ " }\n",
296
+ "</style>\n"
297
+ ],
298
+ "text/plain": [
299
+ "<IPython.core.display.HTML object>"
300
+ ]
301
+ },
302
+ "metadata": {},
303
+ "output_type": "display_data"
304
+ },
305
+ {
306
+ "data": {
307
+ "text/html": [],
308
+ "text/plain": [
309
+ "<IPython.core.display.HTML object>"
310
+ ]
311
+ },
312
+ "metadata": {},
313
+ "output_type": "display_data"
314
+ },
315
+ {
316
+ "data": {
317
+ "text/html": [
318
+ "\n",
319
+ "<style>\n",
320
+ " /* Turns off some styling */\n",
321
+ " progress {\n",
322
+ " /* gets rid of default border in Firefox and Opera. */\n",
323
+ " border: none;\n",
324
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
325
+ " background-size: auto;\n",
326
+ " }\n",
327
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
328
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
329
+ " }\n",
330
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
331
+ " background: #F44336;\n",
332
+ " }\n",
333
+ "</style>\n"
334
+ ],
335
+ "text/plain": [
336
+ "<IPython.core.display.HTML object>"
337
+ ]
338
+ },
339
+ "metadata": {},
340
+ "output_type": "display_data"
341
+ },
342
+ {
343
+ "data": {
344
+ "text/html": [],
345
+ "text/plain": [
346
+ "<IPython.core.display.HTML object>"
347
+ ]
348
+ },
349
+ "metadata": {},
350
+ "output_type": "display_data"
351
+ },
352
+ {
353
+ "data": {
354
+ "text/html": [
355
+ "\n",
356
+ "<style>\n",
357
+ " /* Turns off some styling */\n",
358
+ " progress {\n",
359
+ " /* gets rid of default border in Firefox and Opera. */\n",
360
+ " border: none;\n",
361
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
362
+ " background-size: auto;\n",
363
+ " }\n",
364
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
365
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
366
+ " }\n",
367
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
368
+ " background: #F44336;\n",
369
+ " }\n",
370
+ "</style>\n"
371
+ ],
372
+ "text/plain": [
373
+ "<IPython.core.display.HTML object>"
374
+ ]
375
+ },
376
+ "metadata": {},
377
+ "output_type": "display_data"
378
+ },
379
+ {
380
+ "data": {
381
+ "text/html": [],
382
+ "text/plain": [
383
+ "<IPython.core.display.HTML object>"
384
+ ]
385
+ },
386
+ "metadata": {},
387
+ "output_type": "display_data"
388
+ },
389
+ {
390
+ "data": {
391
+ "text/html": [
392
+ "\n",
393
+ "<style>\n",
394
+ " /* Turns off some styling */\n",
395
+ " progress {\n",
396
+ " /* gets rid of default border in Firefox and Opera. */\n",
397
+ " border: none;\n",
398
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
399
+ " background-size: auto;\n",
400
+ " }\n",
401
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
402
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
403
+ " }\n",
404
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
405
+ " background: #F44336;\n",
406
+ " }\n",
407
+ "</style>\n"
408
+ ],
409
+ "text/plain": [
410
+ "<IPython.core.display.HTML object>"
411
+ ]
412
+ },
413
+ "metadata": {},
414
+ "output_type": "display_data"
415
+ },
416
+ {
417
+ "data": {
418
+ "text/html": [],
419
+ "text/plain": [
420
+ "<IPython.core.display.HTML object>"
421
+ ]
422
+ },
423
+ "metadata": {},
424
+ "output_type": "display_data"
425
+ }
426
+ ],
427
+ "source": [
428
+ "import nbdev\n",
429
+ "nbdev.export.nb_export(\"learning.ipynb\", \"app\")\n",
430
+ "print(\"export successful\")\n"
431
+ ]
432
+ },
433
+ {
434
+ "cell_type": "code",
435
+ "execution_count": 8,
436
+ "metadata": {},
437
+ "outputs": [],
438
+ "source": [
439
+ "from fastdownload import download_url\n",
440
+ "from duckduckgo_search import ddg_images\n",
441
+ "\n",
442
+ "test = L(ddg_images(\"dog\", max_results=1)).itemgot(\"image\")\n",
443
+ "# download_url(test[0], \"dog.jpg\", show_progress=False)\n",
444
+ "\n",
445
+ "cat = L(ddg_images(\"cat\", max_results=1)).itemgot(\"image\")\n",
446
+ "# download_url(cat[0], \"cat.jpg\", show_progress=False)\n",
447
+ "\n",
448
+ "# dunno = L(ddg_images(\"dunno\", max_results=20)).itemgot(\"image\")\n",
449
+ "# download_url(dunno[3], \"dunno.jpg\", show_progress=False)"
450
+ ]
451
+ }
452
+ ],
453
+ "metadata": {
454
+ "kernelspec": {
455
+ "display_name": "Python 3",
456
+ "language": "python",
457
+ "name": "python3"
458
+ },
459
+ "language_info": {
460
+ "codemirror_mode": {
461
+ "name": "ipython",
462
+ "version": 3
463
+ },
464
+ "file_extension": ".py",
465
+ "mimetype": "text/x-python",
466
+ "name": "python",
467
+ "nbconvert_exporter": "python",
468
+ "pygments_lexer": "ipython3",
469
+ "version": "3.9.5"
470
+ },
471
+ "orig_nbformat": 4,
472
+ "vscode": {
473
+ "interpreter": {
474
+ "hash": "36cf16204b8548560b1c020c4e8fb5b57f0e4c58016f52f2d4be01e192833930"
475
+ }
476
+ }
477
+ },
478
+ "nbformat": 4,
479
+ "nbformat_minor": 2
480
+ }
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
3
+ size 47059947