LF-netizen commited on
Commit
cb6f6ef
·
1 Parent(s): a085fad

change pathlib depending on os

Browse files
Files changed (2) hide show
  1. app.py +5 -3
  2. deploy.ipynb +89 -200
app.py CHANGED
@@ -3,9 +3,11 @@ from fastai.vision.all import *
3
  import gradio as gr
4
  import os
5
 
6
- import pathlib
7
- # temp = pathlib.PosixPath
8
- # pathlib.PosixPath = pathlib.WindowsPath
 
 
9
 
10
 
11
  title = 'LEGO sets&creations theme classifier'
 
3
  import gradio as gr
4
  import os
5
 
6
+ import platform
7
+ if platform.system() == 'Windows':
8
+ import pathlib
9
+ temp = pathlib.PosixPath
10
+ pathlib.PosixPath = pathlib.WindowsPath
11
 
12
 
13
  title = 'LEGO sets&creations theme classifier'
deploy.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 28,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -11,14 +11,17 @@
11
  "import gradio as gr\n",
12
  "import os\n",
13
  "\n",
14
- "import pathlib\n",
15
- "temp = pathlib.PosixPath\n",
16
- "pathlib.PosixPath = pathlib.WindowsPath"
 
 
 
17
  ]
18
  },
19
  {
20
  "cell_type": "code",
21
- "execution_count": 29,
22
  "metadata": {},
23
  "outputs": [],
24
  "source": [
@@ -42,14 +45,14 @@
42
  "label = gr.components.Label(label='Predictions')\n",
43
  "examples = [[f'test_images/{img_name}', img_name.split('2', 1)[0].capitalize(), img_name.split('.', 1)[0][-4:]] for img_name in os.listdir('test_images')]\n",
44
  "\n",
45
- "gr.Interface(fn=classify, inputs=[img, real_label, year, is_color], outputs=label, examples=examples).launch(\n",
46
- " # inline=False\n",
47
- " )"
48
  ]
49
  },
50
  {
51
  "cell_type": "code",
52
- "execution_count": 30,
53
  "metadata": {},
54
  "outputs": [],
55
  "source": [
@@ -65,14 +68,22 @@
65
  },
66
  {
67
  "cell_type": "code",
68
- "execution_count": 31,
69
  "metadata": {},
70
  "outputs": [
 
 
 
 
 
 
 
 
71
  {
72
  "name": "stdout",
73
  "output_type": "stream",
74
  "text": [
75
- "Running on local URL: http://127.0.0.1:7867\n",
76
  "\n",
77
  "To create a public link, set `share=True` in `launch()`.\n"
78
  ]
@@ -80,7 +91,7 @@
80
  {
81
  "data": {
82
  "text/html": [
83
- "<div><iframe src=\"http://127.0.0.1:7867/\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
84
  ],
85
  "text/plain": [
86
  "<IPython.core.display.HTML object>"
@@ -91,11 +102,9 @@
91
  },
92
  {
93
  "data": {
94
- "text/plain": [
95
- "(<gradio.routes.App at 0x18df584c880>, 'http://127.0.0.1:7867/', None)"
96
- ]
97
  },
98
- "execution_count": 31,
99
  "metadata": {},
100
  "output_type": "execute_result"
101
  },
@@ -126,146 +135,15 @@
126
  "metadata": {},
127
  "output_type": "display_data"
128
  },
129
- {
130
- "data": {
131
- "text/html": [],
132
- "text/plain": [
133
- "<IPython.core.display.HTML object>"
134
- ]
135
- },
136
- "metadata": {},
137
- "output_type": "display_data"
138
- },
139
- {
140
- "data": {
141
- "text/html": [
142
- "\n",
143
- "<style>\n",
144
- " /* Turns off some styling */\n",
145
- " progress {\n",
146
- " /* gets rid of default border in Firefox and Opera. */\n",
147
- " border: none;\n",
148
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
149
- " background-size: auto;\n",
150
- " }\n",
151
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
152
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
153
- " }\n",
154
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
155
- " background: #F44336;\n",
156
- " }\n",
157
- "</style>\n"
158
- ],
159
- "text/plain": [
160
- "<IPython.core.display.HTML object>"
161
- ]
162
- },
163
- "metadata": {},
164
- "output_type": "display_data"
165
- },
166
- {
167
- "data": {
168
- "text/html": [],
169
- "text/plain": [
170
- "<IPython.core.display.HTML object>"
171
- ]
172
- },
173
- "metadata": {},
174
- "output_type": "display_data"
175
- },
176
- {
177
- "data": {
178
- "text/html": [
179
- "\n",
180
- "<style>\n",
181
- " /* Turns off some styling */\n",
182
- " progress {\n",
183
- " /* gets rid of default border in Firefox and Opera. */\n",
184
- " border: none;\n",
185
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
186
- " background-size: auto;\n",
187
- " }\n",
188
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
189
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
190
- " }\n",
191
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
192
- " background: #F44336;\n",
193
- " }\n",
194
- "</style>\n"
195
- ],
196
- "text/plain": [
197
- "<IPython.core.display.HTML object>"
198
- ]
199
- },
200
- "metadata": {},
201
- "output_type": "display_data"
202
- },
203
- {
204
- "data": {
205
- "text/html": [],
206
- "text/plain": [
207
- "<IPython.core.display.HTML object>"
208
- ]
209
- },
210
- "metadata": {},
211
- "output_type": "display_data"
212
- },
213
- {
214
- "data": {
215
- "text/html": [
216
- "\n",
217
- "<style>\n",
218
- " /* Turns off some styling */\n",
219
- " progress {\n",
220
- " /* gets rid of default border in Firefox and Opera. */\n",
221
- " border: none;\n",
222
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
223
- " background-size: auto;\n",
224
- " }\n",
225
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
226
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
227
- " }\n",
228
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
229
- " background: #F44336;\n",
230
- " }\n",
231
- "</style>\n"
232
- ],
233
- "text/plain": [
234
- "<IPython.core.display.HTML object>"
235
- ]
236
- },
237
- "metadata": {},
238
- "output_type": "display_data"
239
- },
240
- {
241
- "data": {
242
- "text/html": [],
243
- "text/plain": [
244
- "<IPython.core.display.HTML object>"
245
- ]
246
- },
247
- "metadata": {},
248
- "output_type": "display_data"
249
- },
250
  {
251
  "data": {
252
  "text/html": [
253
  "\n",
254
- "<style>\n",
255
- " /* Turns off some styling */\n",
256
- " progress {\n",
257
- " /* gets rid of default border in Firefox and Opera. */\n",
258
- " border: none;\n",
259
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
260
- " background-size: auto;\n",
261
- " }\n",
262
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
263
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
264
- " }\n",
265
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
266
- " background: #F44336;\n",
267
- " }\n",
268
- "</style>\n"
269
  ],
270
  "text/plain": [
271
  "<IPython.core.display.HTML object>"
@@ -275,51 +153,62 @@
275
  "output_type": "display_data"
276
  },
277
  {
278
- "data": {
279
- "text/html": [],
280
- "text/plain": [
281
- "<IPython.core.display.HTML object>"
282
- ]
283
- },
284
- "metadata": {},
285
- "output_type": "display_data"
286
- },
287
- {
288
- "data": {
289
- "text/html": [
290
- "\n",
291
- "<style>\n",
292
- " /* Turns off some styling */\n",
293
- " progress {\n",
294
- " /* gets rid of default border in Firefox and Opera. */\n",
295
- " border: none;\n",
296
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
297
- " background-size: auto;\n",
298
- " }\n",
299
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
300
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
301
- " }\n",
302
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
303
- " background: #F44336;\n",
304
- " }\n",
305
- "</style>\n"
306
- ],
307
- "text/plain": [
308
- "<IPython.core.display.HTML object>"
309
- ]
310
- },
311
- "metadata": {},
312
- "output_type": "display_data"
313
- },
314
- {
315
- "data": {
316
- "text/html": [],
317
- "text/plain": [
318
- "<IPython.core.display.HTML object>"
319
- ]
320
- },
321
- "metadata": {},
322
- "output_type": "display_data"
 
 
 
 
 
 
 
 
 
 
 
323
  }
324
  ],
325
  "source": [
@@ -369,7 +258,7 @@
369
  ],
370
  "metadata": {
371
  "kernelspec": {
372
- "display_name": "Python 3.10.4 ('ml')",
373
  "language": "python",
374
  "name": "python3"
375
  },
@@ -383,12 +272,12 @@
383
  "name": "python",
384
  "nbconvert_exporter": "python",
385
  "pygments_lexer": "ipython3",
386
- "version": "3.10.4"
387
  },
388
  "orig_nbformat": 4,
389
  "vscode": {
390
  "interpreter": {
391
- "hash": "575b27b03c8f4938561cc9027b66655be84e7082a51e87d8eb0fbf4ab5514768"
392
  }
393
  }
394
  },
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 2,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
11
  "import gradio as gr\n",
12
  "import os\n",
13
  "\n",
14
+ "\n",
15
+ "import platform\n",
16
+ "if platform.system() == 'Windows':\n",
17
+ " import pathlib\n",
18
+ " temp = pathlib.PosixPath\n",
19
+ " pathlib.PosixPath = pathlib.WindowsPath"
20
  ]
21
  },
22
  {
23
  "cell_type": "code",
24
+ "execution_count": 3,
25
  "metadata": {},
26
  "outputs": [],
27
  "source": [
 
45
  "label = gr.components.Label(label='Predictions')\n",
46
  "examples = [[f'test_images/{img_name}', img_name.split('2', 1)[0].capitalize(), img_name.split('.', 1)[0][-4:]] for img_name in os.listdir('test_images')]\n",
47
  "\n",
48
+ "# gr.Interface(fn=classify, inputs=[img, real_label, year, is_color], outputs=label, examples=examples).launch(\n",
49
+ "# # inline=False\n",
50
+ "# )"
51
  ]
52
  },
53
  {
54
  "cell_type": "code",
55
+ "execution_count": 2,
56
  "metadata": {},
57
  "outputs": [],
58
  "source": [
 
68
  },
69
  {
70
  "cell_type": "code",
71
+ "execution_count": 3,
72
  "metadata": {},
73
  "outputs": [
74
+ {
75
+ "name": "stderr",
76
+ "output_type": "stream",
77
+ "text": [
78
+ "c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Row, please remove them: {'equal_height': True}\n",
79
+ " warnings.warn(\n"
80
+ ]
81
+ },
82
  {
83
  "name": "stdout",
84
  "output_type": "stream",
85
  "text": [
86
+ "Running on local URL: http://127.0.0.1:7860\n",
87
  "\n",
88
  "To create a public link, set `share=True` in `launch()`.\n"
89
  ]
 
91
  {
92
  "data": {
93
  "text/html": [
94
+ "<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>"
95
  ],
96
  "text/plain": [
97
  "<IPython.core.display.HTML object>"
 
102
  },
103
  {
104
  "data": {
105
+ "text/plain": []
 
 
106
  },
107
+ "execution_count": 3,
108
  "metadata": {},
109
  "output_type": "execute_result"
110
  },
 
135
  "metadata": {},
136
  "output_type": "display_data"
137
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  {
139
  "data": {
140
  "text/html": [
141
  "\n",
142
+ " <div>\n",
143
+ " <progress value='0' class='' max='1' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
144
+ " 0.00% [0/1 00:00&lt;?]\n",
145
+ " </div>\n",
146
+ " "
 
 
 
 
 
 
 
 
 
 
147
  ],
148
  "text/plain": [
149
  "<IPython.core.display.HTML object>"
 
153
  "output_type": "display_data"
154
  },
155
  {
156
+ "name": "stderr",
157
+ "output_type": "stream",
158
+ "text": [
159
+ "Traceback (most recent call last):\n",
160
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\gradio\\routes.py\", line 321, in run_predict\n",
161
+ " output = await app.blocks.process_api(\n",
162
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\gradio\\blocks.py\", line 1015, in process_api\n",
163
+ " result = await self.call_function(fn_index, inputs, iterator, request)\n",
164
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\gradio\\blocks.py\", line 856, in call_function\n",
165
+ " prediction = await anyio.to_thread.run_sync(\n",
166
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\anyio\\to_thread.py\", line 31, in run_sync\n",
167
+ " return await get_asynclib().run_sync_in_worker_thread(\n",
168
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 937, in run_sync_in_worker_thread\n",
169
+ " return await future\n",
170
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 867, in run\n",
171
+ " result = context.run(func, *args)\n",
172
+ " File \"C:\\Users\\ewafa\\AppData\\Local\\Temp\\ipykernel_20024\\986269756.py\", line 9, in classify\n",
173
+ " _, _, probs = learn_color.predict(img)\n",
174
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 313, in predict\n",
175
+ " inp,preds,_,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)\n",
176
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 300, in get_preds\n",
177
+ " self._do_epoch_validate(dl=dl)\n",
178
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 236, in _do_epoch_validate\n",
179
+ " with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelValidException)\n",
180
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 193, in _with_events\n",
181
+ " try: self(f'before_{event_type}'); f()\n",
182
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 199, in all_batches\n",
183
+ " for o in enumerate(self.dl): self.one_batch(*o)\n",
184
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 227, in one_batch\n",
185
+ " self._with_events(self._do_one_batch, 'batch', CancelBatchException)\n",
186
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 193, in _with_events\n",
187
+ " try: self(f'before_{event_type}'); f()\n",
188
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\learner.py\", line 205, in _do_one_batch\n",
189
+ " self.pred = self.model(*self.xb)\n",
190
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1194, in _call_impl\n",
191
+ " return forward_call(*input, **kwargs)\n",
192
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\container.py\", line 204, in forward\n",
193
+ " input = module(input)\n",
194
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1194, in _call_impl\n",
195
+ " return forward_call(*input, **kwargs)\n",
196
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\fastai\\vision\\learner.py\", line 177, in forward\n",
197
+ " def forward(self,x): return self.model.forward_features(x) if self.needs_pool else self.model(x)\n",
198
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\timm\\models\\convnext.py\", line 397, in forward_features\n",
199
+ " x = self.stem(x)\n",
200
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1194, in _call_impl\n",
201
+ " return forward_call(*input, **kwargs)\n",
202
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\container.py\", line 204, in forward\n",
203
+ " input = module(input)\n",
204
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1194, in _call_impl\n",
205
+ " return forward_call(*input, **kwargs)\n",
206
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\timm\\models\\layers\\norm.py\", line 67, in forward\n",
207
+ " if self._fast_norm:\n",
208
+ " File \"c:\\Users\\ewafa\\anaconda3\\envs\\ml\\lib\\site-packages\\torch\\nn\\modules\\module.py\", line 1269, in __getattr__\n",
209
+ " raise AttributeError(\"'{}' object has no attribute '{}'\".format(\n",
210
+ "AttributeError: 'LayerNorm2d' object has no attribute '_fast_norm'\n"
211
+ ]
212
  }
213
  ],
214
  "source": [
 
258
  ],
259
  "metadata": {
260
  "kernelspec": {
261
+ "display_name": "ml",
262
  "language": "python",
263
  "name": "python3"
264
  },
 
272
  "name": "python",
273
  "nbconvert_exporter": "python",
274
  "pygments_lexer": "ipython3",
275
+ "version": "3.10.8 | packaged by conda-forge | (main, Nov 24 2022, 14:07:00) [MSC v.1916 64 bit (AMD64)]"
276
  },
277
  "orig_nbformat": 4,
278
  "vscode": {
279
  "interpreter": {
280
+ "hash": "661d60981a8180246504a9562268f79cf2915497a26a99308f4a10e22604b72f"
281
  }
282
  }
283
  },