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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"id": "e8f0c0de",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"Defaulting to user installation because normal site-packages is not writeable\n",
|
14 |
+
"Collecting ruamel.yaml\n",
|
15 |
+
" Downloading ruamel.yaml-0.17.32-py3-none-any.whl (112 kB)\n",
|
16 |
+
" -------------------------------------- 112.2/112.2 kB 1.6 MB/s eta 0:00:00\n",
|
17 |
+
"Collecting ruamel.yaml.clib>=0.2.7\n",
|
18 |
+
" Downloading ruamel.yaml.clib-0.2.7-cp39-cp39-win_amd64.whl (118 kB)\n",
|
19 |
+
" -------------------------------------- 118.4/118.4 kB 6.8 MB/s eta 0:00:00\n",
|
20 |
+
"Installing collected packages: ruamel.yaml.clib, ruamel.yaml\n",
|
21 |
+
"Successfully installed ruamel.yaml-0.17.32 ruamel.yaml.clib-0.2.7\n"
|
22 |
+
]
|
23 |
+
}
|
24 |
+
],
|
25 |
+
"source": [
|
26 |
+
"!pip install ruamel.yaml"
|
27 |
+
]
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"cell_type": "code",
|
31 |
+
"execution_count": 5,
|
32 |
+
"id": "1c445cb6",
|
33 |
+
"metadata": {},
|
34 |
+
"outputs": [],
|
35 |
+
"source": [
|
36 |
+
"!pip install -Uqq fastai\n",
|
37 |
+
"from fastai import *"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "code",
|
42 |
+
"execution_count": 10,
|
43 |
+
"id": "60065e37",
|
44 |
+
"metadata": {},
|
45 |
+
"outputs": [
|
46 |
+
{
|
47 |
+
"name": "stdout",
|
48 |
+
"output_type": "stream",
|
49 |
+
"text": [
|
50 |
+
"Defaulting to user installation because normal site-packages is not writeable\n",
|
51 |
+
"Requirement already satisfied: torch in c:\\users\\victo\\appdata\\roaming\\python\\python39\\site-packages (2.0.1)\n",
|
52 |
+
"Requirement already satisfied: filelock in j:\\anaconda3\\lib\\site-packages (from torch) (3.6.0)\n",
|
53 |
+
"Requirement already satisfied: typing-extensions in c:\\users\\victo\\appdata\\roaming\\python\\python39\\site-packages (from torch) (4.7.1)\n",
|
54 |
+
"Requirement already satisfied: jinja2 in j:\\anaconda3\\lib\\site-packages (from torch) (2.11.3)\n",
|
55 |
+
"Requirement already satisfied: networkx in j:\\anaconda3\\lib\\site-packages (from torch) (2.8.4)\n",
|
56 |
+
"Requirement already satisfied: sympy in j:\\anaconda3\\lib\\site-packages (from torch) (1.10.1)\n",
|
57 |
+
"Requirement already satisfied: MarkupSafe>=0.23 in j:\\anaconda3\\lib\\site-packages (from jinja2->torch) (2.0.1)\n",
|
58 |
+
"Requirement already satisfied: mpmath>=0.19 in j:\\anaconda3\\lib\\site-packages (from sympy->torch) (1.2.1)\n"
|
59 |
+
]
|
60 |
+
}
|
61 |
+
],
|
62 |
+
"source": [
|
63 |
+
"!pip install torch"
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": 6,
|
69 |
+
"id": "8aecaaa1",
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"!pip install -Uqq scikit-image\n",
|
74 |
+
"!pip install -Uqq gradio"
|
75 |
+
]
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"cell_type": "code",
|
79 |
+
"execution_count": 23,
|
80 |
+
"id": "96a3aa78",
|
81 |
+
"metadata": {},
|
82 |
+
"outputs": [],
|
83 |
+
"source": [
|
84 |
+
"!pip install -Uqq pathlib"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"cell_type": "code",
|
89 |
+
"execution_count": 24,
|
90 |
+
"id": "070bdc04",
|
91 |
+
"metadata": {},
|
92 |
+
"outputs": [],
|
93 |
+
"source": [
|
94 |
+
"from fastai.vision.all import *\n",
|
95 |
+
"import pathlib\n",
|
96 |
+
"temp = pathlib.PosixPath\n",
|
97 |
+
"pathlib.PosixPath = pathlib.WindowsPath\n",
|
98 |
+
"learn = load_learner('C:/Users/Victo/Downloads/movie_era_model.pkl')\n",
|
99 |
+
"pathlib.PosixPath = temp"
|
100 |
+
]
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"cell_type": "code",
|
104 |
+
"execution_count": 25,
|
105 |
+
"id": "aef5f09b",
|
106 |
+
"metadata": {},
|
107 |
+
"outputs": [],
|
108 |
+
"source": [
|
109 |
+
"labels = learn.dls.vocab\n",
|
110 |
+
"def predict(img):\n",
|
111 |
+
" img = PILImage.create(img)\n",
|
112 |
+
" pred,pred_idx,probs = learn.predict(img)\n",
|
113 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"cell_type": "code",
|
118 |
+
"execution_count": 32,
|
119 |
+
"id": "eae89582",
|
120 |
+
"metadata": {},
|
121 |
+
"outputs": [],
|
122 |
+
"source": [
|
123 |
+
"import skimage\n",
|
124 |
+
"title = \"Movie Poster Era Classifier\"\n",
|
125 |
+
"description = \"This is a study project for models deployment via Gradio and HuggingFace Spaces. The app takes a movie poster as an input, returning probabilities of the poster being drawn either in 1900s-1960s, 1970s-1990s or later on. Pretrained resnet 101 was taken as a learner with being fine-tuned on 1500 posters of each period, retreived from DuckDuckGo search queries. Quality of the resulting model is quite low with 0.35 error rate after 11 epochs, but the aim was more to play around with Gradio, rather than crating working movie poster classifier. Full code for the model and deployment is featured on my GitHub page, linked below\"\n",
|
126 |
+
"examples = ['C:\\\\Users\\\\Victo\\\\Downloads\\\\example_1.jpeg', 'C:\\\\Users\\\\Victo\\\\Downloads\\\\example_2.jpeg', 'C:\\\\Users\\\\Victo\\\\Downloads\\\\example_3.jpeg']\n",
|
127 |
+
"article=\"<p style='text-align: center'><a href='https://github.com/VictorPakholkov/movie_era_posters_detection_gradio_app' target='_blank'>Github repo</a></p>\"\n",
|
128 |
+
"interpretation='default'\n",
|
129 |
+
"enable_queue=True"
|
130 |
+
]
|
131 |
+
},
|
132 |
+
{
|
133 |
+
"cell_type": "code",
|
134 |
+
"execution_count": 33,
|
135 |
+
"id": "602aa885",
|
136 |
+
"metadata": {},
|
137 |
+
"outputs": [
|
138 |
+
{
|
139 |
+
"name": "stderr",
|
140 |
+
"output_type": "stream",
|
141 |
+
"text": [
|
142 |
+
"C:\\Users\\Victo\\AppData\\Local\\Temp\\ipykernel_8184\\3255000909.py:3: GradioDeprecationWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
143 |
+
" inputs=gr.inputs.Image(shape=(512, 512)),\n",
|
144 |
+
"C:\\Users\\Victo\\AppData\\Local\\Temp\\ipykernel_8184\\3255000909.py:3: GradioDeprecationWarning: `optional` parameter is deprecated, and it has no effect\n",
|
145 |
+
" inputs=gr.inputs.Image(shape=(512, 512)),\n",
|
146 |
+
"C:\\Users\\Victo\\AppData\\Local\\Temp\\ipykernel_8184\\3255000909.py:4: GradioDeprecationWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
147 |
+
" outputs=gr.outputs.Label(num_top_classes=3),\n",
|
148 |
+
"C:\\Users\\Victo\\AppData\\Local\\Temp\\ipykernel_8184\\3255000909.py:4: GradioUnusedKwargWarning: You have unused kwarg parameters in Label, please remove them: {'type': 'auto'}\n",
|
149 |
+
" outputs=gr.outputs.Label(num_top_classes=3),\n",
|
150 |
+
"C:\\Users\\Victo\\AppData\\Local\\Temp\\ipykernel_8184\\3255000909.py:2: GradioDeprecationWarning: `enable_queue` is deprecated in `Interface()`, please use it within `launch()` instead.\n",
|
151 |
+
" gr.Interface(fn=predict,\n"
|
152 |
+
]
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"name": "stdout",
|
156 |
+
"output_type": "stream",
|
157 |
+
"text": [
|
158 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
159 |
+
"Running on public URL: https://6295736d4372057f9f.gradio.live\n",
|
160 |
+
"\n",
|
161 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
162 |
+
]
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"data": {
|
166 |
+
"text/html": [
|
167 |
+
"<div><iframe src=\"https://6295736d4372057f9f.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
168 |
+
],
|
169 |
+
"text/plain": [
|
170 |
+
"<IPython.core.display.HTML object>"
|
171 |
+
]
|
172 |
+
},
|
173 |
+
"metadata": {},
|
174 |
+
"output_type": "display_data"
|
175 |
+
},
|
176 |
+
{
|
177 |
+
"data": {
|
178 |
+
"text/plain": []
|
179 |
+
},
|
180 |
+
"execution_count": 33,
|
181 |
+
"metadata": {},
|
182 |
+
"output_type": "execute_result"
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"data": {
|
186 |
+
"text/html": [
|
187 |
+
"\n",
|
188 |
+
"<style>\n",
|
189 |
+
" /* Turns off some styling */\n",
|
190 |
+
" progress {\n",
|
191 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
192 |
+
" border: none;\n",
|
193 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
194 |
+
" background-size: auto;\n",
|
195 |
+
" }\n",
|
196 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
197 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
198 |
+
" }\n",
|
199 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
200 |
+
" background: #F44336;\n",
|
201 |
+
" }\n",
|
202 |
+
"</style>\n"
|
203 |
+
],
|
204 |
+
"text/plain": [
|
205 |
+
"<IPython.core.display.HTML object>"
|
206 |
+
]
|
207 |
+
},
|
208 |
+
"metadata": {},
|
209 |
+
"output_type": "display_data"
|
210 |
+
},
|
211 |
+
{
|
212 |
+
"data": {
|
213 |
+
"text/html": [],
|
214 |
+
"text/plain": [
|
215 |
+
"<IPython.core.display.HTML object>"
|
216 |
+
]
|
217 |
+
},
|
218 |
+
"metadata": {},
|
219 |
+
"output_type": "display_data"
|
220 |
+
},
|
221 |
+
{
|
222 |
+
"data": {
|
223 |
+
"text/html": [
|
224 |
+
"\n",
|
225 |
+
"<style>\n",
|
226 |
+
" /* Turns off some styling */\n",
|
227 |
+
" progress {\n",
|
228 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
229 |
+
" border: none;\n",
|
230 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
231 |
+
" background-size: auto;\n",
|
232 |
+
" }\n",
|
233 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
234 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
235 |
+
" }\n",
|
236 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
237 |
+
" background: #F44336;\n",
|
238 |
+
" }\n",
|
239 |
+
"</style>\n"
|
240 |
+
],
|
241 |
+
"text/plain": [
|
242 |
+
"<IPython.core.display.HTML object>"
|
243 |
+
]
|
244 |
+
},
|
245 |
+
"metadata": {},
|
246 |
+
"output_type": "display_data"
|
247 |
+
},
|
248 |
+
{
|
249 |
+
"data": {
|
250 |
+
"text/html": [],
|
251 |
+
"text/plain": [
|
252 |
+
"<IPython.core.display.HTML object>"
|
253 |
+
]
|
254 |
+
},
|
255 |
+
"metadata": {},
|
256 |
+
"output_type": "display_data"
|
257 |
+
},
|
258 |
+
{
|
259 |
+
"data": {
|
260 |
+
"text/html": [
|
261 |
+
"\n",
|
262 |
+
"<style>\n",
|
263 |
+
" /* Turns off some styling */\n",
|
264 |
+
" progress {\n",
|
265 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
266 |
+
" border: none;\n",
|
267 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
268 |
+
" background-size: auto;\n",
|
269 |
+
" }\n",
|
270 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
271 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
272 |
+
" }\n",
|
273 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
274 |
+
" background: #F44336;\n",
|
275 |
+
" }\n",
|
276 |
+
"</style>\n"
|
277 |
+
],
|
278 |
+
"text/plain": [
|
279 |
+
"<IPython.core.display.HTML object>"
|
280 |
+
]
|
281 |
+
},
|
282 |
+
"metadata": {},
|
283 |
+
"output_type": "display_data"
|
284 |
+
},
|
285 |
+
{
|
286 |
+
"data": {
|
287 |
+
"text/html": [],
|
288 |
+
"text/plain": [
|
289 |
+
"<IPython.core.display.HTML object>"
|
290 |
+
]
|
291 |
+
},
|
292 |
+
"metadata": {},
|
293 |
+
"output_type": "display_data"
|
294 |
+
},
|
295 |
+
{
|
296 |
+
"data": {
|
297 |
+
"text/html": [
|
298 |
+
"\n",
|
299 |
+
"<style>\n",
|
300 |
+
" /* Turns off some styling */\n",
|
301 |
+
" progress {\n",
|
302 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
303 |
+
" border: none;\n",
|
304 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
305 |
+
" background-size: auto;\n",
|
306 |
+
" }\n",
|
307 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
308 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
309 |
+
" }\n",
|
310 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
311 |
+
" background: #F44336;\n",
|
312 |
+
" }\n",
|
313 |
+
"</style>\n"
|
314 |
+
],
|
315 |
+
"text/plain": [
|
316 |
+
"<IPython.core.display.HTML object>"
|
317 |
+
]
|
318 |
+
},
|
319 |
+
"metadata": {},
|
320 |
+
"output_type": "display_data"
|
321 |
+
},
|
322 |
+
{
|
323 |
+
"data": {
|
324 |
+
"text/html": [],
|
325 |
+
"text/plain": [
|
326 |
+
"<IPython.core.display.HTML object>"
|
327 |
+
]
|
328 |
+
},
|
329 |
+
"metadata": {},
|
330 |
+
"output_type": "display_data"
|
331 |
+
}
|
332 |
+
],
|
333 |
+
"source": [
|
334 |
+
"import gradio as gr\n",
|
335 |
+
"gr.Interface(fn=predict,\n",
|
336 |
+
" inputs=gr.inputs.Image(shape=(512, 512)),\n",
|
337 |
+
" outputs=gr.outputs.Label(num_top_classes=3),\n",
|
338 |
+
" title=title,\n",
|
339 |
+
" description=description,\n",
|
340 |
+
" article=article,\n",
|
341 |
+
" examples=examples,\n",
|
342 |
+
" interpretation=interpretation,\n",
|
343 |
+
" enable_queue=enable_queue).launch(share=True)"
|
344 |
+
]
|
345 |
+
}
|
346 |
+
],
|
347 |
+
"metadata": {
|
348 |
+
"kernelspec": {
|
349 |
+
"display_name": "Python 3 (ipykernel)",
|
350 |
+
"language": "python",
|
351 |
+
"name": "python3"
|
352 |
+
},
|
353 |
+
"language_info": {
|
354 |
+
"codemirror_mode": {
|
355 |
+
"name": "ipython",
|
356 |
+
"version": 3
|
357 |
+
},
|
358 |
+
"file_extension": ".py",
|
359 |
+
"mimetype": "text/x-python",
|
360 |
+
"name": "python",
|
361 |
+
"nbconvert_exporter": "python",
|
362 |
+
"pygments_lexer": "ipython3",
|
363 |
+
"version": "3.9.13"
|
364 |
+
}
|
365 |
+
},
|
366 |
+
"nbformat": 4,
|
367 |
+
"nbformat_minor": 5
|
368 |
+
}
|
example_1.jpeg
ADDED
example_2.jpeg
ADDED
example_3.jpeg
ADDED
export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6521af37c93751bd3363da10476b7003ab7c56e7424ff7b8b6fb44f062f1ead3
|
3 |
+
size 179215523
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
fastai.vision.all
|
3 |
+
pathlib
|
4 |
+
gradio
|
5 |
+
skimage
|