jeffreymjohnson commited on
Commit
ced6706
·
1 Parent(s): ca286eb

app complete

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .ipynb_checkpoints
2
+ *.Identifier
Deadpool-Detector.ipynb CHANGED
@@ -39,7 +39,7 @@
39
  },
40
  {
41
  "cell_type": "code",
42
- "execution_count": null,
43
  "id": "61850308-6410-412b-a0a3-2a9c8c5ac982",
44
  "metadata": {},
45
  "outputs": [],
@@ -49,7 +49,7 @@
49
  },
50
  {
51
  "cell_type": "code",
52
- "execution_count": null,
53
  "id": "3e665c52-32ba-40a7-b100-480e60d128f6",
54
  "metadata": {},
55
  "outputs": [],
@@ -171,7 +171,7 @@
171
  },
172
  {
173
  "cell_type": "code",
174
- "execution_count": 1,
175
  "id": "f678e4ce-6b99-45b2-ae12-3e3a6978fe0a",
176
  "metadata": {},
177
  "outputs": [],
@@ -182,7 +182,7 @@
182
  },
183
  {
184
  "cell_type": "code",
185
- "execution_count": 2,
186
  "id": "cebedb5a-32ed-483d-90ce-9ccf101bda42",
187
  "metadata": {},
188
  "outputs": [],
@@ -193,7 +193,7 @@
193
  },
194
  {
195
  "cell_type": "code",
196
- "execution_count": 3,
197
  "id": "cc0fa8a2-51fe-4591-9056-e84e0fec9af7",
198
  "metadata": {},
199
  "outputs": [],
@@ -201,23 +201,45 @@
201
  "#|export\n",
202
  "labels = learn.dls.vocab\n",
203
  "def predict(img):\n",
 
 
 
 
204
  " img = PILImage.create(img)\n",
205
  " pred,pred_idx,probs = learn.predict(img)\n",
206
- " return {labels[i]: float(probs[i]) for i in range(len(labels))}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  ]
208
  },
209
  {
210
  "cell_type": "code",
211
- "execution_count": 7,
212
  "id": "3cec4455-8159-457b-9563-7e41aa202dc1",
213
- "metadata": {},
 
 
214
  "outputs": [
215
  {
216
  "name": "stdout",
217
  "output_type": "stream",
218
  "text": [
219
- "Running on local URL: http://127.0.0.1:7863\n",
220
- "Running on public URL: https://40a72959264a859fdc.gradio.live\n",
221
  "\n",
222
  "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
223
  ]
@@ -225,108 +247,7 @@
225
  {
226
  "data": {
227
  "text/html": [
228
- "<div><iframe src=\"https://40a72959264a859fdc.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
229
- ],
230
- "text/plain": [
231
- "<IPython.core.display.HTML object>"
232
- ]
233
- },
234
- "metadata": {},
235
- "output_type": "display_data"
236
- },
237
- {
238
- "data": {
239
- "text/html": [
240
- "\n",
241
- "<style>\n",
242
- " /* Turns off some styling */\n",
243
- " progress {\n",
244
- " /* gets rid of default border in Firefox and Opera. */\n",
245
- " border: none;\n",
246
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
247
- " background-size: auto;\n",
248
- " }\n",
249
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
250
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
251
- " }\n",
252
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
253
- " background: #F44336;\n",
254
- " }\n",
255
- "</style>\n"
256
- ],
257
- "text/plain": [
258
- "<IPython.core.display.HTML object>"
259
- ]
260
- },
261
- "metadata": {},
262
- "output_type": "display_data"
263
- },
264
- {
265
- "data": {
266
- "text/html": [],
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
- "\n",
278
- "<style>\n",
279
- " /* Turns off some styling */\n",
280
- " progress {\n",
281
- " /* gets rid of default border in Firefox and Opera. */\n",
282
- " border: none;\n",
283
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
284
- " background-size: auto;\n",
285
- " }\n",
286
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
287
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
288
- " }\n",
289
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
290
- " background: #F44336;\n",
291
- " }\n",
292
- "</style>\n"
293
- ],
294
- "text/plain": [
295
- "<IPython.core.display.HTML object>"
296
- ]
297
- },
298
- "metadata": {},
299
- "output_type": "display_data"
300
- },
301
- {
302
- "data": {
303
- "text/html": [],
304
- "text/plain": [
305
- "<IPython.core.display.HTML object>"
306
- ]
307
- },
308
- "metadata": {},
309
- "output_type": "display_data"
310
- },
311
- {
312
- "data": {
313
- "text/html": [
314
- "\n",
315
- "<style>\n",
316
- " /* Turns off some styling */\n",
317
- " progress {\n",
318
- " /* gets rid of default border in Firefox and Opera. */\n",
319
- " border: none;\n",
320
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
321
- " background-size: auto;\n",
322
- " }\n",
323
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
324
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
325
- " }\n",
326
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
327
- " background: #F44336;\n",
328
- " }\n",
329
- "</style>\n"
330
  ],
331
  "text/plain": [
332
  "<IPython.core.display.HTML object>"
@@ -334,16 +255,6 @@
334
  },
335
  "metadata": {},
336
  "output_type": "display_data"
337
- },
338
- {
339
- "data": {
340
- "text/html": [],
341
- "text/plain": [
342
- "<IPython.core.display.HTML object>"
343
- ]
344
- },
345
- "metadata": {},
346
- "output_type": "display_data"
347
  }
348
  ],
349
  "source": [
@@ -354,7 +265,7 @@
354
  " title=\"Deadpool™️ Detector\",\n",
355
  " fn=predict,\n",
356
  " inputs=gr.Image(shape=(200,200)),\n",
357
- " outputs=gr.Label(num_top_classes=-3),\n",
358
  " examples=[\"examples/deadpool_example1.jpg\", \"examples/deadpool_example2.jpg\", \"examples/deadpool_example3.jpg\", \"examples/spiderman.jpg\",]\n",
359
  ").launch(share=true)"
360
  ]
@@ -362,7 +273,7 @@
362
  {
363
  "cell_type": "code",
364
  "execution_count": null,
365
- "id": "018d3761-beac-4999-b915-32e61297db7c",
366
  "metadata": {},
367
  "outputs": [],
368
  "source": []
 
39
  },
40
  {
41
  "cell_type": "code",
42
+ "execution_count": 102,
43
  "id": "61850308-6410-412b-a0a3-2a9c8c5ac982",
44
  "metadata": {},
45
  "outputs": [],
 
49
  },
50
  {
51
  "cell_type": "code",
52
+ "execution_count": 103,
53
  "id": "3e665c52-32ba-40a7-b100-480e60d128f6",
54
  "metadata": {},
55
  "outputs": [],
 
171
  },
172
  {
173
  "cell_type": "code",
174
+ "execution_count": 104,
175
  "id": "f678e4ce-6b99-45b2-ae12-3e3a6978fe0a",
176
  "metadata": {},
177
  "outputs": [],
 
182
  },
183
  {
184
  "cell_type": "code",
185
+ "execution_count": 105,
186
  "id": "cebedb5a-32ed-483d-90ce-9ccf101bda42",
187
  "metadata": {},
188
  "outputs": [],
 
193
  },
194
  {
195
  "cell_type": "code",
196
+ "execution_count": 106,
197
  "id": "cc0fa8a2-51fe-4591-9056-e84e0fec9af7",
198
  "metadata": {},
199
  "outputs": [],
 
201
  "#|export\n",
202
  "labels = learn.dls.vocab\n",
203
  "def predict(img):\n",
204
+ " yes_reaction = \"reactions/yes.jfif\"\n",
205
+ " no_reaction = \"reactions/no.jfif\"\n",
206
+ " what_reaction = \"reactions/what.jpg\"\n",
207
+ " \n",
208
  " img = PILImage.create(img)\n",
209
  " pred,pred_idx,probs = learn.predict(img)\n",
210
+ " index = pred_idx.item()\n",
211
+ " probability = probs[index].item()\n",
212
+ " isDeadpool = pred == \"Deadpool\"\n",
213
+ " \n",
214
+ " if isDeadpool:\n",
215
+ " x = \"is\"\n",
216
+ " else:\n",
217
+ " x = \"is not\"\n",
218
+ " \n",
219
+ " print(\"The probability is: [\" + str(probability) + \"] that this \" + x + \" Deadpool\")\n",
220
+ " \n",
221
+ " if probability < .75:\n",
222
+ " return PILImage.create(what_reaction)\n",
223
+ " elif isDeadpool:\n",
224
+ " return PILImage.create(yes_reaction)\n",
225
+ " else:\n",
226
+ " return PILImage.create(no_reaction)"
227
  ]
228
  },
229
  {
230
  "cell_type": "code",
231
+ "execution_count": 107,
232
  "id": "3cec4455-8159-457b-9563-7e41aa202dc1",
233
+ "metadata": {
234
+ "tags": []
235
+ },
236
  "outputs": [
237
  {
238
  "name": "stdout",
239
  "output_type": "stream",
240
  "text": [
241
+ "Running on local URL: http://127.0.0.1:7905\n",
242
+ "Running on public URL: https://db2b51c5e39e6fc032.gradio.live\n",
243
  "\n",
244
  "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
245
  ]
 
247
  {
248
  "data": {
249
  "text/html": [
250
+ "<div><iframe src=\"https://db2b51c5e39e6fc032.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  ],
252
  "text/plain": [
253
  "<IPython.core.display.HTML object>"
 
255
  },
256
  "metadata": {},
257
  "output_type": "display_data"
 
 
 
 
 
 
 
 
 
 
258
  }
259
  ],
260
  "source": [
 
265
  " title=\"Deadpool™️ Detector\",\n",
266
  " fn=predict,\n",
267
  " inputs=gr.Image(shape=(200,200)),\n",
268
+ " outputs=gr.Image(shape=(200,200)), \n",
269
  " examples=[\"examples/deadpool_example1.jpg\", \"examples/deadpool_example2.jpg\", \"examples/deadpool_example3.jpg\", \"examples/spiderman.jpg\",]\n",
270
  ").launch(share=true)"
271
  ]
 
273
  {
274
  "cell_type": "code",
275
  "execution_count": null,
276
+ "id": "0c703c3c-f9a9-4c44-a1d5-44dd1d6189ae",
277
  "metadata": {},
278
  "outputs": [],
279
  "source": []
app.py CHANGED
@@ -1,12 +1,39 @@
 
1
  import gradio as gr
2
 
3
- def classify(input_img):
4
- out_image = input_img
5
- return out_image
6
 
7
- demo = gr.Interface(
8
- fn=classify,
9
- inputs=gr.Image(shape=(200,200)),
10
- outputs="image")
11
 
12
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
4
+ learn = load_learner('./deadpool-detection-model.pkl')
 
 
5
 
6
+ labels = learn.dls.vocab
 
 
 
7
 
8
+ def predict(img):
9
+ yes_reaction = "reactions/yes.jfif"
10
+ no_reaction = "reactions/no.jfif"
11
+ what_reaction = "reactions/what.jpg"
12
+
13
+ img = PILImage.create(img)
14
+ pred,pred_idx,probs = learn.predict(img)
15
+ index = pred_idx.item()
16
+ probability = probs[index].item()
17
+ isDeadpool = pred == "Deadpool"
18
+
19
+ if isDeadpool:
20
+ x = "is"
21
+ else:
22
+ x = "is not"
23
+
24
+ print("The probability is: [" + str(probability) + "] that this " + x + " Deadpool")
25
+
26
+ if probability < .75:
27
+ return PILImage.create(what_reaction)
28
+ elif isDeadpool:
29
+ return PILImage.create(yes_reaction)
30
+ else:
31
+ return PILImage.create(no_reaction)
32
+
33
+ demo = gr.Interface(
34
+ title="Deadpool™️ Detector",
35
+ fn=predict,
36
+ inputs=gr.Image(shape=(200,200)),
37
+ outputs=gr.Image(shape=(200,200)),
38
+ examples=["examples/deadpool_example1.jpg", "examples/deadpool_example2.jpg", "examples/deadpool_example3.jpg", "examples/spiderman.jpg",]
39
+ ).launch(share=true)
examples/deadpool_example1.jpg ADDED
examples/deadpool_example2.jpg ADDED
examples/deadpool_example3.jpg ADDED
examples/spiderman.jpg ADDED
reactions/no.jfif ADDED
Binary file (144 kB). View file
 
reactions/what.jpg ADDED
reactions/yes.jfif ADDED
Binary file (89.6 kB). View file