irakli-ff commited on
Commit
b9c80a4
1 Parent(s): 9cd690d

first version

Browse files
.ipynb_checkpoints/app-checkpoint.ipynb ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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\n",
21
+ "\n",
22
+ "def is_cat(x): return x[0].is_cat"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": null,
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": []
31
+ }
32
+ ],
33
+ "metadata": {
34
+ "kernelspec": {
35
+ "display_name": "Python 3 (ipykernel)",
36
+ "language": "python",
37
+ "name": "python3"
38
+ },
39
+ "language_info": {
40
+ "codemirror_mode": {
41
+ "name": "ipython",
42
+ "version": 3
43
+ },
44
+ "file_extension": ".py",
45
+ "mimetype": "text/x-python",
46
+ "name": "python",
47
+ "nbconvert_exporter": "python",
48
+ "pygments_lexer": "ipython3",
49
+ "version": "3.10.9"
50
+ }
51
+ },
52
+ "nbformat": 4,
53
+ "nbformat_minor": 2
54
+ }
app.ipynb ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|default_exp app2"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "#|export\n",
19
+ "from fastai.vision.all import *\n",
20
+ "import gradio as gr\n",
21
+ "import io\n",
22
+ "from PIL import Image\n",
23
+ "\n",
24
+ "def pet_class(x): return x"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 16,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "im = 'basketball.png'"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 17,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "#|export\n",
43
+ "learn = load_learner('model.pkl')"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": null,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 18,
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "data": {
60
+ "text/plain": [
61
+ "'basketball ball'"
62
+ ]
63
+ },
64
+ "execution_count": 18,
65
+ "metadata": {},
66
+ "output_type": "execute_result"
67
+ }
68
+ ],
69
+ "source": [
70
+ "pred_class"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": 24,
76
+ "metadata": {},
77
+ "outputs": [],
78
+ "source": [
79
+ "#|export\n",
80
+ "categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')\n",
81
+ "\n",
82
+ "def classify_image(img):\n",
83
+ " pred_class, pred_idx, probs = learn.predict(img)\n",
84
+ " return dict(zip(categories, map(float,probs)))"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": 25,
90
+ "metadata": {},
91
+ "outputs": [
92
+ {
93
+ "data": {
94
+ "text/html": [
95
+ "\n",
96
+ "<style>\n",
97
+ " /* Turns off some styling */\n",
98
+ " progress {\n",
99
+ " /* gets rid of default border in Firefox and Opera. */\n",
100
+ " border: none;\n",
101
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
102
+ " background-size: auto;\n",
103
+ " }\n",
104
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
105
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
106
+ " }\n",
107
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
108
+ " background: #F44336;\n",
109
+ " }\n",
110
+ "</style>\n"
111
+ ],
112
+ "text/plain": [
113
+ "<IPython.core.display.HTML object>"
114
+ ]
115
+ },
116
+ "metadata": {},
117
+ "output_type": "display_data"
118
+ },
119
+ {
120
+ "data": {
121
+ "text/html": [],
122
+ "text/plain": [
123
+ "<IPython.core.display.HTML object>"
124
+ ]
125
+ },
126
+ "metadata": {},
127
+ "output_type": "display_data"
128
+ },
129
+ {
130
+ "data": {
131
+ "text/plain": [
132
+ "{'basketball ball': 0.9999959468841553,\n",
133
+ " 'golf ball': 2.8819481485697906e-06,\n",
134
+ " 'rugby ball': 1.3550672406381636e-07,\n",
135
+ " 'soccer ball': 1.1069746506109368e-06}"
136
+ ]
137
+ },
138
+ "execution_count": 25,
139
+ "metadata": {},
140
+ "output_type": "execute_result"
141
+ }
142
+ ],
143
+ "source": [
144
+ "classify_image(im)"
145
+ ]
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "execution_count": 27,
150
+ "metadata": {},
151
+ "outputs": [
152
+ {
153
+ "name": "stdout",
154
+ "output_type": "stream",
155
+ "text": [
156
+ "Running on local URL: http://127.0.0.1:7862\n",
157
+ "\n",
158
+ "To create a public link, set `share=True` in `launch()`.\n"
159
+ ]
160
+ },
161
+ {
162
+ "data": {
163
+ "text/plain": []
164
+ },
165
+ "execution_count": 27,
166
+ "metadata": {},
167
+ "output_type": "execute_result"
168
+ },
169
+ {
170
+ "data": {
171
+ "text/html": [
172
+ "\n",
173
+ "<style>\n",
174
+ " /* Turns off some styling */\n",
175
+ " progress {\n",
176
+ " /* gets rid of default border in Firefox and Opera. */\n",
177
+ " border: none;\n",
178
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
179
+ " background-size: auto;\n",
180
+ " }\n",
181
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
182
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
183
+ " }\n",
184
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
185
+ " background: #F44336;\n",
186
+ " }\n",
187
+ "</style>\n"
188
+ ],
189
+ "text/plain": [
190
+ "<IPython.core.display.HTML object>"
191
+ ]
192
+ },
193
+ "metadata": {},
194
+ "output_type": "display_data"
195
+ },
196
+ {
197
+ "data": {
198
+ "text/html": [],
199
+ "text/plain": [
200
+ "<IPython.core.display.HTML object>"
201
+ ]
202
+ },
203
+ "metadata": {},
204
+ "output_type": "display_data"
205
+ }
206
+ ],
207
+ "source": [
208
+ "#|export\n",
209
+ "image = gr.components.Image(shape=(192,192))\n",
210
+ "label = gr.components.Label()\n",
211
+ "examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']\n",
212
+ "\n",
213
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
214
+ "intf.launch(inline=False)"
215
+ ]
216
+ },
217
+ {
218
+ "cell_type": "code",
219
+ "execution_count": 4,
220
+ "metadata": {},
221
+ "outputs": [],
222
+ "source": [
223
+ "import nbdev\n",
224
+ "nbdev.export.nb_export('app.ipynb', 'app2')"
225
+ ]
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "execution_count": null,
230
+ "metadata": {},
231
+ "outputs": [],
232
+ "source": []
233
+ }
234
+ ],
235
+ "metadata": {
236
+ "kernelspec": {
237
+ "display_name": "Python 3 (ipykernel)",
238
+ "language": "python",
239
+ "name": "python3"
240
+ },
241
+ "language_info": {
242
+ "codemirror_mode": {
243
+ "name": "ipython",
244
+ "version": 3
245
+ },
246
+ "file_extension": ".py",
247
+ "mimetype": "text/x-python",
248
+ "name": "python",
249
+ "nbconvert_exporter": "python",
250
+ "pygments_lexer": "ipython3",
251
+ "version": "3.10.9"
252
+ }
253
+ },
254
+ "nbformat": 4,
255
+ "nbformat_minor": 2
256
+ }
app.py CHANGED
@@ -1,7 +1,30 @@
 
 
 
 
 
 
 
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', 'pet_class', 'classify_image']
5
+
6
+ # %% ../app.ipynb 1
7
+ from fastai.vision.all import *
8
  import gradio as gr
9
+ import io
10
+ from PIL import Image
11
+
12
+ def pet_class(x): return x
13
+
14
+ # %% ../app.ipynb 3
15
+ learn = load_learner('model.pkl')
16
+
17
+ # %% ../app.ipynb 6
18
+ categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')
19
+
20
+ def classify_image(img):
21
+ pred_class, pred_idx, probs = learn.predict(img)
22
+ return dict(zip(categories, map(float,probs)))
23
 
24
+ # %% ../app.ipynb 8
25
+ image = gr.components.Image(shape=(192,192))
26
+ label = gr.components.Label()
27
+ examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']
28
 
29
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
30
+ intf.launch(inline=False)
basketball.png ADDED
golf_ball.jpg ADDED
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee0e8ecf18bfb24c82a4812fd1b184d93ae5b80acc3e6556ea0069618446ecc5
3
+ size 46966617
rugby_ball.jpg ADDED
soccer_ball.jpg ADDED