Spaces:
Sleeping
Sleeping
Benjamin Coman
commited on
Commit
•
7469cf1
1
Parent(s):
7656535
app.py is not a notebook
Browse files- app.py +21 -377
- applocal.ipynb +11 -282
app.py
CHANGED
@@ -1,377 +1,21 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
"id": "066f65b3",
|
23 |
-
"metadata": {},
|
24 |
-
"outputs": [
|
25 |
-
{
|
26 |
-
"name": "stdout",
|
27 |
-
"output_type": "stream",
|
28 |
-
"text": [
|
29 |
-
"Running on local URL: http://127.0.0.1:7873/\n",
|
30 |
-
"\n",
|
31 |
-
"To create a public link, set `share=True` in `launch()`.\n"
|
32 |
-
]
|
33 |
-
},
|
34 |
-
{
|
35 |
-
"data": {
|
36 |
-
"text/plain": [
|
37 |
-
"(<fastapi.applications.FastAPI at 0x7f9a58a15a60>,\n",
|
38 |
-
" 'http://127.0.0.1:7873/',\n",
|
39 |
-
" None)"
|
40 |
-
]
|
41 |
-
},
|
42 |
-
"execution_count": 27,
|
43 |
-
"metadata": {},
|
44 |
-
"output_type": "execute_result"
|
45 |
-
},
|
46 |
-
{
|
47 |
-
"data": {
|
48 |
-
"text/html": [
|
49 |
-
"\n",
|
50 |
-
"<style>\n",
|
51 |
-
" /* Turns off some styling */\n",
|
52 |
-
" progress {\n",
|
53 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
54 |
-
" border: none;\n",
|
55 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
56 |
-
" background-size: auto;\n",
|
57 |
-
" }\n",
|
58 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
59 |
-
" background: #F44336;\n",
|
60 |
-
" }\n",
|
61 |
-
"</style>\n"
|
62 |
-
],
|
63 |
-
"text/plain": [
|
64 |
-
"<IPython.core.display.HTML object>"
|
65 |
-
]
|
66 |
-
},
|
67 |
-
"metadata": {},
|
68 |
-
"output_type": "display_data"
|
69 |
-
},
|
70 |
-
{
|
71 |
-
"data": {
|
72 |
-
"text/html": [],
|
73 |
-
"text/plain": [
|
74 |
-
"<IPython.core.display.HTML object>"
|
75 |
-
]
|
76 |
-
},
|
77 |
-
"metadata": {},
|
78 |
-
"output_type": "display_data"
|
79 |
-
},
|
80 |
-
{
|
81 |
-
"data": {
|
82 |
-
"text/html": [
|
83 |
-
"\n",
|
84 |
-
"<style>\n",
|
85 |
-
" /* Turns off some styling */\n",
|
86 |
-
" progress {\n",
|
87 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
88 |
-
" border: none;\n",
|
89 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
90 |
-
" background-size: auto;\n",
|
91 |
-
" }\n",
|
92 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
93 |
-
" background: #F44336;\n",
|
94 |
-
" }\n",
|
95 |
-
"</style>\n"
|
96 |
-
],
|
97 |
-
"text/plain": [
|
98 |
-
"<IPython.core.display.HTML object>"
|
99 |
-
]
|
100 |
-
},
|
101 |
-
"metadata": {},
|
102 |
-
"output_type": "display_data"
|
103 |
-
},
|
104 |
-
{
|
105 |
-
"data": {
|
106 |
-
"text/html": [],
|
107 |
-
"text/plain": [
|
108 |
-
"<IPython.core.display.HTML object>"
|
109 |
-
]
|
110 |
-
},
|
111 |
-
"metadata": {},
|
112 |
-
"output_type": "display_data"
|
113 |
-
},
|
114 |
-
{
|
115 |
-
"data": {
|
116 |
-
"text/html": [
|
117 |
-
"\n",
|
118 |
-
"<style>\n",
|
119 |
-
" /* Turns off some styling */\n",
|
120 |
-
" progress {\n",
|
121 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
122 |
-
" border: none;\n",
|
123 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
124 |
-
" background-size: auto;\n",
|
125 |
-
" }\n",
|
126 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
127 |
-
" background: #F44336;\n",
|
128 |
-
" }\n",
|
129 |
-
"</style>\n"
|
130 |
-
],
|
131 |
-
"text/plain": [
|
132 |
-
"<IPython.core.display.HTML object>"
|
133 |
-
]
|
134 |
-
},
|
135 |
-
"metadata": {},
|
136 |
-
"output_type": "display_data"
|
137 |
-
},
|
138 |
-
{
|
139 |
-
"data": {
|
140 |
-
"text/html": [],
|
141 |
-
"text/plain": [
|
142 |
-
"<IPython.core.display.HTML object>"
|
143 |
-
]
|
144 |
-
},
|
145 |
-
"metadata": {},
|
146 |
-
"output_type": "display_data"
|
147 |
-
},
|
148 |
-
{
|
149 |
-
"data": {
|
150 |
-
"text/html": [
|
151 |
-
"\n",
|
152 |
-
"<style>\n",
|
153 |
-
" /* Turns off some styling */\n",
|
154 |
-
" progress {\n",
|
155 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
156 |
-
" border: none;\n",
|
157 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
158 |
-
" background-size: auto;\n",
|
159 |
-
" }\n",
|
160 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
161 |
-
" background: #F44336;\n",
|
162 |
-
" }\n",
|
163 |
-
"</style>\n"
|
164 |
-
],
|
165 |
-
"text/plain": [
|
166 |
-
"<IPython.core.display.HTML object>"
|
167 |
-
]
|
168 |
-
},
|
169 |
-
"metadata": {},
|
170 |
-
"output_type": "display_data"
|
171 |
-
},
|
172 |
-
{
|
173 |
-
"data": {
|
174 |
-
"text/html": [],
|
175 |
-
"text/plain": [
|
176 |
-
"<IPython.core.display.HTML object>"
|
177 |
-
]
|
178 |
-
},
|
179 |
-
"metadata": {},
|
180 |
-
"output_type": "display_data"
|
181 |
-
},
|
182 |
-
{
|
183 |
-
"data": {
|
184 |
-
"text/html": [
|
185 |
-
"\n",
|
186 |
-
"<style>\n",
|
187 |
-
" /* Turns off some styling */\n",
|
188 |
-
" progress {\n",
|
189 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
190 |
-
" border: none;\n",
|
191 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
192 |
-
" background-size: auto;\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-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-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
263 |
-
" background: #F44336;\n",
|
264 |
-
" }\n",
|
265 |
-
"</style>\n"
|
266 |
-
],
|
267 |
-
"text/plain": [
|
268 |
-
"<IPython.core.display.HTML object>"
|
269 |
-
]
|
270 |
-
},
|
271 |
-
"metadata": {},
|
272 |
-
"output_type": "display_data"
|
273 |
-
},
|
274 |
-
{
|
275 |
-
"data": {
|
276 |
-
"text/html": [],
|
277 |
-
"text/plain": [
|
278 |
-
"<IPython.core.display.HTML object>"
|
279 |
-
]
|
280 |
-
},
|
281 |
-
"metadata": {},
|
282 |
-
"output_type": "display_data"
|
283 |
-
},
|
284 |
-
{
|
285 |
-
"data": {
|
286 |
-
"text/html": [
|
287 |
-
"\n",
|
288 |
-
"<style>\n",
|
289 |
-
" /* Turns off some styling */\n",
|
290 |
-
" progress {\n",
|
291 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
292 |
-
" border: none;\n",
|
293 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
294 |
-
" background-size: auto;\n",
|
295 |
-
" }\n",
|
296 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
297 |
-
" background: #F44336;\n",
|
298 |
-
" }\n",
|
299 |
-
"</style>\n"
|
300 |
-
],
|
301 |
-
"text/plain": [
|
302 |
-
"<IPython.core.display.HTML object>"
|
303 |
-
]
|
304 |
-
},
|
305 |
-
"metadata": {},
|
306 |
-
"output_type": "display_data"
|
307 |
-
},
|
308 |
-
{
|
309 |
-
"data": {
|
310 |
-
"text/html": [],
|
311 |
-
"text/plain": [
|
312 |
-
"<IPython.core.display.HTML object>"
|
313 |
-
]
|
314 |
-
},
|
315 |
-
"metadata": {},
|
316 |
-
"output_type": "display_data"
|
317 |
-
}
|
318 |
-
],
|
319 |
-
"source": [
|
320 |
-
"categories = learn.dls.vocab\n",
|
321 |
-
"\n",
|
322 |
-
"def classify_image(img):\n",
|
323 |
-
" pred,idx,probs = learn.predict(img)\n",
|
324 |
-
" return( dict(zip(categories, map(float,probs))))\n",
|
325 |
-
"\n",
|
326 |
-
"image = gr.inputs.Image(shape=(192,192))\n",
|
327 |
-
"label = gr.outputs.Label()\n",
|
328 |
-
"examples = './examples'\n",
|
329 |
-
"\n",
|
330 |
-
"iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
331 |
-
"iface.launch(inline=False)"
|
332 |
-
]
|
333 |
-
},
|
334 |
-
{
|
335 |
-
"cell_type": "code",
|
336 |
-
"execution_count": null,
|
337 |
-
"id": "5c2b5daa",
|
338 |
-
"metadata": {},
|
339 |
-
"outputs": [],
|
340 |
-
"source": []
|
341 |
-
}
|
342 |
-
],
|
343 |
-
"metadata": {
|
344 |
-
"kernelspec": {
|
345 |
-
"display_name": "Python [conda env:root] *",
|
346 |
-
"language": "python",
|
347 |
-
"name": "conda-root-py"
|
348 |
-
},
|
349 |
-
"language_info": {
|
350 |
-
"codemirror_mode": {
|
351 |
-
"name": "ipython",
|
352 |
-
"version": 3
|
353 |
-
},
|
354 |
-
"file_extension": ".py",
|
355 |
-
"mimetype": "text/x-python",
|
356 |
-
"name": "python",
|
357 |
-
"nbconvert_exporter": "python",
|
358 |
-
"pygments_lexer": "ipython3",
|
359 |
-
"version": "3.9.10"
|
360 |
-
},
|
361 |
-
"toc": {
|
362 |
-
"base_numbering": 1,
|
363 |
-
"nav_menu": {},
|
364 |
-
"number_sections": true,
|
365 |
-
"sideBar": true,
|
366 |
-
"skip_h1_title": false,
|
367 |
-
"title_cell": "Table of Contents",
|
368 |
-
"title_sidebar": "Contents",
|
369 |
-
"toc_cell": false,
|
370 |
-
"toc_position": {},
|
371 |
-
"toc_section_display": true,
|
372 |
-
"toc_window_display": false
|
373 |
-
}
|
374 |
-
},
|
375 |
-
"nbformat": 4,
|
376 |
-
"nbformat_minor": 5
|
377 |
-
}
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
learn = load_learner('watersports.pkl')
|
5 |
+
categories = learn.dls.vocab
|
6 |
+
|
7 |
+
def classify_image(img):
|
8 |
+
pred,idx,probs = learn.predict(img)
|
9 |
+
return( dict(zip(categories, map(float,probs))))
|
10 |
+
|
11 |
+
title = "Which Watersport?"
|
12 |
+
description = "Drag an image into the analyser. Try to guess the water sport yourself, before hitting submit. \
|
13 |
+
You need to clear before dragging next image. You can also drag images directly from a google search."
|
14 |
+
image = gr.inputs.Image(shape=(192,192))
|
15 |
+
label = gr.outputs.Label()
|
16 |
+
examples = './examples'
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, \
|
19 |
+
examples=examples, title=title, description=description)
|
20 |
+
iface.launch(inline=False)
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applocal.ipynb
CHANGED
@@ -10,15 +10,13 @@
|
|
10 |
"from fastai.vision.all import *\n",
|
11 |
"import gradio as gr\n",
|
12 |
"\n",
|
13 |
-
"#def is_cat(x): return x[0].isupper()\n",
|
14 |
-
"\n",
|
15 |
"learn = load_learner('watersports.pkl')\n",
|
16 |
-
"
|
17 |
]
|
18 |
},
|
19 |
{
|
20 |
"cell_type": "code",
|
21 |
-
"execution_count":
|
22 |
"id": "066f65b3",
|
23 |
"metadata": {},
|
24 |
"outputs": [
|
@@ -26,7 +24,7 @@
|
|
26 |
"name": "stdout",
|
27 |
"output_type": "stream",
|
28 |
"text": [
|
29 |
-
"Running on local URL: http://127.0.0.1:
|
30 |
"\n",
|
31 |
"To create a public link, set `share=True` in `launch()`.\n"
|
32 |
]
|
@@ -35,306 +33,37 @@
|
|
35 |
"data": {
|
36 |
"text/plain": [
|
37 |
"(<fastapi.applications.FastAPI at 0x7f9a58a15a60>,\n",
|
38 |
-
" 'http://127.0.0.1:
|
39 |
" None)"
|
40 |
]
|
41 |
},
|
42 |
-
"execution_count":
|
43 |
"metadata": {},
|
44 |
"output_type": "execute_result"
|
45 |
-
},
|
46 |
-
{
|
47 |
-
"data": {
|
48 |
-
"text/html": [
|
49 |
-
"\n",
|
50 |
-
"<style>\n",
|
51 |
-
" /* Turns off some styling */\n",
|
52 |
-
" progress {\n",
|
53 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
54 |
-
" border: none;\n",
|
55 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
56 |
-
" background-size: auto;\n",
|
57 |
-
" }\n",
|
58 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
59 |
-
" background: #F44336;\n",
|
60 |
-
" }\n",
|
61 |
-
"</style>\n"
|
62 |
-
],
|
63 |
-
"text/plain": [
|
64 |
-
"<IPython.core.display.HTML object>"
|
65 |
-
]
|
66 |
-
},
|
67 |
-
"metadata": {},
|
68 |
-
"output_type": "display_data"
|
69 |
-
},
|
70 |
-
{
|
71 |
-
"data": {
|
72 |
-
"text/html": [],
|
73 |
-
"text/plain": [
|
74 |
-
"<IPython.core.display.HTML object>"
|
75 |
-
]
|
76 |
-
},
|
77 |
-
"metadata": {},
|
78 |
-
"output_type": "display_data"
|
79 |
-
},
|
80 |
-
{
|
81 |
-
"data": {
|
82 |
-
"text/html": [
|
83 |
-
"\n",
|
84 |
-
"<style>\n",
|
85 |
-
" /* Turns off some styling */\n",
|
86 |
-
" progress {\n",
|
87 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
88 |
-
" border: none;\n",
|
89 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
90 |
-
" background-size: auto;\n",
|
91 |
-
" }\n",
|
92 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
93 |
-
" background: #F44336;\n",
|
94 |
-
" }\n",
|
95 |
-
"</style>\n"
|
96 |
-
],
|
97 |
-
"text/plain": [
|
98 |
-
"<IPython.core.display.HTML object>"
|
99 |
-
]
|
100 |
-
},
|
101 |
-
"metadata": {},
|
102 |
-
"output_type": "display_data"
|
103 |
-
},
|
104 |
-
{
|
105 |
-
"data": {
|
106 |
-
"text/html": [],
|
107 |
-
"text/plain": [
|
108 |
-
"<IPython.core.display.HTML object>"
|
109 |
-
]
|
110 |
-
},
|
111 |
-
"metadata": {},
|
112 |
-
"output_type": "display_data"
|
113 |
-
},
|
114 |
-
{
|
115 |
-
"data": {
|
116 |
-
"text/html": [
|
117 |
-
"\n",
|
118 |
-
"<style>\n",
|
119 |
-
" /* Turns off some styling */\n",
|
120 |
-
" progress {\n",
|
121 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
122 |
-
" border: none;\n",
|
123 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
124 |
-
" background-size: auto;\n",
|
125 |
-
" }\n",
|
126 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
127 |
-
" background: #F44336;\n",
|
128 |
-
" }\n",
|
129 |
-
"</style>\n"
|
130 |
-
],
|
131 |
-
"text/plain": [
|
132 |
-
"<IPython.core.display.HTML object>"
|
133 |
-
]
|
134 |
-
},
|
135 |
-
"metadata": {},
|
136 |
-
"output_type": "display_data"
|
137 |
-
},
|
138 |
-
{
|
139 |
-
"data": {
|
140 |
-
"text/html": [],
|
141 |
-
"text/plain": [
|
142 |
-
"<IPython.core.display.HTML object>"
|
143 |
-
]
|
144 |
-
},
|
145 |
-
"metadata": {},
|
146 |
-
"output_type": "display_data"
|
147 |
-
},
|
148 |
-
{
|
149 |
-
"data": {
|
150 |
-
"text/html": [
|
151 |
-
"\n",
|
152 |
-
"<style>\n",
|
153 |
-
" /* Turns off some styling */\n",
|
154 |
-
" progress {\n",
|
155 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
156 |
-
" border: none;\n",
|
157 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
158 |
-
" background-size: auto;\n",
|
159 |
-
" }\n",
|
160 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
161 |
-
" background: #F44336;\n",
|
162 |
-
" }\n",
|
163 |
-
"</style>\n"
|
164 |
-
],
|
165 |
-
"text/plain": [
|
166 |
-
"<IPython.core.display.HTML object>"
|
167 |
-
]
|
168 |
-
},
|
169 |
-
"metadata": {},
|
170 |
-
"output_type": "display_data"
|
171 |
-
},
|
172 |
-
{
|
173 |
-
"data": {
|
174 |
-
"text/html": [],
|
175 |
-
"text/plain": [
|
176 |
-
"<IPython.core.display.HTML object>"
|
177 |
-
]
|
178 |
-
},
|
179 |
-
"metadata": {},
|
180 |
-
"output_type": "display_data"
|
181 |
-
},
|
182 |
-
{
|
183 |
-
"data": {
|
184 |
-
"text/html": [
|
185 |
-
"\n",
|
186 |
-
"<style>\n",
|
187 |
-
" /* Turns off some styling */\n",
|
188 |
-
" progress {\n",
|
189 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
190 |
-
" border: none;\n",
|
191 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
192 |
-
" background-size: auto;\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-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-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
263 |
-
" background: #F44336;\n",
|
264 |
-
" }\n",
|
265 |
-
"</style>\n"
|
266 |
-
],
|
267 |
-
"text/plain": [
|
268 |
-
"<IPython.core.display.HTML object>"
|
269 |
-
]
|
270 |
-
},
|
271 |
-
"metadata": {},
|
272 |
-
"output_type": "display_data"
|
273 |
-
},
|
274 |
-
{
|
275 |
-
"data": {
|
276 |
-
"text/html": [],
|
277 |
-
"text/plain": [
|
278 |
-
"<IPython.core.display.HTML object>"
|
279 |
-
]
|
280 |
-
},
|
281 |
-
"metadata": {},
|
282 |
-
"output_type": "display_data"
|
283 |
-
},
|
284 |
-
{
|
285 |
-
"data": {
|
286 |
-
"text/html": [
|
287 |
-
"\n",
|
288 |
-
"<style>\n",
|
289 |
-
" /* Turns off some styling */\n",
|
290 |
-
" progress {\n",
|
291 |
-
" /* gets rid of default border in Firefox and Opera. */\n",
|
292 |
-
" border: none;\n",
|
293 |
-
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
294 |
-
" background-size: auto;\n",
|
295 |
-
" }\n",
|
296 |
-
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
297 |
-
" background: #F44336;\n",
|
298 |
-
" }\n",
|
299 |
-
"</style>\n"
|
300 |
-
],
|
301 |
-
"text/plain": [
|
302 |
-
"<IPython.core.display.HTML object>"
|
303 |
-
]
|
304 |
-
},
|
305 |
-
"metadata": {},
|
306 |
-
"output_type": "display_data"
|
307 |
-
},
|
308 |
-
{
|
309 |
-
"data": {
|
310 |
-
"text/html": [],
|
311 |
-
"text/plain": [
|
312 |
-
"<IPython.core.display.HTML object>"
|
313 |
-
]
|
314 |
-
},
|
315 |
-
"metadata": {},
|
316 |
-
"output_type": "display_data"
|
317 |
}
|
318 |
],
|
319 |
"source": [
|
320 |
-
"
|
321 |
"\n",
|
322 |
"def classify_image(img):\n",
|
323 |
" pred,idx,probs = learn.predict(img)\n",
|
324 |
" return( dict(zip(categories, map(float,probs))))\n",
|
325 |
"\n",
|
|
|
|
|
|
|
326 |
"image = gr.inputs.Image(shape=(192,192))\n",
|
327 |
"label = gr.outputs.Label()\n",
|
328 |
"examples = './examples'\n",
|
329 |
"\n",
|
330 |
-
"iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
331 |
"iface.launch(inline=False)"
|
332 |
]
|
333 |
},
|
334 |
{
|
335 |
"cell_type": "code",
|
336 |
"execution_count": null,
|
337 |
-
"id": "
|
338 |
"metadata": {},
|
339 |
"outputs": [],
|
340 |
"source": []
|
|
|
10 |
"from fastai.vision.all import *\n",
|
11 |
"import gradio as gr\n",
|
12 |
"\n",
|
|
|
|
|
13 |
"learn = load_learner('watersports.pkl')\n",
|
14 |
+
"categories = learn.dls.vocab"
|
15 |
]
|
16 |
},
|
17 |
{
|
18 |
"cell_type": "code",
|
19 |
+
"execution_count": 29,
|
20 |
"id": "066f65b3",
|
21 |
"metadata": {},
|
22 |
"outputs": [
|
|
|
24 |
"name": "stdout",
|
25 |
"output_type": "stream",
|
26 |
"text": [
|
27 |
+
"Running on local URL: http://127.0.0.1:7875/\n",
|
28 |
"\n",
|
29 |
"To create a public link, set `share=True` in `launch()`.\n"
|
30 |
]
|
|
|
33 |
"data": {
|
34 |
"text/plain": [
|
35 |
"(<fastapi.applications.FastAPI at 0x7f9a58a15a60>,\n",
|
36 |
+
" 'http://127.0.0.1:7875/',\n",
|
37 |
" None)"
|
38 |
]
|
39 |
},
|
40 |
+
"execution_count": 29,
|
41 |
"metadata": {},
|
42 |
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
],
|
45 |
"source": [
|
46 |
+
"\n",
|
47 |
"\n",
|
48 |
"def classify_image(img):\n",
|
49 |
" pred,idx,probs = learn.predict(img)\n",
|
50 |
" return( dict(zip(categories, map(float,probs))))\n",
|
51 |
"\n",
|
52 |
+
"title = \"Which Watersport?\"\n",
|
53 |
+
"description = \"Drag an image into the analyser. Try to guess the water sport yourself, before hitting submit. \\\n",
|
54 |
+
"You need to clear before dragging next image. You can also drag images directly from a google search.\"\n",
|
55 |
"image = gr.inputs.Image(shape=(192,192))\n",
|
56 |
"label = gr.outputs.Label()\n",
|
57 |
"examples = './examples'\n",
|
58 |
"\n",
|
59 |
+
"iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples, title=title, description=description)\n",
|
60 |
"iface.launch(inline=False)"
|
61 |
]
|
62 |
},
|
63 |
{
|
64 |
"cell_type": "code",
|
65 |
"execution_count": null,
|
66 |
+
"id": "165054fe",
|
67 |
"metadata": {},
|
68 |
"outputs": [],
|
69 |
"source": []
|