Spaces:
Runtime error
Runtime error
add cat and dog pet classifier
Browse files- .ipynb_checkpoints/app-checkpoint.ipynb +6 -0
- app.ipynb +406 -0
- export.pkl +3 -0
- learning_gradio/app.py +23 -0
.ipynb_checkpoints/app-checkpoint.ipynb
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [],
|
3 |
+
"metadata": {},
|
4 |
+
"nbformat": 4,
|
5 |
+
"nbformat_minor": 5
|
6 |
+
}
|
app.ipynb
ADDED
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "e49d72ea",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"#|default_exp app"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
+
"id": "6ffe5ce8",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"#|export\n",
|
21 |
+
"# write this at the top of each cell which has to be exported to final script"
|
22 |
+
]
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"cell_type": "code",
|
26 |
+
"execution_count": 3,
|
27 |
+
"id": "dd7a7a33",
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"#|export\n",
|
32 |
+
"from fastai.vision.all import *"
|
33 |
+
]
|
34 |
+
},
|
35 |
+
{
|
36 |
+
"cell_type": "code",
|
37 |
+
"execution_count": 6,
|
38 |
+
"id": "501504ae",
|
39 |
+
"metadata": {},
|
40 |
+
"outputs": [],
|
41 |
+
"source": [
|
42 |
+
"#|export\n",
|
43 |
+
"# this identifies the type of classifier\n",
|
44 |
+
"learn = load_learner('export.pkl')\n",
|
45 |
+
"labels = learn.dls.vocab\n",
|
46 |
+
"def predict(img):\n",
|
47 |
+
" img = PILImage.create(img)\n",
|
48 |
+
" pred,pred_idx,probs = learn.predict(img)\n",
|
49 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
50 |
+
]
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"cell_type": "code",
|
54 |
+
"execution_count": 5,
|
55 |
+
"id": "bbedafc3",
|
56 |
+
"metadata": {},
|
57 |
+
"outputs": [
|
58 |
+
{
|
59 |
+
"name": "stderr",
|
60 |
+
"output_type": "stream",
|
61 |
+
"text": [
|
62 |
+
"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/inputs.py:256: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
63 |
+
" warnings.warn(\n",
|
64 |
+
"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
65 |
+
" warnings.warn(value)\n",
|
66 |
+
"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
67 |
+
" warnings.warn(\n",
|
68 |
+
"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
69 |
+
" warnings.warn(value)\n"
|
70 |
+
]
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"name": "stdout",
|
74 |
+
"output_type": "stream",
|
75 |
+
"text": [
|
76 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
77 |
+
"Running on public URL: https://28738.gradio.app\n",
|
78 |
+
"\n",
|
79 |
+
"This share link expires in 72 hours. For free permanent hosting, check out Spaces: https://huggingface.co/spaces\n"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"data": {
|
84 |
+
"text/html": [
|
85 |
+
"<div><iframe src=\"https://28738.gradio.app\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
86 |
+
],
|
87 |
+
"text/plain": [
|
88 |
+
"<IPython.core.display.HTML object>"
|
89 |
+
]
|
90 |
+
},
|
91 |
+
"metadata": {},
|
92 |
+
"output_type": "display_data"
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"data": {
|
96 |
+
"text/plain": [
|
97 |
+
"(<gradio.routes.App at 0x7f8dee0aaeb0>,\n",
|
98 |
+
" 'http://127.0.0.1:7860/',\n",
|
99 |
+
" 'https://28738.gradio.app')"
|
100 |
+
]
|
101 |
+
},
|
102 |
+
"execution_count": 5,
|
103 |
+
"metadata": {},
|
104 |
+
"output_type": "execute_result"
|
105 |
+
},
|
106 |
+
{
|
107 |
+
"data": {
|
108 |
+
"text/html": [
|
109 |
+
"\n",
|
110 |
+
"<style>\n",
|
111 |
+
" /* Turns off some styling */\n",
|
112 |
+
" progress {\n",
|
113 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
114 |
+
" border: none;\n",
|
115 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
116 |
+
" background-size: auto;\n",
|
117 |
+
" }\n",
|
118 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
119 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
120 |
+
" }\n",
|
121 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
122 |
+
" background: #F44336;\n",
|
123 |
+
" }\n",
|
124 |
+
"</style>\n"
|
125 |
+
],
|
126 |
+
"text/plain": [
|
127 |
+
"<IPython.core.display.HTML object>"
|
128 |
+
]
|
129 |
+
},
|
130 |
+
"metadata": {},
|
131 |
+
"output_type": "display_data"
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"data": {
|
135 |
+
"text/html": [],
|
136 |
+
"text/plain": [
|
137 |
+
"<IPython.core.display.HTML object>"
|
138 |
+
]
|
139 |
+
},
|
140 |
+
"metadata": {},
|
141 |
+
"output_type": "display_data"
|
142 |
+
},
|
143 |
+
{
|
144 |
+
"name": "stderr",
|
145 |
+
"output_type": "stream",
|
146 |
+
"text": [
|
147 |
+
"Traceback (most recent call last):\n",
|
148 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/PIL/Image.py\", line 3096, in open\n",
|
149 |
+
" fp.seek(0)\n",
|
150 |
+
"AttributeError: 'NoneType' object has no attribute 'seek'\n",
|
151 |
+
"\n",
|
152 |
+
"During handling of the above exception, another exception occurred:\n",
|
153 |
+
"\n",
|
154 |
+
"Traceback (most recent call last):\n",
|
155 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/routes.py\", line 268, in run_predict\n",
|
156 |
+
" output = await app.blocks.process_api(\n",
|
157 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/blocks.py\", line 748, in process_api\n",
|
158 |
+
" result = await self.call_function(fn_index, inputs, iterator)\n",
|
159 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/gradio/blocks.py\", line 627, in call_function\n",
|
160 |
+
" prediction = await anyio.to_thread.run_sync(\n",
|
161 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/anyio/to_thread.py\", line 31, in run_sync\n",
|
162 |
+
" return await get_asynclib().run_sync_in_worker_thread(\n",
|
163 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/anyio/_backends/_asyncio.py\", line 937, in run_sync_in_worker_thread\n",
|
164 |
+
" return await future\n",
|
165 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/anyio/_backends/_asyncio.py\", line 867, in run\n",
|
166 |
+
" result = context.run(func, *args)\n",
|
167 |
+
" File \"<ipython-input-4-7102b1720f8e>\", line 5, in predict\n",
|
168 |
+
" img = PILImage.create(img)\n",
|
169 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/fastai/vision/core.py\", line 123, in create\n",
|
170 |
+
" return cls(load_image(fn, **merge(cls._open_args, kwargs)))\n",
|
171 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/fastai/vision/core.py\", line 98, in load_image\n",
|
172 |
+
" im = Image.open(fn)\n",
|
173 |
+
" File \"/home/gilopez/mambaforge/envs/fastai/lib/python3.9/site-packages/PIL/Image.py\", line 3098, in open\n",
|
174 |
+
" fp = io.BytesIO(fp.read())\n",
|
175 |
+
"AttributeError: 'NoneType' object has no attribute 'read'\n"
|
176 |
+
]
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"data": {
|
180 |
+
"text/html": [
|
181 |
+
"\n",
|
182 |
+
"<style>\n",
|
183 |
+
" /* Turns off some styling */\n",
|
184 |
+
" progress {\n",
|
185 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
186 |
+
" border: none;\n",
|
187 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
188 |
+
" background-size: auto;\n",
|
189 |
+
" }\n",
|
190 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
191 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
192 |
+
" }\n",
|
193 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
194 |
+
" background: #F44336;\n",
|
195 |
+
" }\n",
|
196 |
+
"</style>\n"
|
197 |
+
],
|
198 |
+
"text/plain": [
|
199 |
+
"<IPython.core.display.HTML object>"
|
200 |
+
]
|
201 |
+
},
|
202 |
+
"metadata": {},
|
203 |
+
"output_type": "display_data"
|
204 |
+
},
|
205 |
+
{
|
206 |
+
"data": {
|
207 |
+
"text/html": [],
|
208 |
+
"text/plain": [
|
209 |
+
"<IPython.core.display.HTML object>"
|
210 |
+
]
|
211 |
+
},
|
212 |
+
"metadata": {},
|
213 |
+
"output_type": "display_data"
|
214 |
+
},
|
215 |
+
{
|
216 |
+
"data": {
|
217 |
+
"text/html": [
|
218 |
+
"\n",
|
219 |
+
"<style>\n",
|
220 |
+
" /* Turns off some styling */\n",
|
221 |
+
" progress {\n",
|
222 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
223 |
+
" border: none;\n",
|
224 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
225 |
+
" background-size: auto;\n",
|
226 |
+
" }\n",
|
227 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
228 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
229 |
+
" }\n",
|
230 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
231 |
+
" background: #F44336;\n",
|
232 |
+
" }\n",
|
233 |
+
"</style>\n"
|
234 |
+
],
|
235 |
+
"text/plain": [
|
236 |
+
"<IPython.core.display.HTML object>"
|
237 |
+
]
|
238 |
+
},
|
239 |
+
"metadata": {},
|
240 |
+
"output_type": "display_data"
|
241 |
+
},
|
242 |
+
{
|
243 |
+
"data": {
|
244 |
+
"text/html": [],
|
245 |
+
"text/plain": [
|
246 |
+
"<IPython.core.display.HTML object>"
|
247 |
+
]
|
248 |
+
},
|
249 |
+
"metadata": {},
|
250 |
+
"output_type": "display_data"
|
251 |
+
}
|
252 |
+
],
|
253 |
+
"source": [
|
254 |
+
"#|export\n",
|
255 |
+
"import gradio as gr\n",
|
256 |
+
"gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)"
|
257 |
+
]
|
258 |
+
},
|
259 |
+
{
|
260 |
+
"cell_type": "code",
|
261 |
+
"execution_count": null,
|
262 |
+
"id": "321e5e2a",
|
263 |
+
"metadata": {},
|
264 |
+
"outputs": [],
|
265 |
+
"source": []
|
266 |
+
},
|
267 |
+
{
|
268 |
+
"cell_type": "code",
|
269 |
+
"execution_count": null,
|
270 |
+
"id": "eab7bd30",
|
271 |
+
"metadata": {},
|
272 |
+
"outputs": [],
|
273 |
+
"source": []
|
274 |
+
},
|
275 |
+
{
|
276 |
+
"cell_type": "code",
|
277 |
+
"execution_count": null,
|
278 |
+
"id": "aab565a0",
|
279 |
+
"metadata": {},
|
280 |
+
"outputs": [],
|
281 |
+
"source": []
|
282 |
+
},
|
283 |
+
{
|
284 |
+
"cell_type": "code",
|
285 |
+
"execution_count": null,
|
286 |
+
"id": "1f6ef9c6",
|
287 |
+
"metadata": {},
|
288 |
+
"outputs": [],
|
289 |
+
"source": []
|
290 |
+
},
|
291 |
+
{
|
292 |
+
"cell_type": "code",
|
293 |
+
"execution_count": null,
|
294 |
+
"id": "0d8b4820",
|
295 |
+
"metadata": {},
|
296 |
+
"outputs": [],
|
297 |
+
"source": []
|
298 |
+
},
|
299 |
+
{
|
300 |
+
"cell_type": "code",
|
301 |
+
"execution_count": null,
|
302 |
+
"id": "29bc0545",
|
303 |
+
"metadata": {},
|
304 |
+
"outputs": [],
|
305 |
+
"source": []
|
306 |
+
},
|
307 |
+
{
|
308 |
+
"cell_type": "code",
|
309 |
+
"execution_count": null,
|
310 |
+
"id": "eec30b86",
|
311 |
+
"metadata": {},
|
312 |
+
"outputs": [],
|
313 |
+
"source": []
|
314 |
+
},
|
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"
|
329 |
+
]
|
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": []
|
383 |
+
}
|
384 |
+
],
|
385 |
+
"metadata": {
|
386 |
+
"kernelspec": {
|
387 |
+
"display_name": "fastai",
|
388 |
+
"language": "python",
|
389 |
+
"name": "fastai"
|
390 |
+
},
|
391 |
+
"language_info": {
|
392 |
+
"codemirror_mode": {
|
393 |
+
"name": "ipython",
|
394 |
+
"version": 3
|
395 |
+
},
|
396 |
+
"file_extension": ".py",
|
397 |
+
"mimetype": "text/x-python",
|
398 |
+
"name": "python",
|
399 |
+
"nbconvert_exporter": "python",
|
400 |
+
"pygments_lexer": "ipython3",
|
401 |
+
"version": "3.9.13"
|
402 |
+
}
|
403 |
+
},
|
404 |
+
"nbformat": 4,
|
405 |
+
"nbformat_minor": 5
|
406 |
+
}
|
export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ff1e9a7925b9798c26b56763db26b7f8aabf3accd2a2aebb4902d9f0b56cf2c
|
3 |
+
size 103045461
|
learning_gradio/app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|