Spaces:
Runtime error
Runtime error
matdmiller
commited on
Commit
•
d2e57c6
1
Parent(s):
e0a6772
modified: app.py
Browse files- .ipynb_checkpoints/app-checkpoint.ipynb +298 -0
- __pycache__/app.cpython-37.pyc +0 -0
- app.ipynb +189 -24
- app.py +1 -1
- app.pyc +0 -0
.ipynb_checkpoints/app-checkpoint.ipynb
ADDED
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "d2c2b738",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"from fastai.vision.all import *\n",
|
11 |
+
"import gradio as gr"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 2,
|
17 |
+
"id": "b92d24f3",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"# search_terms = ('hard hat','construction gloves','safety glasses','construction boots', 'screw driver','hammer','f150')\n"
|
22 |
+
]
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"cell_type": "code",
|
26 |
+
"execution_count": 9,
|
27 |
+
"id": "34ebdca4",
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"path = Path('construction_photos')"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 12,
|
37 |
+
"id": "04347f65",
|
38 |
+
"metadata": {},
|
39 |
+
"outputs": [
|
40 |
+
{
|
41 |
+
"data": {
|
42 |
+
"text/plain": [
|
43 |
+
"['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver']"
|
44 |
+
]
|
45 |
+
},
|
46 |
+
"execution_count": 12,
|
47 |
+
"metadata": {},
|
48 |
+
"output_type": "execute_result"
|
49 |
+
}
|
50 |
+
],
|
51 |
+
"source": [
|
52 |
+
"dls = DataBlock(\n",
|
53 |
+
" blocks=(ImageBlock,CategoryBlock),\n",
|
54 |
+
" getters=None,\n",
|
55 |
+
" n_inp=None,\n",
|
56 |
+
" item_tfms=[Resize(224,method='squish')],\n",
|
57 |
+
" get_items=get_image_files,\n",
|
58 |
+
" splitter=RandomSplitter(seed=42),\n",
|
59 |
+
" get_y=parent_label,\n",
|
60 |
+
").dataloaders('../python_clean_code_book/construction_photos/',bs=128)\n",
|
61 |
+
"# ).dataloaders()\n",
|
62 |
+
"#['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver']\n",
|
63 |
+
"dls.vocab"
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": 5,
|
69 |
+
"id": "85098e65",
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"learn = load_learner('construction_things.pkl')"
|
74 |
+
]
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"cell_type": "code",
|
78 |
+
"execution_count": 13,
|
79 |
+
"id": "a6ed198b",
|
80 |
+
"metadata": {},
|
81 |
+
"outputs": [],
|
82 |
+
"source": [
|
83 |
+
"def classify_image(img):\n",
|
84 |
+
" pred,idx,probs = learn.predict(img)\n",
|
85 |
+
" return dict(zip(['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver'],map(float,probs)))\n",
|
86 |
+
"# classify_image(get_image_files(path)[100])"
|
87 |
+
]
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"cell_type": "code",
|
91 |
+
"execution_count": 14,
|
92 |
+
"id": "dccf379e",
|
93 |
+
"metadata": {},
|
94 |
+
"outputs": [
|
95 |
+
{
|
96 |
+
"data": {
|
97 |
+
"text/html": [
|
98 |
+
"\n",
|
99 |
+
"<style>\n",
|
100 |
+
" /* Turns off some styling */\n",
|
101 |
+
" progress {\n",
|
102 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
103 |
+
" border: none;\n",
|
104 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
105 |
+
" background-size: auto;\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 |
+
"{'construction boots': 5.033571142121218e-07,\n",
|
133 |
+
" 'construction gloves': 1.9164571085639182e-07,\n",
|
134 |
+
" 'f150': 0.9999986886978149,\n",
|
135 |
+
" 'hammer': 2.487358869984746e-07,\n",
|
136 |
+
" 'hard hat': 9.779357412753598e-08,\n",
|
137 |
+
" 'safety glasses': 2.88559984795711e-08,\n",
|
138 |
+
" 'screw driver': 1.963149287576016e-07}"
|
139 |
+
]
|
140 |
+
},
|
141 |
+
"execution_count": 14,
|
142 |
+
"metadata": {},
|
143 |
+
"output_type": "execute_result"
|
144 |
+
}
|
145 |
+
],
|
146 |
+
"source": [
|
147 |
+
"classify_image('../../ebs1/python_clean_code_book/construction_photos/f150/00000000.jpg')"
|
148 |
+
]
|
149 |
+
},
|
150 |
+
{
|
151 |
+
"cell_type": "code",
|
152 |
+
"execution_count": 15,
|
153 |
+
"id": "b2f582a8",
|
154 |
+
"metadata": {},
|
155 |
+
"outputs": [
|
156 |
+
{
|
157 |
+
"name": "stdout",
|
158 |
+
"output_type": "stream",
|
159 |
+
"text": [
|
160 |
+
"Running on local URL: http://127.0.0.1:7861/\n",
|
161 |
+
"Running on public URL: https://54519.gradio.app\n",
|
162 |
+
"\n",
|
163 |
+
"This share link expires in 72 hours. For free permanent hosting, check out Spaces (https://huggingface.co/spaces)\n"
|
164 |
+
]
|
165 |
+
},
|
166 |
+
{
|
167 |
+
"data": {
|
168 |
+
"text/html": [
|
169 |
+
"\n",
|
170 |
+
" <iframe\n",
|
171 |
+
" width=\"900\"\n",
|
172 |
+
" height=\"500\"\n",
|
173 |
+
" src=\"https://54519.gradio.app\"\n",
|
174 |
+
" frameborder=\"0\"\n",
|
175 |
+
" allowfullscreen\n",
|
176 |
+
" \n",
|
177 |
+
" ></iframe>\n",
|
178 |
+
" "
|
179 |
+
],
|
180 |
+
"text/plain": [
|
181 |
+
"<IPython.lib.display.IFrame at 0x7f2dc985d640>"
|
182 |
+
]
|
183 |
+
},
|
184 |
+
"metadata": {},
|
185 |
+
"output_type": "display_data"
|
186 |
+
},
|
187 |
+
{
|
188 |
+
"data": {
|
189 |
+
"text/plain": [
|
190 |
+
"(<fastapi.applications.FastAPI at 0x7f2de255f3d0>,\n",
|
191 |
+
" 'http://127.0.0.1:7861/',\n",
|
192 |
+
" 'https://54519.gradio.app')"
|
193 |
+
]
|
194 |
+
},
|
195 |
+
"execution_count": 15,
|
196 |
+
"metadata": {},
|
197 |
+
"output_type": "execute_result"
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"data": {
|
201 |
+
"text/html": [
|
202 |
+
"\n",
|
203 |
+
"<style>\n",
|
204 |
+
" /* Turns off some styling */\n",
|
205 |
+
" progress {\n",
|
206 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
207 |
+
" border: none;\n",
|
208 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
209 |
+
" background-size: auto;\n",
|
210 |
+
" }\n",
|
211 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
212 |
+
" background: #F44336;\n",
|
213 |
+
" }\n",
|
214 |
+
"</style>\n"
|
215 |
+
],
|
216 |
+
"text/plain": [
|
217 |
+
"<IPython.core.display.HTML object>"
|
218 |
+
]
|
219 |
+
},
|
220 |
+
"metadata": {},
|
221 |
+
"output_type": "display_data"
|
222 |
+
},
|
223 |
+
{
|
224 |
+
"data": {
|
225 |
+
"text/html": [],
|
226 |
+
"text/plain": [
|
227 |
+
"<IPython.core.display.HTML object>"
|
228 |
+
]
|
229 |
+
},
|
230 |
+
"metadata": {},
|
231 |
+
"output_type": "display_data"
|
232 |
+
},
|
233 |
+
{
|
234 |
+
"name": "stderr",
|
235 |
+
"output_type": "stream",
|
236 |
+
"text": [
|
237 |
+
"Traceback (most recent call last):\n",
|
238 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/routes.py\", line 269, in predict\n",
|
239 |
+
" output = await run_in_threadpool(app.launchable.process_api, body, username)\n",
|
240 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/starlette/concurrency.py\", line 45, in run_in_threadpool\n",
|
241 |
+
" return await anyio.to_thread.run_sync(func, *args)\n",
|
242 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/anyio/to_thread.py\", line 28, in run_sync\n",
|
243 |
+
" return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,\n",
|
244 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/anyio/_backends/_asyncio.py\", line 818, in run_sync_in_worker_thread\n",
|
245 |
+
" return await future\n",
|
246 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/anyio/_backends/_asyncio.py\", line 754, in run\n",
|
247 |
+
" result = context.run(func, *args)\n",
|
248 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/interface.py\", line 573, in process_api\n",
|
249 |
+
" prediction, durations = self.process(raw_input)\n",
|
250 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/interface.py\", line 615, in process\n",
|
251 |
+
" predictions, durations = self.run_prediction(\n",
|
252 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/interface.py\", line 531, in run_prediction\n",
|
253 |
+
" prediction = predict_fn(*processed_input)\n",
|
254 |
+
" File \"/tmp/ipykernel_11528/2341249033.py\", line 3, in classify_image\n",
|
255 |
+
" return dict(zip(dls.vocab,map(float,probs)))\n",
|
256 |
+
"NameError: name 'dls' is not defined\n"
|
257 |
+
]
|
258 |
+
}
|
259 |
+
],
|
260 |
+
"source": [
|
261 |
+
"image = gr.inputs.Image(shape=(192,192))\n",
|
262 |
+
"label = gr.outputs.Label()\n",
|
263 |
+
"interface = gr.Interface(fn=classify_image,inputs=image,outputs=label)\n",
|
264 |
+
"interface.launch(inline=True,share=True)\n",
|
265 |
+
"# interface.launch(inline=False)"
|
266 |
+
]
|
267 |
+
},
|
268 |
+
{
|
269 |
+
"cell_type": "code",
|
270 |
+
"execution_count": null,
|
271 |
+
"id": "4b39ddcb",
|
272 |
+
"metadata": {},
|
273 |
+
"outputs": [],
|
274 |
+
"source": []
|
275 |
+
}
|
276 |
+
],
|
277 |
+
"metadata": {
|
278 |
+
"kernelspec": {
|
279 |
+
"display_name": "Python 3 (ipykernel)",
|
280 |
+
"language": "python",
|
281 |
+
"name": "python3"
|
282 |
+
},
|
283 |
+
"language_info": {
|
284 |
+
"codemirror_mode": {
|
285 |
+
"name": "ipython",
|
286 |
+
"version": 3
|
287 |
+
},
|
288 |
+
"file_extension": ".py",
|
289 |
+
"mimetype": "text/x-python",
|
290 |
+
"name": "python",
|
291 |
+
"nbconvert_exporter": "python",
|
292 |
+
"pygments_lexer": "ipython3",
|
293 |
+
"version": "3.9.7"
|
294 |
+
}
|
295 |
+
},
|
296 |
+
"nbformat": 4,
|
297 |
+
"nbformat_minor": 5
|
298 |
+
}
|
__pycache__/app.cpython-37.pyc
ADDED
Binary file (649 Bytes). View file
|
|
app.ipynb
CHANGED
@@ -23,30 +23,44 @@
|
|
23 |
},
|
24 |
{
|
25 |
"cell_type": "code",
|
26 |
-
"execution_count":
|
27 |
"id": "34ebdca4",
|
28 |
"metadata": {},
|
29 |
"outputs": [],
|
30 |
"source": [
|
31 |
-
"
|
32 |
]
|
33 |
},
|
34 |
{
|
35 |
"cell_type": "code",
|
36 |
-
"execution_count":
|
37 |
"id": "04347f65",
|
38 |
"metadata": {},
|
39 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
"source": [
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
-
"
|
|
|
|
|
|
|
50 |
]
|
51 |
},
|
52 |
{
|
@@ -61,20 +75,81 @@
|
|
61 |
},
|
62 |
{
|
63 |
"cell_type": "code",
|
64 |
-
"execution_count":
|
65 |
"id": "a6ed198b",
|
66 |
"metadata": {},
|
67 |
"outputs": [],
|
68 |
"source": [
|
69 |
"def classify_image(img):\n",
|
70 |
" pred,idx,probs = learn.predict(img)\n",
|
71 |
-
" return dict(zip(
|
72 |
"# classify_image(get_image_files(path)[100])"
|
73 |
]
|
74 |
},
|
75 |
{
|
76 |
"cell_type": "code",
|
77 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
"id": "b2f582a8",
|
79 |
"metadata": {},
|
80 |
"outputs": [
|
@@ -82,31 +157,121 @@
|
|
82 |
"name": "stdout",
|
83 |
"output_type": "stream",
|
84 |
"text": [
|
85 |
-
"Running on local URL: http://127.0.0.1:
|
|
|
86 |
"\n",
|
87 |
-
"
|
88 |
]
|
89 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
{
|
91 |
"data": {
|
92 |
"text/plain": [
|
93 |
-
"(<fastapi.applications.FastAPI at
|
94 |
-
" 'http://127.0.0.1:
|
95 |
-
"
|
96 |
]
|
97 |
},
|
98 |
-
"execution_count":
|
99 |
"metadata": {},
|
100 |
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
],
|
103 |
"source": [
|
104 |
"image = gr.inputs.Image(shape=(192,192))\n",
|
105 |
"label = gr.outputs.Label()\n",
|
106 |
"interface = gr.Interface(fn=classify_image,inputs=image,outputs=label)\n",
|
107 |
-
"
|
108 |
-
"interface.launch(inline=False)"
|
109 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}
|
111 |
],
|
112 |
"metadata": {
|
|
|
23 |
},
|
24 |
{
|
25 |
"cell_type": "code",
|
26 |
+
"execution_count": 9,
|
27 |
"id": "34ebdca4",
|
28 |
"metadata": {},
|
29 |
"outputs": [],
|
30 |
"source": [
|
31 |
+
"path = Path('construction_photos')"
|
32 |
]
|
33 |
},
|
34 |
{
|
35 |
"cell_type": "code",
|
36 |
+
"execution_count": 12,
|
37 |
"id": "04347f65",
|
38 |
"metadata": {},
|
39 |
+
"outputs": [
|
40 |
+
{
|
41 |
+
"data": {
|
42 |
+
"text/plain": [
|
43 |
+
"['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver']"
|
44 |
+
]
|
45 |
+
},
|
46 |
+
"execution_count": 12,
|
47 |
+
"metadata": {},
|
48 |
+
"output_type": "execute_result"
|
49 |
+
}
|
50 |
+
],
|
51 |
"source": [
|
52 |
+
"dls = DataBlock(\n",
|
53 |
+
" blocks=(ImageBlock,CategoryBlock),\n",
|
54 |
+
" getters=None,\n",
|
55 |
+
" n_inp=None,\n",
|
56 |
+
" item_tfms=[Resize(224,method='squish')],\n",
|
57 |
+
" get_items=get_image_files,\n",
|
58 |
+
" splitter=RandomSplitter(seed=42),\n",
|
59 |
+
" get_y=parent_label,\n",
|
60 |
+
").dataloaders('../python_clean_code_book/construction_photos/',bs=128)\n",
|
61 |
+
"# ).dataloaders()\n",
|
62 |
+
"#['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver']\n",
|
63 |
+
"dls.vocab"
|
64 |
]
|
65 |
},
|
66 |
{
|
|
|
75 |
},
|
76 |
{
|
77 |
"cell_type": "code",
|
78 |
+
"execution_count": 13,
|
79 |
"id": "a6ed198b",
|
80 |
"metadata": {},
|
81 |
"outputs": [],
|
82 |
"source": [
|
83 |
"def classify_image(img):\n",
|
84 |
" pred,idx,probs = learn.predict(img)\n",
|
85 |
+
" return dict(zip(['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver'],map(float,probs)))\n",
|
86 |
"# classify_image(get_image_files(path)[100])"
|
87 |
]
|
88 |
},
|
89 |
{
|
90 |
"cell_type": "code",
|
91 |
+
"execution_count": 14,
|
92 |
+
"id": "dccf379e",
|
93 |
+
"metadata": {},
|
94 |
+
"outputs": [
|
95 |
+
{
|
96 |
+
"data": {
|
97 |
+
"text/html": [
|
98 |
+
"\n",
|
99 |
+
"<style>\n",
|
100 |
+
" /* Turns off some styling */\n",
|
101 |
+
" progress {\n",
|
102 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
103 |
+
" border: none;\n",
|
104 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
105 |
+
" background-size: auto;\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 |
+
"{'construction boots': 5.033571142121218e-07,\n",
|
133 |
+
" 'construction gloves': 1.9164571085639182e-07,\n",
|
134 |
+
" 'f150': 0.9999986886978149,\n",
|
135 |
+
" 'hammer': 2.487358869984746e-07,\n",
|
136 |
+
" 'hard hat': 9.779357412753598e-08,\n",
|
137 |
+
" 'safety glasses': 2.88559984795711e-08,\n",
|
138 |
+
" 'screw driver': 1.963149287576016e-07}"
|
139 |
+
]
|
140 |
+
},
|
141 |
+
"execution_count": 14,
|
142 |
+
"metadata": {},
|
143 |
+
"output_type": "execute_result"
|
144 |
+
}
|
145 |
+
],
|
146 |
+
"source": [
|
147 |
+
"classify_image('../../ebs1/python_clean_code_book/construction_photos/f150/00000000.jpg')"
|
148 |
+
]
|
149 |
+
},
|
150 |
+
{
|
151 |
+
"cell_type": "code",
|
152 |
+
"execution_count": 15,
|
153 |
"id": "b2f582a8",
|
154 |
"metadata": {},
|
155 |
"outputs": [
|
|
|
157 |
"name": "stdout",
|
158 |
"output_type": "stream",
|
159 |
"text": [
|
160 |
+
"Running on local URL: http://127.0.0.1:7861/\n",
|
161 |
+
"Running on public URL: https://54519.gradio.app\n",
|
162 |
"\n",
|
163 |
+
"This share link expires in 72 hours. For free permanent hosting, check out Spaces (https://huggingface.co/spaces)\n"
|
164 |
]
|
165 |
},
|
166 |
+
{
|
167 |
+
"data": {
|
168 |
+
"text/html": [
|
169 |
+
"\n",
|
170 |
+
" <iframe\n",
|
171 |
+
" width=\"900\"\n",
|
172 |
+
" height=\"500\"\n",
|
173 |
+
" src=\"https://54519.gradio.app\"\n",
|
174 |
+
" frameborder=\"0\"\n",
|
175 |
+
" allowfullscreen\n",
|
176 |
+
" \n",
|
177 |
+
" ></iframe>\n",
|
178 |
+
" "
|
179 |
+
],
|
180 |
+
"text/plain": [
|
181 |
+
"<IPython.lib.display.IFrame at 0x7f2dc985d640>"
|
182 |
+
]
|
183 |
+
},
|
184 |
+
"metadata": {},
|
185 |
+
"output_type": "display_data"
|
186 |
+
},
|
187 |
{
|
188 |
"data": {
|
189 |
"text/plain": [
|
190 |
+
"(<fastapi.applications.FastAPI at 0x7f2de255f3d0>,\n",
|
191 |
+
" 'http://127.0.0.1:7861/',\n",
|
192 |
+
" 'https://54519.gradio.app')"
|
193 |
]
|
194 |
},
|
195 |
+
"execution_count": 15,
|
196 |
"metadata": {},
|
197 |
"output_type": "execute_result"
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"data": {
|
201 |
+
"text/html": [
|
202 |
+
"\n",
|
203 |
+
"<style>\n",
|
204 |
+
" /* Turns off some styling */\n",
|
205 |
+
" progress {\n",
|
206 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
207 |
+
" border: none;\n",
|
208 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
209 |
+
" background-size: auto;\n",
|
210 |
+
" }\n",
|
211 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
212 |
+
" background: #F44336;\n",
|
213 |
+
" }\n",
|
214 |
+
"</style>\n"
|
215 |
+
],
|
216 |
+
"text/plain": [
|
217 |
+
"<IPython.core.display.HTML object>"
|
218 |
+
]
|
219 |
+
},
|
220 |
+
"metadata": {},
|
221 |
+
"output_type": "display_data"
|
222 |
+
},
|
223 |
+
{
|
224 |
+
"data": {
|
225 |
+
"text/html": [],
|
226 |
+
"text/plain": [
|
227 |
+
"<IPython.core.display.HTML object>"
|
228 |
+
]
|
229 |
+
},
|
230 |
+
"metadata": {},
|
231 |
+
"output_type": "display_data"
|
232 |
+
},
|
233 |
+
{
|
234 |
+
"name": "stderr",
|
235 |
+
"output_type": "stream",
|
236 |
+
"text": [
|
237 |
+
"Traceback (most recent call last):\n",
|
238 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/routes.py\", line 269, in predict\n",
|
239 |
+
" output = await run_in_threadpool(app.launchable.process_api, body, username)\n",
|
240 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/starlette/concurrency.py\", line 45, in run_in_threadpool\n",
|
241 |
+
" return await anyio.to_thread.run_sync(func, *args)\n",
|
242 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/anyio/to_thread.py\", line 28, in run_sync\n",
|
243 |
+
" return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,\n",
|
244 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/anyio/_backends/_asyncio.py\", line 818, in run_sync_in_worker_thread\n",
|
245 |
+
" return await future\n",
|
246 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/anyio/_backends/_asyncio.py\", line 754, in run\n",
|
247 |
+
" result = context.run(func, *args)\n",
|
248 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/interface.py\", line 573, in process_api\n",
|
249 |
+
" prediction, durations = self.process(raw_input)\n",
|
250 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/interface.py\", line 615, in process\n",
|
251 |
+
" predictions, durations = self.run_prediction(\n",
|
252 |
+
" File \"/root/miniconda/lib/python3.9/site-packages/gradio/interface.py\", line 531, in run_prediction\n",
|
253 |
+
" prediction = predict_fn(*processed_input)\n",
|
254 |
+
" File \"/tmp/ipykernel_11528/2341249033.py\", line 3, in classify_image\n",
|
255 |
+
" return dict(zip(dls.vocab,map(float,probs)))\n",
|
256 |
+
"NameError: name 'dls' is not defined\n"
|
257 |
+
]
|
258 |
}
|
259 |
],
|
260 |
"source": [
|
261 |
"image = gr.inputs.Image(shape=(192,192))\n",
|
262 |
"label = gr.outputs.Label()\n",
|
263 |
"interface = gr.Interface(fn=classify_image,inputs=image,outputs=label)\n",
|
264 |
+
"interface.launch(inline=True,share=True)\n",
|
265 |
+
"# interface.launch(inline=False)"
|
266 |
]
|
267 |
+
},
|
268 |
+
{
|
269 |
+
"cell_type": "code",
|
270 |
+
"execution_count": null,
|
271 |
+
"id": "4b39ddcb",
|
272 |
+
"metadata": {},
|
273 |
+
"outputs": [],
|
274 |
+
"source": []
|
275 |
}
|
276 |
],
|
277 |
"metadata": {
|
app.py
CHANGED
@@ -5,7 +5,7 @@ learn = load_learner('construction_things.pkl')
|
|
5 |
|
6 |
def classify_image(img):
|
7 |
pred,idx,probs = learn.predict(img)
|
8 |
-
return dict(zip(
|
9 |
|
10 |
image = gr.inputs.Image(shape=(192,192))
|
11 |
label = gr.outputs.Label()
|
|
|
5 |
|
6 |
def classify_image(img):
|
7 |
pred,idx,probs = learn.predict(img)
|
8 |
+
return dict(zip(['construction boots', 'construction gloves', 'f150', 'hammer', 'hard hat', 'safety glasses', 'screw driver'],map(float,probs)))
|
9 |
|
10 |
image = gr.inputs.Image(shape=(192,192))
|
11 |
label = gr.outputs.Label()
|
app.pyc
ADDED
Binary file (769 Bytes). View file
|
|