Gavin Francis
commited on
Commit
·
7c9dc7f
1
Parent(s):
6dade27
App ready
Browse filesImported model trained on Kaggle GPU
Set up app using Gradio
- Angelina Jolie.jpg +0 -0
- FilmStarsApp.ipynb +218 -0
- Jack Nicholson.jpg +0 -0
- Penelope Cruz.jpg +0 -0
- app.py +23 -4
- filmstars50.pkl +3 -0
Angelina Jolie.jpg
ADDED
FilmStarsApp.ipynb
ADDED
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"id": "77fbe5ae",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"# Film Stars Gradio App"
|
9 |
+
]
|
10 |
+
},
|
11 |
+
{
|
12 |
+
"cell_type": "code",
|
13 |
+
"execution_count": 1,
|
14 |
+
"id": "37d47b60",
|
15 |
+
"metadata": {},
|
16 |
+
"outputs": [],
|
17 |
+
"source": [
|
18 |
+
"#|default_exp app"
|
19 |
+
]
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"cell_type": "code",
|
23 |
+
"execution_count": 2,
|
24 |
+
"id": "96a084dc",
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [],
|
27 |
+
"source": [
|
28 |
+
"#|export\n",
|
29 |
+
"from fastai.vision.all import *\n",
|
30 |
+
"import gradio as gr"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": 3,
|
36 |
+
"id": "0dd4db80",
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [],
|
39 |
+
"source": [
|
40 |
+
"pic = 'Penelope Cruz.jpg'\n"
|
41 |
+
]
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"cell_type": "code",
|
45 |
+
"execution_count": 4,
|
46 |
+
"id": "cf73c204",
|
47 |
+
"metadata": {},
|
48 |
+
"outputs": [],
|
49 |
+
"source": [
|
50 |
+
"#|export\n",
|
51 |
+
"learn50 = load_learner('filmstars50.pkl')"
|
52 |
+
]
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"cell_type": "code",
|
56 |
+
"execution_count": 5,
|
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 dict(zip([learn50.dls.vocab[idx] for idx in idxs], map(float,ps)))\n"
|
66 |
+
]
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"cell_type": "code",
|
70 |
+
"execution_count": 6,
|
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": 6,
|
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": 7,
|
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": 7,
|
121 |
+
"metadata": {},
|
122 |
+
"output_type": "execute_result"
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"data": {
|
126 |
+
"text/html": [],
|
127 |
+
"text/plain": [
|
128 |
+
"<IPython.core.display.HTML object>"
|
129 |
+
]
|
130 |
+
},
|
131 |
+
"metadata": {},
|
132 |
+
"output_type": "display_data"
|
133 |
+
},
|
134 |
+
{
|
135 |
+
"data": {
|
136 |
+
"text/html": [],
|
137 |
+
"text/plain": [
|
138 |
+
"<IPython.core.display.HTML object>"
|
139 |
+
]
|
140 |
+
},
|
141 |
+
"metadata": {},
|
142 |
+
"output_type": "display_data"
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"data": {
|
146 |
+
"text/html": [],
|
147 |
+
"text/plain": [
|
148 |
+
"<IPython.core.display.HTML object>"
|
149 |
+
]
|
150 |
+
},
|
151 |
+
"metadata": {},
|
152 |
+
"output_type": "display_data"
|
153 |
+
}
|
154 |
+
],
|
155 |
+
"source": [
|
156 |
+
"#|export\n",
|
157 |
+
"image = gr.components.Image()\n",
|
158 |
+
"label = gr.components.Label()\n",
|
159 |
+
"examples = ['Angelina Jolie.jpg','Penelope Cruz.jpg','Jack Nicholson.jpg']\n",
|
160 |
+
"\n",
|
161 |
+
"intfr = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
162 |
+
"intfr.launch(inline=False)"
|
163 |
+
]
|
164 |
+
},
|
165 |
+
{
|
166 |
+
"cell_type": "code",
|
167 |
+
"execution_count": 10,
|
168 |
+
"id": "705f241c",
|
169 |
+
"metadata": {},
|
170 |
+
"outputs": [],
|
171 |
+
"source": [
|
172 |
+
"from nbdev.export import nb_export\n",
|
173 |
+
"nb_export('FilmStarsApp.ipynb')"
|
174 |
+
]
|
175 |
+
},
|
176 |
+
{
|
177 |
+
"cell_type": "code",
|
178 |
+
"execution_count": null,
|
179 |
+
"id": "cbaa52cc",
|
180 |
+
"metadata": {},
|
181 |
+
"outputs": [],
|
182 |
+
"source": []
|
183 |
+
}
|
184 |
+
],
|
185 |
+
"metadata": {
|
186 |
+
"kernelspec": {
|
187 |
+
"display_name": "Python (base)",
|
188 |
+
"language": "python",
|
189 |
+
"name": "base"
|
190 |
+
},
|
191 |
+
"language_info": {
|
192 |
+
"codemirror_mode": {
|
193 |
+
"name": "ipython",
|
194 |
+
"version": 3
|
195 |
+
},
|
196 |
+
"file_extension": ".py",
|
197 |
+
"mimetype": "text/x-python",
|
198 |
+
"name": "python",
|
199 |
+
"nbconvert_exporter": "python",
|
200 |
+
"pygments_lexer": "ipython3",
|
201 |
+
"version": "3.10.8"
|
202 |
+
},
|
203 |
+
"toc": {
|
204 |
+
"nav_menu": {},
|
205 |
+
"number_sections": true,
|
206 |
+
"sideBar": true,
|
207 |
+
"skip_h1_title": false,
|
208 |
+
"title_cell": "Table of Contents",
|
209 |
+
"title_sidebar": "Contents",
|
210 |
+
"toc_cell": false,
|
211 |
+
"toc_position": {},
|
212 |
+
"toc_section_display": true,
|
213 |
+
"toc_window_display": false
|
214 |
+
}
|
215 |
+
},
|
216 |
+
"nbformat": 4,
|
217 |
+
"nbformat_minor": 5
|
218 |
+
}
|
Jack Nicholson.jpg
ADDED
Penelope Cruz.jpg
ADDED
app.py
CHANGED
@@ -1,7 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../FilmStarsApp.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn50', 'image', 'label', 'examples', 'intfr', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../FilmStarsApp.ipynb 2
|
7 |
+
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
|
10 |
+
# %% ../FilmStarsApp.ipynb 4
|
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 dict(zip([learn50.dls.vocab[idx] for idx in idxs], map(float,ps)))
|
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 |
|
25 |
+
intfr = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
26 |
+
intfr.launch(inline=False)
|
filmstars50.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67b9b502101a5daa664736bee814aa3773fbb6f60e53f3f24e3e1ce29dde8554
|
3 |
+
size 103651871
|