Himgos commited on
Commit
819f285
β€’
1 Parent(s): 3f97dc3

model deployed

Browse files
Files changed (8) hide show
  1. README.md +4 -4
  2. app.ipynb +400 -0
  3. app.py +32 -0
  4. chillypotato.jpg +0 -0
  5. food.pkl +3 -0
  6. friedrice.jpg +0 -0
  7. momos.jpg +0 -0
  8. requirements.txt +4 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Food
3
- emoji: 🐠
4
- colorFrom: purple
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 3.21.0
8
  app_file: app.py
 
1
  ---
2
+ title: Fastfood
3
+ emoji: πŸ“‰
4
+ colorFrom: indigo
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.21.0
8
  app_file: app.py
app.ipynb ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|default_exp app"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 3,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "#|export\n",
19
+ "from fastai.vision.all import *\n",
20
+ "import gradio as gr"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 4,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "#|export\n",
30
+ "\n",
31
+ "learn = load_learner('food.pkl')"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 5,
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "data": {
41
+ "text/plain": [
42
+ "['burger', 'chilly potato', 'chowmein', 'french fry', 'fried rice', 'momos', 'pizza', 'spring roll']"
43
+ ]
44
+ },
45
+ "execution_count": 5,
46
+ "metadata": {},
47
+ "output_type": "execute_result"
48
+ }
49
+ ],
50
+ "source": [
51
+ "learn.dls.vocab"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 6,
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": [
60
+ "#|export\n",
61
+ "\n",
62
+ "categories = ('burger', 'chilly potato', 'chowmein', 'french fry', 'fried rice', 'momos', 'pizza', 'spring roll')\n",
63
+ "\n",
64
+ "def classify_image(img):\n",
65
+ " pred, idx, probs = learn.predict(img)\n",
66
+ " return dict(zip(categories, map(float, probs)))"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "code",
71
+ "execution_count": 7,
72
+ "metadata": {},
73
+ "outputs": [
74
+ {
75
+ "name": "stderr",
76
+ "output_type": "stream",
77
+ "text": [
78
+ "c:\\Users\\Himz\\anaconda3\\lib\\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",
79
+ " warnings.warn(\n",
80
+ "c:\\Users\\Himz\\anaconda3\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
81
+ " warnings.warn(value)\n",
82
+ "c:\\Users\\Himz\\anaconda3\\lib\\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",
83
+ " warnings.warn(\n",
84
+ "c:\\Users\\Himz\\anaconda3\\lib\\site-packages\\gradio\\deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
85
+ " warnings.warn(value)\n"
86
+ ]
87
+ },
88
+ {
89
+ "name": "stdout",
90
+ "output_type": "stream",
91
+ "text": [
92
+ "Running on local URL: http://127.0.0.1:7860\n",
93
+ "\n",
94
+ "To create a public link, set `share=True` in `launch()`.\n"
95
+ ]
96
+ },
97
+ {
98
+ "data": {
99
+ "text/plain": []
100
+ },
101
+ "execution_count": 7,
102
+ "metadata": {},
103
+ "output_type": "execute_result"
104
+ },
105
+ {
106
+ "data": {
107
+ "text/html": [
108
+ "\n",
109
+ "<style>\n",
110
+ " /* Turns off some styling */\n",
111
+ " progress {\n",
112
+ " /* gets rid of default border in Firefox and Opera. */\n",
113
+ " border: none;\n",
114
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
115
+ " background-size: auto;\n",
116
+ " }\n",
117
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
118
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
119
+ " }\n",
120
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
121
+ " background: #F44336;\n",
122
+ " }\n",
123
+ "</style>\n"
124
+ ],
125
+ "text/plain": [
126
+ "<IPython.core.display.HTML object>"
127
+ ]
128
+ },
129
+ "metadata": {},
130
+ "output_type": "display_data"
131
+ },
132
+ {
133
+ "data": {
134
+ "text/html": [],
135
+ "text/plain": [
136
+ "<IPython.core.display.HTML object>"
137
+ ]
138
+ },
139
+ "metadata": {},
140
+ "output_type": "display_data"
141
+ },
142
+ {
143
+ "data": {
144
+ "text/html": [
145
+ "\n",
146
+ "<style>\n",
147
+ " /* Turns off some styling */\n",
148
+ " progress {\n",
149
+ " /* gets rid of default border in Firefox and Opera. */\n",
150
+ " border: none;\n",
151
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
152
+ " background-size: auto;\n",
153
+ " }\n",
154
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
155
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
156
+ " }\n",
157
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
158
+ " background: #F44336;\n",
159
+ " }\n",
160
+ "</style>\n"
161
+ ],
162
+ "text/plain": [
163
+ "<IPython.core.display.HTML object>"
164
+ ]
165
+ },
166
+ "metadata": {},
167
+ "output_type": "display_data"
168
+ },
169
+ {
170
+ "data": {
171
+ "text/html": [],
172
+ "text/plain": [
173
+ "<IPython.core.display.HTML object>"
174
+ ]
175
+ },
176
+ "metadata": {},
177
+ "output_type": "display_data"
178
+ },
179
+ {
180
+ "data": {
181
+ "text/html": [
182
+ "\n",
183
+ "<style>\n",
184
+ " /* Turns off some styling */\n",
185
+ " progress {\n",
186
+ " /* gets rid of default border in Firefox and Opera. */\n",
187
+ " border: none;\n",
188
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
189
+ " background-size: auto;\n",
190
+ " }\n",
191
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
192
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
193
+ " }\n",
194
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
195
+ " background: #F44336;\n",
196
+ " }\n",
197
+ "</style>\n"
198
+ ],
199
+ "text/plain": [
200
+ "<IPython.core.display.HTML object>"
201
+ ]
202
+ },
203
+ "metadata": {},
204
+ "output_type": "display_data"
205
+ },
206
+ {
207
+ "data": {
208
+ "text/html": [],
209
+ "text/plain": [
210
+ "<IPython.core.display.HTML object>"
211
+ ]
212
+ },
213
+ "metadata": {},
214
+ "output_type": "display_data"
215
+ },
216
+ {
217
+ "data": {
218
+ "text/html": [
219
+ "\n",
220
+ "<style>\n",
221
+ " /* Turns off some styling */\n",
222
+ " progress {\n",
223
+ " /* gets rid of default border in Firefox and Opera. */\n",
224
+ " border: none;\n",
225
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
226
+ " background-size: auto;\n",
227
+ " }\n",
228
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
229
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
230
+ " }\n",
231
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
232
+ " background: #F44336;\n",
233
+ " }\n",
234
+ "</style>\n"
235
+ ],
236
+ "text/plain": [
237
+ "<IPython.core.display.HTML object>"
238
+ ]
239
+ },
240
+ "metadata": {},
241
+ "output_type": "display_data"
242
+ },
243
+ {
244
+ "data": {
245
+ "text/html": [],
246
+ "text/plain": [
247
+ "<IPython.core.display.HTML object>"
248
+ ]
249
+ },
250
+ "metadata": {},
251
+ "output_type": "display_data"
252
+ },
253
+ {
254
+ "data": {
255
+ "text/html": [
256
+ "\n",
257
+ "<style>\n",
258
+ " /* Turns off some styling */\n",
259
+ " progress {\n",
260
+ " /* gets rid of default border in Firefox and Opera. */\n",
261
+ " border: none;\n",
262
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
263
+ " background-size: auto;\n",
264
+ " }\n",
265
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
266
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
267
+ " }\n",
268
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
269
+ " background: #F44336;\n",
270
+ " }\n",
271
+ "</style>\n"
272
+ ],
273
+ "text/plain": [
274
+ "<IPython.core.display.HTML object>"
275
+ ]
276
+ },
277
+ "metadata": {},
278
+ "output_type": "display_data"
279
+ },
280
+ {
281
+ "data": {
282
+ "text/html": [],
283
+ "text/plain": [
284
+ "<IPython.core.display.HTML object>"
285
+ ]
286
+ },
287
+ "metadata": {},
288
+ "output_type": "display_data"
289
+ },
290
+ {
291
+ "data": {
292
+ "text/html": [
293
+ "\n",
294
+ "<style>\n",
295
+ " /* Turns off some styling */\n",
296
+ " progress {\n",
297
+ " /* gets rid of default border in Firefox and Opera. */\n",
298
+ " border: none;\n",
299
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
300
+ " background-size: auto;\n",
301
+ " }\n",
302
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
303
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
304
+ " }\n",
305
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
306
+ " background: #F44336;\n",
307
+ " }\n",
308
+ "</style>\n"
309
+ ],
310
+ "text/plain": [
311
+ "<IPython.core.display.HTML object>"
312
+ ]
313
+ },
314
+ "metadata": {},
315
+ "output_type": "display_data"
316
+ },
317
+ {
318
+ "data": {
319
+ "text/html": [],
320
+ "text/plain": [
321
+ "<IPython.core.display.HTML object>"
322
+ ]
323
+ },
324
+ "metadata": {},
325
+ "output_type": "display_data"
326
+ }
327
+ ],
328
+ "source": [
329
+ "#|export \n",
330
+ "image = gr.inputs.Image(shape=(224,224))\n",
331
+ "label = gr.outputs.Label()\n",
332
+ "examples = ['chillypotato.jpg', 'friedrice.jpg', 'momos.jpg']\n",
333
+ "\n",
334
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
335
+ "intf.launch(inline=False)"
336
+ ]
337
+ },
338
+ {
339
+ "attachments": {},
340
+ "cell_type": "markdown",
341
+ "metadata": {},
342
+ "source": [
343
+ "## Export"
344
+ ]
345
+ },
346
+ {
347
+ "cell_type": "code",
348
+ "execution_count": 10,
349
+ "metadata": {},
350
+ "outputs": [
351
+ {
352
+ "name": "stdout",
353
+ "output_type": "stream",
354
+ "text": [
355
+ "Successfull\n"
356
+ ]
357
+ }
358
+ ],
359
+ "source": [
360
+ "import nbdev\n",
361
+ "nbdev.export.nb_export('app.ipynb', './')\n",
362
+ "print(\"Successfull\")"
363
+ ]
364
+ },
365
+ {
366
+ "cell_type": "code",
367
+ "execution_count": null,
368
+ "metadata": {},
369
+ "outputs": [],
370
+ "source": []
371
+ }
372
+ ],
373
+ "metadata": {
374
+ "kernelspec": {
375
+ "display_name": "base",
376
+ "language": "python",
377
+ "name": "python3"
378
+ },
379
+ "language_info": {
380
+ "codemirror_mode": {
381
+ "name": "ipython",
382
+ "version": 3
383
+ },
384
+ "file_extension": ".py",
385
+ "mimetype": "text/x-python",
386
+ "name": "python",
387
+ "nbconvert_exporter": "python",
388
+ "pygments_lexer": "ipython3",
389
+ "version": "3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]"
390
+ },
391
+ "orig_nbformat": 4,
392
+ "vscode": {
393
+ "interpreter": {
394
+ "hash": "5a98ca32c900e45ba6fdf802df0386790e8919c5ffd6432e6c5973ff7369f74d"
395
+ }
396
+ }
397
+ },
398
+ "nbformat": 4,
399
+ "nbformat_minor": 2
400
+ }
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ from pathlib import *
4
+ import platform
5
+ plt = platform.system()
6
+ if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
7
+
8
+ # %% auto 0
9
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
10
+
11
+ # %% app.ipynb 1
12
+ from fastai.vision.all import *
13
+ import gradio as gr
14
+
15
+ # %% app.ipynb 2
16
+ learn = load_learner('food.pkl')
17
+
18
+ # %% app.ipynb 4
19
+ categories = ('burger', 'chilly potato', 'chowmein', 'french fry', 'fried rice', 'momos', 'pizza', 'spring roll')
20
+
21
+ def classify_image(img):
22
+ pred, idx, probs = learn.predict(img)
23
+ return dict(zip(categories, map(float, probs)))
24
+
25
+ # %% app.ipynb 5
26
+ image = gr.inputs.Image(shape=(224,224))
27
+ label = gr.outputs.Label()
28
+ examples = ['chillypotato.jpg', 'friedrice.jpg', 'momos.jpg']
29
+
30
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
31
+ intf.launch(inline=False)
32
+
chillypotato.jpg ADDED
food.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4d95502f446f40255773c718def7de31c055f0979d73054cbfdc6c9f393fbf4
3
+ size 46991909
friedrice.jpg ADDED
momos.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastai==2.7.11
2
+ gradio==3.21.0
3
+ pathlib
4
+ transformers