lgg commited on
Commit
2303861
·
1 Parent(s): 3d55efa

fixing bugs

Browse files
Files changed (3) hide show
  1. app.ipynb +23 -47
  2. app.py +21 -5
  3. learning_gradio/app.py +0 -23
app.ipynb CHANGED
@@ -3,7 +3,7 @@
3
  {
4
  "cell_type": "code",
5
  "execution_count": 1,
6
- "id": "e49d72ea",
7
  "metadata": {},
8
  "outputs": [],
9
  "source": [
@@ -13,7 +13,7 @@
13
  {
14
  "cell_type": "code",
15
  "execution_count": 2,
16
- "id": "6ffe5ce8",
17
  "metadata": {},
18
  "outputs": [],
19
  "source": [
@@ -24,7 +24,7 @@
24
  {
25
  "cell_type": "code",
26
  "execution_count": 3,
27
- "id": "dd7a7a33",
28
  "metadata": {},
29
  "outputs": [],
30
  "source": [
@@ -35,7 +35,7 @@
35
  {
36
  "cell_type": "code",
37
  "execution_count": 6,
38
- "id": "501504ae",
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
@@ -52,7 +52,7 @@
52
  {
53
  "cell_type": "code",
54
  "execution_count": 5,
55
- "id": "bbedafc3",
56
  "metadata": {},
57
  "outputs": [
58
  {
@@ -259,7 +259,7 @@
259
  {
260
  "cell_type": "code",
261
  "execution_count": null,
262
- "id": "321e5e2a",
263
  "metadata": {},
264
  "outputs": [],
265
  "source": []
@@ -267,7 +267,7 @@
267
  {
268
  "cell_type": "code",
269
  "execution_count": null,
270
- "id": "eab7bd30",
271
  "metadata": {},
272
  "outputs": [],
273
  "source": []
@@ -275,7 +275,7 @@
275
  {
276
  "cell_type": "code",
277
  "execution_count": null,
278
- "id": "aab565a0",
279
  "metadata": {},
280
  "outputs": [],
281
  "source": []
@@ -283,7 +283,7 @@
283
  {
284
  "cell_type": "code",
285
  "execution_count": null,
286
- "id": "1f6ef9c6",
287
  "metadata": {},
288
  "outputs": [],
289
  "source": []
@@ -291,7 +291,7 @@
291
  {
292
  "cell_type": "code",
293
  "execution_count": null,
294
- "id": "0d8b4820",
295
  "metadata": {},
296
  "outputs": [],
297
  "source": []
@@ -299,7 +299,7 @@
299
  {
300
  "cell_type": "code",
301
  "execution_count": null,
302
- "id": "29bc0545",
303
  "metadata": {},
304
  "outputs": [],
305
  "source": []
@@ -307,7 +307,7 @@
307
  {
308
  "cell_type": "code",
309
  "execution_count": null,
310
- "id": "eec30b86",
311
  "metadata": {},
312
  "outputs": [],
313
  "source": []
@@ -315,14 +315,14 @@
315
  {
316
  "cell_type": "code",
317
  "execution_count": null,
318
- "id": "da262cb1",
319
  "metadata": {},
320
  "outputs": [],
321
  "source": []
322
  },
323
  {
324
  "cell_type": "markdown",
325
- "id": "1c886008",
326
  "metadata": {},
327
  "source": [
328
  "## export notebook"
@@ -330,53 +330,29 @@
330
  },
331
  {
332
  "cell_type": "code",
333
- "execution_count": 10,
334
- "id": "e8b709a5",
335
  "metadata": {},
336
- "outputs": [
337
- {
338
- "ename": "ImportError",
339
- "evalue": "cannot import name 'notebook2script' from 'nbdev.export' (/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/nbdev/export.py)",
340
- "output_type": "error",
341
- "traceback": [
342
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
343
- "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
344
- "Cell \u001b[0;32mIn [10], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# export notebook\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mnbdev\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexport\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m notebook2script\n",
345
- "\u001b[0;31mImportError\u001b[0m: cannot import name 'notebook2script' from 'nbdev.export' (/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/nbdev/export.py)"
346
- ]
347
- }
348
- ],
349
  "source": [
350
  "# export notebook\n",
351
- "from nbdev.export import notebook2script"
352
  ]
353
  },
354
  {
355
  "cell_type": "code",
356
- "execution_count": 9,
357
- "id": "582eea60",
358
  "metadata": {},
359
- "outputs": [
360
- {
361
- "ename": "NameError",
362
- "evalue": "name 'notebook2script' is not defined",
363
- "output_type": "error",
364
- "traceback": [
365
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
366
- "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
367
- "Cell \u001b[0;32mIn [9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mnotebook2script\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mapp.ipynb\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
368
- "\u001b[0;31mNameError\u001b[0m: name 'notebook2script' is not defined"
369
- ]
370
- }
371
- ],
372
  "source": [
373
- "notebook2script('app.ipynb')"
374
  ]
375
  },
376
  {
377
  "cell_type": "code",
378
  "execution_count": null,
379
- "id": "1626b5fd",
380
  "metadata": {},
381
  "outputs": [],
382
  "source": []
 
3
  {
4
  "cell_type": "code",
5
  "execution_count": 1,
6
+ "id": "7e08d187",
7
  "metadata": {},
8
  "outputs": [],
9
  "source": [
 
13
  {
14
  "cell_type": "code",
15
  "execution_count": 2,
16
+ "id": "e449d107",
17
  "metadata": {},
18
  "outputs": [],
19
  "source": [
 
24
  {
25
  "cell_type": "code",
26
  "execution_count": 3,
27
+ "id": "7fa3f38f",
28
  "metadata": {},
29
  "outputs": [],
30
  "source": [
 
35
  {
36
  "cell_type": "code",
37
  "execution_count": 6,
38
+ "id": "ba04f1d8",
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
 
52
  {
53
  "cell_type": "code",
54
  "execution_count": 5,
55
+ "id": "5c77d812",
56
  "metadata": {},
57
  "outputs": [
58
  {
 
259
  {
260
  "cell_type": "code",
261
  "execution_count": null,
262
+ "id": "7d39cbf6",
263
  "metadata": {},
264
  "outputs": [],
265
  "source": []
 
267
  {
268
  "cell_type": "code",
269
  "execution_count": null,
270
+ "id": "02a65a7b",
271
  "metadata": {},
272
  "outputs": [],
273
  "source": []
 
275
  {
276
  "cell_type": "code",
277
  "execution_count": null,
278
+ "id": "ab54f129",
279
  "metadata": {},
280
  "outputs": [],
281
  "source": []
 
283
  {
284
  "cell_type": "code",
285
  "execution_count": null,
286
+ "id": "00153d99",
287
  "metadata": {},
288
  "outputs": [],
289
  "source": []
 
291
  {
292
  "cell_type": "code",
293
  "execution_count": null,
294
+ "id": "d3beb9d9",
295
  "metadata": {},
296
  "outputs": [],
297
  "source": []
 
299
  {
300
  "cell_type": "code",
301
  "execution_count": null,
302
+ "id": "384fdf33",
303
  "metadata": {},
304
  "outputs": [],
305
  "source": []
 
307
  {
308
  "cell_type": "code",
309
  "execution_count": null,
310
+ "id": "301ee4c4",
311
  "metadata": {},
312
  "outputs": [],
313
  "source": []
 
315
  {
316
  "cell_type": "code",
317
  "execution_count": null,
318
+ "id": "4ef0f13c",
319
  "metadata": {},
320
  "outputs": [],
321
  "source": []
322
  },
323
  {
324
  "cell_type": "markdown",
325
+ "id": "2712605e",
326
  "metadata": {},
327
  "source": [
328
  "## export notebook"
 
330
  },
331
  {
332
  "cell_type": "code",
333
+ "execution_count": 11,
334
+ "id": "217ceef9",
335
  "metadata": {},
336
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
337
  "source": [
338
  "# export notebook\n",
339
+ "from nbdev.export import nb_export"
340
  ]
341
  },
342
  {
343
  "cell_type": "code",
344
+ "execution_count": 12,
345
+ "id": "033dba80",
346
  "metadata": {},
347
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
348
  "source": [
349
+ "nb_export('app.ipynb')"
350
  ]
351
  },
352
  {
353
  "cell_type": "code",
354
  "execution_count": null,
355
+ "id": "24a6fd20",
356
  "metadata": {},
357
  "outputs": [],
358
  "source": []
app.py CHANGED
@@ -1,7 +1,23 @@
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', 'labels', 'predict']
5
+
6
+ # %% ../app.ipynb 1
7
+ # write this at the top of each cell which has to be exported to final script
8
 
9
+ # %% ../app.ipynb 2
10
+ from fastai.vision.all import *
11
 
12
+ # %% ../app.ipynb 3
13
+ # this identifies the type of classifier
14
+ learn = load_learner('export.pkl')
15
+ labels = learn.dls.vocab
16
+ def predict(img):
17
+ img = PILImage.create(img)
18
+ pred,pred_idx,probs = learn.predict(img)
19
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
20
+
21
+ # %% ../app.ipynb 4
22
+ import gradio as gr
23
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
learning_gradio/app.py DELETED
@@ -1,23 +0,0 @@
1
- # AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
2
-
3
- # %% auto 0
4
- __all__ = ['learn', 'labels', 'predict']
5
-
6
- # %% ../app.ipynb 1
7
- # write this at the top of each cell which has to be exported to final script
8
-
9
- # %% ../app.ipynb 2
10
- from fastai.vision.all import *
11
-
12
- # %% ../app.ipynb 3
13
- # this identifies the type of classifier
14
- learn = load_learner('export.pkl')
15
- labels = learn.dls.vocab
16
- def predict(img):
17
- img = PILImage.create(img)
18
- pred,pred_idx,probs = learn.predict(img)
19
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
20
-
21
- # %% ../app.ipynb 4
22
- import gradio as gr
23
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)