Spaces:
Sleeping
Sleeping
Add app prototype
Browse files- prototype.ipynb +201 -0
prototype.ipynb
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "6169050c",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import gradio as gr\n",
|
11 |
+
"from fastai.vision.all import *"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 5,
|
17 |
+
"id": "f9d42773",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"learner = load_learner(\"./zidane_scholes_mbappe_resnet34.pkl\")\n",
|
22 |
+
"labels = learner.dls.vocab"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 6,
|
28 |
+
"id": "1d09c8aa",
|
29 |
+
"metadata": {},
|
30 |
+
"outputs": [],
|
31 |
+
"source": [
|
32 |
+
"def predict(img):\n",
|
33 |
+
" _, _, probs = learner.predict(img)\n",
|
34 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": 8,
|
40 |
+
"id": "6e94819f",
|
41 |
+
"metadata": {},
|
42 |
+
"outputs": [
|
43 |
+
{
|
44 |
+
"name": "stderr",
|
45 |
+
"output_type": "stream",
|
46 |
+
"text": [
|
47 |
+
"/Users/pvasudev/.virtualenvs/fast_ai/lib/python3.9/site-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
48 |
+
" warnings.warn(\n",
|
49 |
+
"/Users/pvasudev/.virtualenvs/fast_ai/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
50 |
+
" warnings.warn(value)\n",
|
51 |
+
"/Users/pvasudev/.virtualenvs/fast_ai/lib/python3.9/site-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
52 |
+
" warnings.warn(\n",
|
53 |
+
"/Users/pvasudev/.virtualenvs/fast_ai/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
54 |
+
" warnings.warn(value)\n"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"name": "stdout",
|
59 |
+
"output_type": "stream",
|
60 |
+
"text": [
|
61 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
62 |
+
"\n",
|
63 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"data": {
|
68 |
+
"text/html": [
|
69 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
70 |
+
],
|
71 |
+
"text/plain": [
|
72 |
+
"<IPython.core.display.HTML object>"
|
73 |
+
]
|
74 |
+
},
|
75 |
+
"metadata": {},
|
76 |
+
"output_type": "display_data"
|
77 |
+
},
|
78 |
+
{
|
79 |
+
"data": {
|
80 |
+
"text/plain": []
|
81 |
+
},
|
82 |
+
"execution_count": 8,
|
83 |
+
"metadata": {},
|
84 |
+
"output_type": "execute_result"
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"data": {
|
88 |
+
"text/html": [
|
89 |
+
"\n",
|
90 |
+
"<style>\n",
|
91 |
+
" /* Turns off some styling */\n",
|
92 |
+
" progress {\n",
|
93 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
94 |
+
" border: none;\n",
|
95 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
96 |
+
" background-size: auto;\n",
|
97 |
+
" }\n",
|
98 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
99 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
100 |
+
" }\n",
|
101 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
102 |
+
" background: #F44336;\n",
|
103 |
+
" }\n",
|
104 |
+
"</style>\n"
|
105 |
+
],
|
106 |
+
"text/plain": [
|
107 |
+
"<IPython.core.display.HTML object>"
|
108 |
+
]
|
109 |
+
},
|
110 |
+
"metadata": {},
|
111 |
+
"output_type": "display_data"
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"data": {
|
115 |
+
"text/html": [],
|
116 |
+
"text/plain": [
|
117 |
+
"<IPython.core.display.HTML object>"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
"metadata": {},
|
121 |
+
"output_type": "display_data"
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"data": {
|
125 |
+
"text/html": [
|
126 |
+
"\n",
|
127 |
+
"<style>\n",
|
128 |
+
" /* Turns off some styling */\n",
|
129 |
+
" progress {\n",
|
130 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
131 |
+
" border: none;\n",
|
132 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
133 |
+
" background-size: auto;\n",
|
134 |
+
" }\n",
|
135 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
136 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
137 |
+
" }\n",
|
138 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
139 |
+
" background: #F44336;\n",
|
140 |
+
" }\n",
|
141 |
+
"</style>\n"
|
142 |
+
],
|
143 |
+
"text/plain": [
|
144 |
+
"<IPython.core.display.HTML object>"
|
145 |
+
]
|
146 |
+
},
|
147 |
+
"metadata": {},
|
148 |
+
"output_type": "display_data"
|
149 |
+
},
|
150 |
+
{
|
151 |
+
"data": {
|
152 |
+
"text/html": [],
|
153 |
+
"text/plain": [
|
154 |
+
"<IPython.core.display.HTML object>"
|
155 |
+
]
|
156 |
+
},
|
157 |
+
"metadata": {},
|
158 |
+
"output_type": "display_data"
|
159 |
+
}
|
160 |
+
],
|
161 |
+
"source": [
|
162 |
+
"gr.Interface(\n",
|
163 |
+
" fn=predict,\n",
|
164 |
+
" inputs=gr.inputs.Image(shape=(512, 512)),\n",
|
165 |
+
" outputs=gr.outputs.Label(num_top_classes=3),\n",
|
166 |
+
" examples=[\n",
|
167 |
+
" \"zidane_01.jpg\",\n",
|
168 |
+
" \"zidane_02.jpg\",\n",
|
169 |
+
" \"scholes_01.jpg\",\n",
|
170 |
+
" \"scholes_02.jpg\",\n",
|
171 |
+
" \"mbappe_01.jpg\",\n",
|
172 |
+
" \"mbappe_02.jpg\"\n",
|
173 |
+
" ],\n",
|
174 |
+
" title=\"A simple app to differentiate pictures of three amazing footballers\",\n",
|
175 |
+
" description=\"Classify a picture of a footballer being either Kylian Mbappe, Zinedine Zidane, or Paul Scholes\"\n",
|
176 |
+
").launch()"
|
177 |
+
]
|
178 |
+
}
|
179 |
+
],
|
180 |
+
"metadata": {
|
181 |
+
"kernelspec": {
|
182 |
+
"display_name": "Python 3 (ipykernel)",
|
183 |
+
"language": "python",
|
184 |
+
"name": "python3"
|
185 |
+
},
|
186 |
+
"language_info": {
|
187 |
+
"codemirror_mode": {
|
188 |
+
"name": "ipython",
|
189 |
+
"version": 3
|
190 |
+
},
|
191 |
+
"file_extension": ".py",
|
192 |
+
"mimetype": "text/x-python",
|
193 |
+
"name": "python",
|
194 |
+
"nbconvert_exporter": "python",
|
195 |
+
"pygments_lexer": "ipython3",
|
196 |
+
"version": "3.9.6"
|
197 |
+
}
|
198 |
+
},
|
199 |
+
"nbformat": 4,
|
200 |
+
"nbformat_minor": 5
|
201 |
+
}
|