farcasclaudiu commited on
Commit
f97bb61
·
1 Parent(s): ad1c4b9
Files changed (3) hide show
  1. app.ipynb +125 -0
  2. app.py +44 -4
  3. old_app.py +9 -0
app.ipynb ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "Dogs vs Cats"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": null,
13
+ "metadata": {},
14
+ "outputs": [],
15
+ "source": [
16
+ "#|default_exp app\n",
17
+ "!pip install gradio"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": null,
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "#|export\n",
27
+ "from fastai.vision.all import *\n",
28
+ "import gradio as gr\n",
29
+ "\n",
30
+ "def is_cat(x): return x[0].isupper()"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": null,
36
+ "metadata": {},
37
+ "outputs": [],
38
+ "source": [
39
+ "im = PILImage.create('dog.jpg')\n",
40
+ "im.thumbnail((192,192))\n",
41
+ "im"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": null,
47
+ "metadata": {},
48
+ "outputs": [],
49
+ "source": [
50
+ "#|export\n",
51
+ "\n",
52
+ "learn = load_learner(\"model.pkl\")"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": null,
58
+ "metadata": {},
59
+ "outputs": [],
60
+ "source": [
61
+ "%time learn.predict(im)"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "execution_count": null,
67
+ "metadata": {},
68
+ "outputs": [],
69
+ "source": [
70
+ "#|export\n",
71
+ "categories = ('Dog', 'Cat')\n",
72
+ "\n",
73
+ "def classify_image(img):\n",
74
+ " pred,idx,probs = learn.predict(img)\n",
75
+ " return dict(zip(categories, map(float, probs)))"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": null,
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": [
84
+ "classify_image(im)"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": null,
90
+ "metadata": {},
91
+ "outputs": [],
92
+ "source": [
93
+ "#|export\n",
94
+ "image = gr.inputs.Image(shape=(192,192))\n",
95
+ "label = gr.outputs.Label()\n",
96
+ "examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']\n",
97
+ "\n",
98
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
99
+ "intf.launch(inline=False)"
100
+ ]
101
+ }
102
+ ],
103
+ "metadata": {
104
+ "kernelspec": {
105
+ "display_name": "myenv",
106
+ "language": "python",
107
+ "name": "python3"
108
+ },
109
+ "language_info": {
110
+ "codemirror_mode": {
111
+ "name": "ipython",
112
+ "version": 3
113
+ },
114
+ "file_extension": ".py",
115
+ "mimetype": "text/x-python",
116
+ "name": "python",
117
+ "nbconvert_exporter": "python",
118
+ "pygments_lexer": "ipython3",
119
+ "version": "3.10.12"
120
+ },
121
+ "orig_nbformat": 4
122
+ },
123
+ "nbformat": 4,
124
+ "nbformat_minor": 2
125
+ }
app.py CHANGED
@@ -1,9 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
6
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- iface.launch()
 
1
+
2
+ # %% [markdown]
3
+ # Dogs vs Cats
4
+
5
+ # %%
6
+ #|default_exp app
7
+ !pip install gradio
8
+
9
+ # %%
10
+ #|export
11
+ from fastai.vision.all import *
12
  import gradio as gr
13
 
14
+ def is_cat(x): return x[0].isupper()
15
+
16
+ # %%
17
+ im = PILImage.create('dog.jpg')
18
+ im.thumbnail((192,192))
19
+ im
20
+
21
+ # %%
22
+ #|export
23
+
24
+ learn = load_learner("model.pkl")
25
+
26
+ # %%
27
+ %time learn.predict(im)
28
+
29
+ # %%
30
+ #|export
31
+ categories = ('Dog', 'Cat')
32
+
33
+ def classify_image(img):
34
+ pred,idx,probs = learn.predict(img)
35
+ return dict(zip(categories, map(float, probs)))
36
+
37
+ # %%
38
+ classify_image(im)
39
+
40
+ # %%
41
+ #|export
42
+ image = gr.inputs.Image(shape=(192,192))
43
+ label = gr.outputs.Label()
44
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
45
 
46
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
47
+ intf.launch(inline=False)
48
 
49
 
 
 
old_app.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def greet(name):
5
+ return "Hello " + name + "!!"
6
+
7
+
8
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
+ iface.launch()