Gavin Francis
commited on
Commit
•
9427311
1
Parent(s):
a3de1a8
Added blog post
Browse filesAdded blog post comment and changed top 3 labels code
- FilmStarsApp.ipynb +16 -56
- app.py +7 -6
FilmStarsApp.ipynb
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
},
|
11 |
{
|
12 |
"cell_type": "code",
|
13 |
-
"execution_count":
|
14 |
"id": "37d47b60",
|
15 |
"metadata": {},
|
16 |
"outputs": [],
|
@@ -20,7 +20,7 @@
|
|
20 |
},
|
21 |
{
|
22 |
"cell_type": "code",
|
23 |
-
"execution_count":
|
24 |
"id": "96a084dc",
|
25 |
"metadata": {},
|
26 |
"outputs": [],
|
@@ -32,7 +32,7 @@
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
-
"execution_count":
|
36 |
"id": "0dd4db80",
|
37 |
"metadata": {},
|
38 |
"outputs": [],
|
@@ -42,7 +42,7 @@
|
|
42 |
},
|
43 |
{
|
44 |
"cell_type": "code",
|
45 |
-
"execution_count":
|
46 |
"id": "cf73c204",
|
47 |
"metadata": {},
|
48 |
"outputs": [],
|
@@ -53,89 +53,49 @@
|
|
53 |
},
|
54 |
{
|
55 |
"cell_type": "code",
|
56 |
-
"execution_count":
|
57 |
"id": "18bfac9a",
|
58 |
"metadata": {},
|
59 |
"outputs": [],
|
60 |
"source": [
|
61 |
"#|export\n",
|
|
|
62 |
"def classify_image(pic):\n",
|
63 |
" pred,pred_idx,probs = learn50.predict(PILImage.create(pic))\n",
|
64 |
-
" ps, idxs = probs.topk(3)\n",
|
65 |
-
" return
|
66 |
]
|
67 |
},
|
68 |
{
|
69 |
"cell_type": "code",
|
70 |
-
"execution_count":
|
71 |
"id": "d49e1a0e",
|
72 |
"metadata": {},
|
73 |
-
"outputs": [
|
74 |
-
{
|
75 |
-
"data": {
|
76 |
-
"text/html": [],
|
77 |
-
"text/plain": [
|
78 |
-
"<IPython.core.display.HTML object>"
|
79 |
-
]
|
80 |
-
},
|
81 |
-
"metadata": {},
|
82 |
-
"output_type": "display_data"
|
83 |
-
},
|
84 |
-
{
|
85 |
-
"data": {
|
86 |
-
"text/plain": [
|
87 |
-
"{'Penelope Cruz': 0.5769789218902588,\n",
|
88 |
-
" 'Halle Berry': 0.12028565257787704,\n",
|
89 |
-
" 'Angelina Jolie': 0.08253376185894012}"
|
90 |
-
]
|
91 |
-
},
|
92 |
-
"execution_count": 7,
|
93 |
-
"metadata": {},
|
94 |
-
"output_type": "execute_result"
|
95 |
-
}
|
96 |
-
],
|
97 |
"source": [
|
98 |
-
"classify_image(pic)"
|
99 |
]
|
100 |
},
|
101 |
{
|
102 |
"cell_type": "code",
|
103 |
-
"execution_count":
|
104 |
"id": "773dab23",
|
105 |
"metadata": {},
|
106 |
-
"outputs": [
|
107 |
-
{
|
108 |
-
"name": "stdout",
|
109 |
-
"output_type": "stream",
|
110 |
-
"text": [
|
111 |
-
"Running on local URL: http://127.0.0.1:7860\n",
|
112 |
-
"\n",
|
113 |
-
"To create a public link, set `share=True` in `launch()`.\n"
|
114 |
-
]
|
115 |
-
},
|
116 |
-
{
|
117 |
-
"data": {
|
118 |
-
"text/plain": []
|
119 |
-
},
|
120 |
-
"execution_count": 8,
|
121 |
-
"metadata": {},
|
122 |
-
"output_type": "execute_result"
|
123 |
-
}
|
124 |
-
],
|
125 |
"source": [
|
126 |
"#|export\n",
|
127 |
"image = gr.components.Image()\n",
|
128 |
-
"label = gr.components.Label()\n",
|
129 |
"examples = ['Angelina Jolie.jpg','Penelope Cruz.jpg','Jack Nicholson.jpg']\n",
|
130 |
"title = \"Identify film stars similar to your image\"\n",
|
131 |
"description = \"Try uploading a photograph of yourself\"\n",
|
132 |
-
"
|
|
|
133 |
"intfr.launch(inline=False)"
|
134 |
]
|
135 |
},
|
136 |
{
|
137 |
"cell_type": "code",
|
138 |
-
"execution_count":
|
139 |
"id": "705f241c",
|
140 |
"metadata": {},
|
141 |
"outputs": [],
|
|
|
10 |
},
|
11 |
{
|
12 |
"cell_type": "code",
|
13 |
+
"execution_count": null,
|
14 |
"id": "37d47b60",
|
15 |
"metadata": {},
|
16 |
"outputs": [],
|
|
|
20 |
},
|
21 |
{
|
22 |
"cell_type": "code",
|
23 |
+
"execution_count": null,
|
24 |
"id": "96a084dc",
|
25 |
"metadata": {},
|
26 |
"outputs": [],
|
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
+
"execution_count": null,
|
36 |
"id": "0dd4db80",
|
37 |
"metadata": {},
|
38 |
"outputs": [],
|
|
|
42 |
},
|
43 |
{
|
44 |
"cell_type": "code",
|
45 |
+
"execution_count": null,
|
46 |
"id": "cf73c204",
|
47 |
"metadata": {},
|
48 |
"outputs": [],
|
|
|
53 |
},
|
54 |
{
|
55 |
"cell_type": "code",
|
56 |
+
"execution_count": null,
|
57 |
"id": "18bfac9a",
|
58 |
"metadata": {},
|
59 |
"outputs": [],
|
60 |
"source": [
|
61 |
"#|export\n",
|
62 |
+
"labels = learn50.dls.vocab\n",
|
63 |
"def classify_image(pic):\n",
|
64 |
" pred,pred_idx,probs = learn50.predict(PILImage.create(pic))\n",
|
65 |
+
" #ps, idxs = probs.topk(3)\n",
|
66 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}\n"
|
67 |
]
|
68 |
},
|
69 |
{
|
70 |
"cell_type": "code",
|
71 |
+
"execution_count": null,
|
72 |
"id": "d49e1a0e",
|
73 |
"metadata": {},
|
74 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
"source": [
|
76 |
+
"classify_image(pic);"
|
77 |
]
|
78 |
},
|
79 |
{
|
80 |
"cell_type": "code",
|
81 |
+
"execution_count": null,
|
82 |
"id": "773dab23",
|
83 |
"metadata": {},
|
84 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
"source": [
|
86 |
"#|export\n",
|
87 |
"image = gr.components.Image()\n",
|
|
|
88 |
"examples = ['Angelina Jolie.jpg','Penelope Cruz.jpg','Jack Nicholson.jpg']\n",
|
89 |
"title = \"Identify film stars similar to your image\"\n",
|
90 |
"description = \"Try uploading a photograph of yourself\"\n",
|
91 |
+
"article = \"<p style='text-align: center'><a href='https://science4performance.com/2023/01/01/eddy-goes-to-hollywood/' target='_blank'>Blog post</a></p>\"\n",
|
92 |
+
"intfr = gr.Interface(fn=classify_image, inputs=image, outputs=gr.components.Label(num_top_classes=3), examples=examples, title=title, description=description, article=article)\n",
|
93 |
"intfr.launch(inline=False)"
|
94 |
]
|
95 |
},
|
96 |
{
|
97 |
"cell_type": "code",
|
98 |
+
"execution_count": 17,
|
99 |
"id": "705f241c",
|
100 |
"metadata": {},
|
101 |
"outputs": [],
|
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../FilmStarsApp.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['learn50', '
|
5 |
|
6 |
# %% ../FilmStarsApp.ipynb 2
|
7 |
from fastai.vision.all import *
|
@@ -11,17 +11,18 @@ import gradio as gr
|
|
11 |
learn50 = load_learner('filmstars50.pkl')
|
12 |
|
13 |
# %% ../FilmStarsApp.ipynb 5
|
|
|
14 |
def classify_image(pic):
|
15 |
pred,pred_idx,probs = learn50.predict(PILImage.create(pic))
|
16 |
-
ps, idxs = probs.topk(3)
|
17 |
-
return
|
18 |
|
19 |
|
20 |
# %% ../FilmStarsApp.ipynb 7
|
21 |
image = gr.components.Image()
|
22 |
-
label = gr.components.Label()
|
23 |
examples = ['Angelina Jolie.jpg','Penelope Cruz.jpg','Jack Nicholson.jpg']
|
24 |
title = "Identify film stars similar to your image"
|
25 |
-
description = "Try uploading a
|
26 |
-
|
|
|
27 |
intfr.launch(inline=False)
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: ../FilmStarsApp.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['learn50', 'labels', 'image', 'examples', 'title', 'description', 'article', 'intfr', 'classify_image']
|
5 |
|
6 |
# %% ../FilmStarsApp.ipynb 2
|
7 |
from fastai.vision.all import *
|
|
|
11 |
learn50 = load_learner('filmstars50.pkl')
|
12 |
|
13 |
# %% ../FilmStarsApp.ipynb 5
|
14 |
+
labels = learn50.dls.vocab
|
15 |
def classify_image(pic):
|
16 |
pred,pred_idx,probs = learn50.predict(PILImage.create(pic))
|
17 |
+
#ps, idxs = probs.topk(3)
|
18 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
19 |
|
20 |
|
21 |
# %% ../FilmStarsApp.ipynb 7
|
22 |
image = gr.components.Image()
|
|
|
23 |
examples = ['Angelina Jolie.jpg','Penelope Cruz.jpg','Jack Nicholson.jpg']
|
24 |
title = "Identify film stars similar to your image"
|
25 |
+
description = "Try uploading a photograph of yourself"
|
26 |
+
article = "<p style='text-align: center'><a href='https://science4performance.com/2023/01/01/eddy-goes-to-hollywood/' target='_blank'>Blog post</a></p>"
|
27 |
+
intfr = gr.Interface(fn=classify_image, inputs=image, outputs=gr.components.Label(num_top_classes=3), examples=examples, title=title, description=description, article=article)
|
28 |
intfr.launch(inline=False)
|