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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "f91e1910",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"#|default_exp app"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
+
"id": "cbdfe953",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"#|export\n",
|
21 |
+
"from fastai.vision.all import *\n",
|
22 |
+
"import gradio as gr\n",
|
23 |
+
"\n",
|
24 |
+
"def is_cat(x): return x[0].isupper()"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": 3,
|
30 |
+
"id": "a32b77a4",
|
31 |
+
"metadata": {},
|
32 |
+
"outputs": [],
|
33 |
+
"source": [
|
34 |
+
"im = PILImage.create('dog.jpeg')\n",
|
35 |
+
"im.thumbnail((192,192))"
|
36 |
+
]
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"cell_type": "code",
|
40 |
+
"execution_count": 4,
|
41 |
+
"id": "0ffe7ca2",
|
42 |
+
"metadata": {},
|
43 |
+
"outputs": [],
|
44 |
+
"source": [
|
45 |
+
"#|export\n",
|
46 |
+
"learn = load_learner('model.pkl')"
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": 5,
|
52 |
+
"id": "4fbbc235",
|
53 |
+
"metadata": {},
|
54 |
+
"outputs": [
|
55 |
+
{
|
56 |
+
"data": {
|
57 |
+
"text/html": [
|
58 |
+
"\n",
|
59 |
+
"<style>\n",
|
60 |
+
" /* Turns off some styling */\n",
|
61 |
+
" progress {\n",
|
62 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
63 |
+
" border: none;\n",
|
64 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
65 |
+
" background-size: auto;\n",
|
66 |
+
" }\n",
|
67 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
68 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
69 |
+
" }\n",
|
70 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
71 |
+
" background: #F44336;\n",
|
72 |
+
" }\n",
|
73 |
+
"</style>\n"
|
74 |
+
],
|
75 |
+
"text/plain": [
|
76 |
+
"<IPython.core.display.HTML object>"
|
77 |
+
]
|
78 |
+
},
|
79 |
+
"metadata": {},
|
80 |
+
"output_type": "display_data"
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"data": {
|
84 |
+
"text/html": [],
|
85 |
+
"text/plain": [
|
86 |
+
"<IPython.core.display.HTML object>"
|
87 |
+
]
|
88 |
+
},
|
89 |
+
"metadata": {},
|
90 |
+
"output_type": "display_data"
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"name": "stdout",
|
94 |
+
"output_type": "stream",
|
95 |
+
"text": [
|
96 |
+
"CPU times: user 262 ms, sys: 23.1 ms, total: 285 ms\n",
|
97 |
+
"Wall time: 62.5 ms\n"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"data": {
|
102 |
+
"text/plain": [
|
103 |
+
"('False', tensor(0), tensor([9.9985e-01, 1.5188e-04]))"
|
104 |
+
]
|
105 |
+
},
|
106 |
+
"execution_count": 5,
|
107 |
+
"metadata": {},
|
108 |
+
"output_type": "execute_result"
|
109 |
+
}
|
110 |
+
],
|
111 |
+
"source": [
|
112 |
+
"%time learn.predict(im)"
|
113 |
+
]
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"cell_type": "code",
|
117 |
+
"execution_count": 6,
|
118 |
+
"id": "f9135ca0",
|
119 |
+
"metadata": {},
|
120 |
+
"outputs": [],
|
121 |
+
"source": [
|
122 |
+
"#|export\n",
|
123 |
+
"\n",
|
124 |
+
"categories = ('Dog', 'Cat')\n",
|
125 |
+
"\n",
|
126 |
+
"def classify_image(img):\n",
|
127 |
+
" pred, idx, probs = learn.predict(img)\n",
|
128 |
+
" return dict(zip(categories, map(float,probs)))"
|
129 |
+
]
|
130 |
+
},
|
131 |
+
{
|
132 |
+
"cell_type": "code",
|
133 |
+
"execution_count": 7,
|
134 |
+
"id": "6379871a",
|
135 |
+
"metadata": {},
|
136 |
+
"outputs": [
|
137 |
+
{
|
138 |
+
"name": "stderr",
|
139 |
+
"output_type": "stream",
|
140 |
+
"text": [
|
141 |
+
"/Users/mohitgarg/mambaforge/lib/python3.10/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",
|
142 |
+
" warnings.warn(\n",
|
143 |
+
"/Users/mohitgarg/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
144 |
+
" warnings.warn(value)\n",
|
145 |
+
"/Users/mohitgarg/mambaforge/lib/python3.10/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",
|
146 |
+
" warnings.warn(\n",
|
147 |
+
"/Users/mohitgarg/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
148 |
+
" warnings.warn(value)\n"
|
149 |
+
]
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"name": "stdout",
|
153 |
+
"output_type": "stream",
|
154 |
+
"text": [
|
155 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
156 |
+
"\n",
|
157 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
158 |
+
]
|
159 |
+
},
|
160 |
+
{
|
161 |
+
"data": {
|
162 |
+
"text/plain": []
|
163 |
+
},
|
164 |
+
"execution_count": 7,
|
165 |
+
"metadata": {},
|
166 |
+
"output_type": "execute_result"
|
167 |
+
}
|
168 |
+
],
|
169 |
+
"source": [
|
170 |
+
"#|export\n",
|
171 |
+
"\n",
|
172 |
+
"image = gr.inputs.Image(shape=(192, 192))\n",
|
173 |
+
"label = gr.outputs.Label()\n",
|
174 |
+
"\n",
|
175 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n",
|
176 |
+
"intf.launch(inline=False)"
|
177 |
+
]
|
178 |
+
},
|
179 |
+
{
|
180 |
+
"cell_type": "code",
|
181 |
+
"execution_count": 15,
|
182 |
+
"id": "377fd772",
|
183 |
+
"metadata": {},
|
184 |
+
"outputs": [],
|
185 |
+
"source": [
|
186 |
+
"import nbdev\n",
|
187 |
+
"nbdev.export.nb_export('app.ipynb', '.')"
|
188 |
+
]
|
189 |
+
},
|
190 |
+
{
|
191 |
+
"cell_type": "code",
|
192 |
+
"execution_count": null,
|
193 |
+
"id": "9eaf11d9",
|
194 |
+
"metadata": {},
|
195 |
+
"outputs": [],
|
196 |
+
"source": []
|
197 |
+
}
|
198 |
+
],
|
199 |
+
"metadata": {
|
200 |
+
"kernelspec": {
|
201 |
+
"display_name": "Python 3 (ipykernel)",
|
202 |
+
"language": "python",
|
203 |
+
"name": "python3"
|
204 |
+
},
|
205 |
+
"language_info": {
|
206 |
+
"codemirror_mode": {
|
207 |
+
"name": "ipython",
|
208 |
+
"version": 3
|
209 |
+
},
|
210 |
+
"file_extension": ".py",
|
211 |
+
"mimetype": "text/x-python",
|
212 |
+
"name": "python",
|
213 |
+
"nbconvert_exporter": "python",
|
214 |
+
"pygments_lexer": "ipython3",
|
215 |
+
"version": "3.10.10"
|
216 |
+
}
|
217 |
+
},
|
218 |
+
"nbformat": 4,
|
219 |
+
"nbformat_minor": 5
|
220 |
+
}
|
app.py
CHANGED
@@ -1,17 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
def is_cat(x): return x[0].isupper()
|
5 |
|
|
|
6 |
learn = load_learner('model.pkl')
|
|
|
|
|
7 |
categories = ('Dog', 'Cat')
|
8 |
|
9 |
def classify_image(img):
|
10 |
pred, idx, probs = learn.predict(img)
|
11 |
return dict(zip(categories, map(float,probs)))
|
12 |
|
|
|
13 |
image = gr.inputs.Image(shape=(192, 192))
|
14 |
label = gr.outputs.Label()
|
15 |
|
16 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
|
17 |
-
intf.launch(inline=False
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'intf', 'is_cat', 'classify_image']
|
5 |
+
|
6 |
+
# %% app.ipynb 1
|
7 |
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
|
10 |
def is_cat(x): return x[0].isupper()
|
11 |
|
12 |
+
# %% app.ipynb 3
|
13 |
learn = load_learner('model.pkl')
|
14 |
+
|
15 |
+
# %% app.ipynb 5
|
16 |
categories = ('Dog', 'Cat')
|
17 |
|
18 |
def classify_image(img):
|
19 |
pred, idx, probs = learn.predict(img)
|
20 |
return dict(zip(categories, map(float,probs)))
|
21 |
|
22 |
+
# %% app.ipynb 6
|
23 |
image = gr.inputs.Image(shape=(192, 192))
|
24 |
label = gr.outputs.Label()
|
25 |
|
26 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
|
27 |
+
intf.launch(inline=False)
|
dog.jpeg
ADDED
![]() |
requirements.txt
CHANGED
@@ -91,3 +91,96 @@ uvicorn==0.21.1
|
|
91 |
wasabi==1.1.1
|
92 |
websockets==11.0.1
|
93 |
yarl==1.8.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
wasabi==1.1.1
|
92 |
websockets==11.0.1
|
93 |
yarl==1.8.2
|
94 |
+
aiofiles==23.1.0
|
95 |
+
aiohttp==3.8.4
|
96 |
+
aiosignal==1.3.1
|
97 |
+
altair==4.2.2
|
98 |
+
anyio==3.6.2
|
99 |
+
async-timeout==4.0.2
|
100 |
+
attrs==22.2.0
|
101 |
+
blis==0.7.9
|
102 |
+
catalogue==2.0.8
|
103 |
+
certifi==2022.12.7
|
104 |
+
charset-normalizer==3.1.0
|
105 |
+
click==8.1.3
|
106 |
+
confection==0.0.4
|
107 |
+
contourpy==1.0.7
|
108 |
+
cycler==0.11.0
|
109 |
+
cymem==2.0.7
|
110 |
+
entrypoints==0.4
|
111 |
+
fastai==2.7.12
|
112 |
+
fastapi==0.95.0
|
113 |
+
fastcore==1.5.29
|
114 |
+
fastdownload==0.0.7
|
115 |
+
fastprogress==1.0.3
|
116 |
+
ffmpy==0.3.0
|
117 |
+
filelock==3.11.0
|
118 |
+
fonttools==4.39.3
|
119 |
+
frozenlist==1.3.3
|
120 |
+
fsspec==2023.4.0
|
121 |
+
gradio==3.25.0
|
122 |
+
gradio_client==0.0.8
|
123 |
+
h11==0.14.0
|
124 |
+
httpcore==0.16.3
|
125 |
+
httpx==0.23.3
|
126 |
+
huggingface-hub==0.13.4
|
127 |
+
idna==3.4
|
128 |
+
Jinja2==3.1.2
|
129 |
+
joblib==1.2.0
|
130 |
+
jsonschema==4.17.3
|
131 |
+
kiwisolver==1.4.4
|
132 |
+
langcodes==3.3.0
|
133 |
+
linkify-it-py==2.0.0
|
134 |
+
markdown-it-py==2.2.0
|
135 |
+
MarkupSafe==2.1.2
|
136 |
+
matplotlib==3.7.1
|
137 |
+
mdit-py-plugins==0.3.3
|
138 |
+
mdurl==0.1.2
|
139 |
+
mpmath==1.3.0
|
140 |
+
multidict==6.0.4
|
141 |
+
murmurhash==1.0.9
|
142 |
+
networkx==3.1
|
143 |
+
numpy==1.24.2
|
144 |
+
orjson==3.8.10
|
145 |
+
packaging==23.0
|
146 |
+
pandas==2.0.0
|
147 |
+
pathy==0.10.1
|
148 |
+
Pillow==9.5.0
|
149 |
+
preshed==3.0.8
|
150 |
+
pydantic==1.10.7
|
151 |
+
pydub==0.25.1
|
152 |
+
pyparsing==3.0.9
|
153 |
+
pyrsistent==0.19.3
|
154 |
+
python-dateutil==2.8.2
|
155 |
+
python-multipart==0.0.6
|
156 |
+
pytz==2023.3
|
157 |
+
PyYAML==6.0
|
158 |
+
requests==2.28.2
|
159 |
+
rfc3986==1.5.0
|
160 |
+
scikit-learn==1.2.2
|
161 |
+
scipy==1.10.1
|
162 |
+
semantic-version==2.10.0
|
163 |
+
six==1.16.0
|
164 |
+
smart-open==6.3.0
|
165 |
+
sniffio==1.3.0
|
166 |
+
spacy==3.5.1
|
167 |
+
spacy-legacy==3.0.12
|
168 |
+
spacy-loggers==1.0.4
|
169 |
+
srsly==2.4.6
|
170 |
+
starlette==0.26.1
|
171 |
+
sympy==1.11.1
|
172 |
+
thinc==8.1.9
|
173 |
+
threadpoolctl==3.1.0
|
174 |
+
toolz==0.12.0
|
175 |
+
torch==2.0.0
|
176 |
+
torchvision==0.15.1
|
177 |
+
tqdm==4.65.0
|
178 |
+
typer==0.7.0
|
179 |
+
typing_extensions==4.5.0
|
180 |
+
tzdata==2023.3
|
181 |
+
uc-micro-py==1.0.1
|
182 |
+
urllib3==1.26.15
|
183 |
+
uvicorn==0.21.1
|
184 |
+
wasabi==1.1.1
|
185 |
+
websockets==11.0.1
|
186 |
+
yarl==1.8.2
|