Oleh Hnashuk commited on
Commit
814ade9
1 Parent(s): 7d5e272

gradio app

Browse files
.gitattributes CHANGED
@@ -32,3 +32,5 @@ 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
+ *.pk1 filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
.ipynb_checkpoints/app-checkpoint.ipynb ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "b0b5e6d7",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp app"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": null,
16
+ "id": "894a6707",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|export\n",
21
+ "from fastai.vision.all import *\n",
22
+ "import gradio as gr"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 2,
28
+ "id": "d9019a15",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "#|export \n",
33
+ "\n",
34
+ "categories = ('ocean', 'space', 'money')\n",
35
+ "\n",
36
+ "def classify_image(img):\n",
37
+ " pred, idx, probs = learn.predict(img)\n",
38
+ " return dict(zip(categories, map(float, probs)))"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": 3,
44
+ "id": "d04d8882",
45
+ "metadata": {},
46
+ "outputs": [
47
+ {
48
+ "ename": "NameError",
49
+ "evalue": "name 'learn' is not defined",
50
+ "output_type": "error",
51
+ "traceback": [
52
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
53
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
54
+ "Cell \u001b[0;32mIn[3], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m im \u001b[38;5;241m=\u001b[39m PILImage\u001b[38;5;241m.\u001b[39mcreate(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mocean.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mclassify_image\u001b[49m\u001b[43m(\u001b[49m\u001b[43mim\u001b[49m\u001b[43m)\u001b[49m\n",
55
+ "Cell \u001b[0;32mIn[2], line 6\u001b[0m, in \u001b[0;36mclassify_image\u001b[0;34m(img)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mclassify_image\u001b[39m(img):\n\u001b[0;32m----> 6\u001b[0m pred, idx, probs \u001b[38;5;241m=\u001b[39m \u001b[43mlearn\u001b[49m\u001b[38;5;241m.\u001b[39mpredict(img)\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mdict\u001b[39m(\u001b[38;5;28mzip\u001b[39m(categories, \u001b[38;5;28mmap\u001b[39m(\u001b[38;5;28mfloat\u001b[39m, probs)))\n",
56
+ "\u001b[0;31mNameError\u001b[0m: name 'learn' is not defined"
57
+ ]
58
+ }
59
+ ],
60
+ "source": [
61
+ "im = PILImage.create('ocean.jpg')\n",
62
+ "classify_image(im)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": null,
68
+ "id": "bbef2af6",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "#|export\n",
73
+ "image = gr.inputs.Image(shape=(192,192))\n",
74
+ "label = gr.outputs.Label()\n",
75
+ "examples = ['ocean.jpg', 'space.jpg', 'money.jpg']\n",
76
+ "\n",
77
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
78
+ "intf.launch(inline=False)"
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "execution_count": null,
84
+ "id": "c0c533db",
85
+ "metadata": {},
86
+ "outputs": [],
87
+ "source": []
88
+ }
89
+ ],
90
+ "metadata": {
91
+ "kernelspec": {
92
+ "display_name": "Python 3 (ipykernel)",
93
+ "language": "python",
94
+ "name": "python3"
95
+ },
96
+ "language_info": {
97
+ "codemirror_mode": {
98
+ "name": "ipython",
99
+ "version": 3
100
+ },
101
+ "file_extension": ".py",
102
+ "mimetype": "text/x-python",
103
+ "name": "python",
104
+ "nbconvert_exporter": "python",
105
+ "pygments_lexer": "ipython3",
106
+ "version": "3.8.13"
107
+ }
108
+ },
109
+ "nbformat": 4,
110
+ "nbformat_minor": 5
111
+ }
app-sample.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
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()
app.ipynb ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 12,
6
+ "id": "b0b5e6d7",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp app"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 9,
16
+ "id": "894a6707",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|export\n",
21
+ "from fastai.vision.all import *\n",
22
+ "import gradio as gr"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 4,
28
+ "id": "3308043c",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "#|export\n",
33
+ "learn = load_learner('model.pk1')"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 5,
39
+ "id": "d9019a15",
40
+ "metadata": {},
41
+ "outputs": [],
42
+ "source": [
43
+ "#|export \n",
44
+ "\n",
45
+ "categories = ('ocean', 'space', 'money')\n",
46
+ "\n",
47
+ "def classify_image(img):\n",
48
+ " pred, idx, probs = learn.predict(img)\n",
49
+ " return dict(zip(categories, map(float, probs)))"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 6,
55
+ "id": "d04d8882",
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "data": {
60
+ "text/html": [
61
+ "\n",
62
+ "<style>\n",
63
+ " /* Turns off some styling */\n",
64
+ " progress {\n",
65
+ " /* gets rid of default border in Firefox and Opera. */\n",
66
+ " border: none;\n",
67
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
68
+ " background-size: auto;\n",
69
+ " }\n",
70
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
71
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
72
+ " }\n",
73
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
74
+ " background: #F44336;\n",
75
+ " }\n",
76
+ "</style>\n"
77
+ ],
78
+ "text/plain": [
79
+ "<IPython.core.display.HTML object>"
80
+ ]
81
+ },
82
+ "metadata": {},
83
+ "output_type": "display_data"
84
+ },
85
+ {
86
+ "data": {
87
+ "text/html": [],
88
+ "text/plain": [
89
+ "<IPython.core.display.HTML object>"
90
+ ]
91
+ },
92
+ "metadata": {},
93
+ "output_type": "display_data"
94
+ },
95
+ {
96
+ "data": {
97
+ "text/plain": [
98
+ "{'ocean': 5.39313214176218e-06,\n",
99
+ " 'space': 0.9999582767486572,\n",
100
+ " 'money': 3.6335437471279874e-05}"
101
+ ]
102
+ },
103
+ "execution_count": 6,
104
+ "metadata": {},
105
+ "output_type": "execute_result"
106
+ }
107
+ ],
108
+ "source": [
109
+ "im = PILImage.create('ocean.jpg')\n",
110
+ "classify_image(im)"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 10,
116
+ "id": "bbef2af6",
117
+ "metadata": {},
118
+ "outputs": [
119
+ {
120
+ "name": "stderr",
121
+ "output_type": "stream",
122
+ "text": [
123
+ "/Users/oleh.hnashukschibsted.com/.pyenv/versions/3.8.13/lib/python3.8/site-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
124
+ " warnings.warn(\n",
125
+ "/Users/oleh.hnashukschibsted.com/.pyenv/versions/3.8.13/lib/python3.8/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
126
+ " warnings.warn(value)\n",
127
+ "/Users/oleh.hnashukschibsted.com/.pyenv/versions/3.8.13/lib/python3.8/site-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
128
+ " warnings.warn(\n",
129
+ "/Users/oleh.hnashukschibsted.com/.pyenv/versions/3.8.13/lib/python3.8/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
130
+ " warnings.warn(value)\n"
131
+ ]
132
+ },
133
+ {
134
+ "name": "stdout",
135
+ "output_type": "stream",
136
+ "text": [
137
+ "Running on local URL: http://127.0.0.1:7860\n",
138
+ "\n",
139
+ "To create a public link, set `share=True` in `launch()`.\n"
140
+ ]
141
+ },
142
+ {
143
+ "data": {
144
+ "text/plain": []
145
+ },
146
+ "execution_count": 10,
147
+ "metadata": {},
148
+ "output_type": "execute_result"
149
+ },
150
+ {
151
+ "data": {
152
+ "text/html": [
153
+ "\n",
154
+ "<style>\n",
155
+ " /* Turns off some styling */\n",
156
+ " progress {\n",
157
+ " /* gets rid of default border in Firefox and Opera. */\n",
158
+ " border: none;\n",
159
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
160
+ " background-size: auto;\n",
161
+ " }\n",
162
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
163
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
164
+ " }\n",
165
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
166
+ " background: #F44336;\n",
167
+ " }\n",
168
+ "</style>\n"
169
+ ],
170
+ "text/plain": [
171
+ "<IPython.core.display.HTML object>"
172
+ ]
173
+ },
174
+ "metadata": {},
175
+ "output_type": "display_data"
176
+ },
177
+ {
178
+ "data": {
179
+ "text/html": [],
180
+ "text/plain": [
181
+ "<IPython.core.display.HTML object>"
182
+ ]
183
+ },
184
+ "metadata": {},
185
+ "output_type": "display_data"
186
+ },
187
+ {
188
+ "data": {
189
+ "text/html": [
190
+ "\n",
191
+ "<style>\n",
192
+ " /* Turns off some styling */\n",
193
+ " progress {\n",
194
+ " /* gets rid of default border in Firefox and Opera. */\n",
195
+ " border: none;\n",
196
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
197
+ " background-size: auto;\n",
198
+ " }\n",
199
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
200
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
201
+ " }\n",
202
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
203
+ " background: #F44336;\n",
204
+ " }\n",
205
+ "</style>\n"
206
+ ],
207
+ "text/plain": [
208
+ "<IPython.core.display.HTML object>"
209
+ ]
210
+ },
211
+ "metadata": {},
212
+ "output_type": "display_data"
213
+ },
214
+ {
215
+ "data": {
216
+ "text/html": [],
217
+ "text/plain": [
218
+ "<IPython.core.display.HTML object>"
219
+ ]
220
+ },
221
+ "metadata": {},
222
+ "output_type": "display_data"
223
+ },
224
+ {
225
+ "data": {
226
+ "text/html": [
227
+ "\n",
228
+ "<style>\n",
229
+ " /* Turns off some styling */\n",
230
+ " progress {\n",
231
+ " /* gets rid of default border in Firefox and Opera. */\n",
232
+ " border: none;\n",
233
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
234
+ " background-size: auto;\n",
235
+ " }\n",
236
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
237
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
238
+ " }\n",
239
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
240
+ " background: #F44336;\n",
241
+ " }\n",
242
+ "</style>\n"
243
+ ],
244
+ "text/plain": [
245
+ "<IPython.core.display.HTML object>"
246
+ ]
247
+ },
248
+ "metadata": {},
249
+ "output_type": "display_data"
250
+ },
251
+ {
252
+ "data": {
253
+ "text/html": [],
254
+ "text/plain": [
255
+ "<IPython.core.display.HTML object>"
256
+ ]
257
+ },
258
+ "metadata": {},
259
+ "output_type": "display_data"
260
+ }
261
+ ],
262
+ "source": [
263
+ "#|export\n",
264
+ "image = gr.inputs.Image(shape=(192,192))\n",
265
+ "label = gr.outputs.Label()\n",
266
+ "examples = ['ocean.jpg', 'space.jpg', 'money.jpg']\n",
267
+ "\n",
268
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
269
+ "intf.launch(inline=False)"
270
+ ]
271
+ },
272
+ {
273
+ "cell_type": "code",
274
+ "execution_count": 14,
275
+ "id": "c0c533db",
276
+ "metadata": {},
277
+ "outputs": [],
278
+ "source": [
279
+ "import nbdev\n",
280
+ "nbdev.export.nb_export('app.ipynb', 'app')"
281
+ ]
282
+ },
283
+ {
284
+ "cell_type": "code",
285
+ "execution_count": null,
286
+ "id": "c28672b0",
287
+ "metadata": {},
288
+ "outputs": [],
289
+ "source": []
290
+ }
291
+ ],
292
+ "metadata": {
293
+ "kernelspec": {
294
+ "display_name": "Python 3 (ipykernel)",
295
+ "language": "python",
296
+ "name": "python3"
297
+ },
298
+ "language_info": {
299
+ "codemirror_mode": {
300
+ "name": "ipython",
301
+ "version": 3
302
+ },
303
+ "file_extension": ".py",
304
+ "mimetype": "text/x-python",
305
+ "name": "python",
306
+ "nbconvert_exporter": "python",
307
+ "pygments_lexer": "ipython3",
308
+ "version": "3.8.13"
309
+ }
310
+ },
311
+ "nbformat": 4,
312
+ "nbformat_minor": 5
313
+ }
app.py CHANGED
@@ -1,7 +1,26 @@
 
 
 
 
 
 
 
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
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
5
+
6
+ # %% ../app.ipynb 1
7
+ from fastai.vision.all import *
8
  import gradio as gr
9
 
10
+ # %% ../app.ipynb 2
11
+ learn = load_learner('model.pk1')
12
+
13
+ # %% ../app.ipynb 3
14
+ categories = ('ocean', 'space', 'money')
15
+
16
+ def classify_image(img):
17
+ pred, idx, probs = learn.predict(img)
18
+ return dict(zip(categories, map(float, probs)))
19
+
20
+ # %% ../app.ipynb 5
21
+ image = gr.inputs.Image(shape=(192,192))
22
+ label = gr.outputs.Label()
23
+ examples = ['ocean.jpg', 'space.jpg', 'money.jpg']
24
 
25
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
26
+ intf.launch(inline=False)
flagged/img/tmpn_vj79gf.jpg ADDED

Git LFS Details

  • SHA256: c009f390c686542768f512843ac8c0fdb2c374e5788e5590ff29d2c790f5f068
  • Pointer size: 132 Bytes
  • Size of remote file: 5.12 MB
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ img,output,flag,username,timestamp
2
+ /Users/oleh.hnashukschibsted.com/Developer/ai-academy/flagged/img/tmpn_vj79gf.jpg,/Users/oleh.hnashukschibsted.com/Developer/ai-academy/flagged/output/tmp6_fevvx2.json,,,2023-01-26 17:44:57.905355
flagged/output/tmp6_fevvx2.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"label": "ocean", "confidences": [{"label": "ocean", "confidence": 0.9999922513961792}, {"label": "space", "confidence": 4.0672466639080085e-06}, {"label": "money", "confidence": 3.702712092490401e-06}]}
model.pk1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c397fb6984c96890e13718ebd9f62f19553c56b7f2cdd6b5d861b7df89461a0c
3
+ size 46958063
money.jpg ADDED

Git LFS Details

  • SHA256: c009f390c686542768f512843ac8c0fdb2c374e5788e5590ff29d2c790f5f068
  • Pointer size: 132 Bytes
  • Size of remote file: 5.12 MB
ocean.jpg ADDED

Git LFS Details

  • SHA256: fa1306971660e7cb25cdebe5c73ba1a63795cade0ced0617a793e2fa6b60f289
  • Pointer size: 131 Bytes
  • Size of remote file: 604 kB
space.jpg ADDED

Git LFS Details

  • SHA256: 28ffd02502eec83c6617d40168037d51418bdf07f579de4f5b8523209cb769d9
  • Pointer size: 132 Bytes
  • Size of remote file: 5.62 MB