try autogen app.py with nbdev
Browse files- app-manual.py +23 -0
- app-nbdev.ipynb +197 -0
- app.py +13 -4
app-manual.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# necessary for load_learner not to complain about missing functions
|
5 |
+
def is_cat(x): return x[0].isupper()
|
6 |
+
|
7 |
+
learn = load_learner('model.pkl')
|
8 |
+
|
9 |
+
categories = ('Dog ', 'Cat')
|
10 |
+
|
11 |
+
def classify_image(img):
|
12 |
+
pred,idx,probs = learn.predict(img)
|
13 |
+
return dict(zip(categories, map(float,probs)))
|
14 |
+
|
15 |
+
inp_img = gr.inputs.Image(shape=(200,200))
|
16 |
+
out_label = gr.outputs.Label()
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=classify_image,
|
19 |
+
inputs=inp_img,
|
20 |
+
outputs=out_label,
|
21 |
+
title="Pet classifier")
|
22 |
+
|
23 |
+
iface.launch(inline=False)
|
app-nbdev.ipynb
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 10,
|
6 |
+
"id": "8ceccd3e",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"#| default_exp app-nbdev"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 11,
|
16 |
+
"id": "9cc2c7e8",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"#|export\n",
|
21 |
+
"from fastai.vision.all import *\n",
|
22 |
+
"import gradio as gr"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 12,
|
28 |
+
"id": "6cb828e7",
|
29 |
+
"metadata": {},
|
30 |
+
"outputs": [],
|
31 |
+
"source": [
|
32 |
+
"#|export\n",
|
33 |
+
"def is_cat(x): return x[0].isupper() "
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"execution_count": 13,
|
39 |
+
"id": "70a94ed8",
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": [
|
43 |
+
"#|export\n",
|
44 |
+
"learn = load_learner('model.pkl')"
|
45 |
+
]
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"cell_type": "code",
|
49 |
+
"execution_count": 14,
|
50 |
+
"id": "2856326d",
|
51 |
+
"metadata": {},
|
52 |
+
"outputs": [],
|
53 |
+
"source": [
|
54 |
+
"#|export\n",
|
55 |
+
"categories = ('Dog', 'Cat')\n",
|
56 |
+
"\n",
|
57 |
+
"def classify_image(img):\n",
|
58 |
+
" pred,idx,probs = learn.predict(img)\n",
|
59 |
+
" return dict(zip(categories, map(float,probs)))"
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"cell_type": "code",
|
64 |
+
"execution_count": 15,
|
65 |
+
"id": "a11b5552",
|
66 |
+
"metadata": {},
|
67 |
+
"outputs": [
|
68 |
+
{
|
69 |
+
"name": "stderr",
|
70 |
+
"output_type": "stream",
|
71 |
+
"text": [
|
72 |
+
"/opt/homebrew/lib/python3.9/site-packages/gradio/inputs.py:256: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
73 |
+
" warnings.warn(\n",
|
74 |
+
"/opt/homebrew/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
75 |
+
" warnings.warn(value)\n",
|
76 |
+
"/opt/homebrew/lib/python3.9/site-packages/gradio/outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
77 |
+
" warnings.warn(\n",
|
78 |
+
"/opt/homebrew/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
79 |
+
" warnings.warn(value)\n"
|
80 |
+
]
|
81 |
+
}
|
82 |
+
],
|
83 |
+
"source": [
|
84 |
+
"#|export\n",
|
85 |
+
"inp_img = gr.inputs.Image(shape=(200,200))\n",
|
86 |
+
"out_label = gr.outputs.Label()\n",
|
87 |
+
"\n",
|
88 |
+
"iface = gr.Interface(fn=classify_image,\n",
|
89 |
+
" inputs=inp_img,\n",
|
90 |
+
" outputs=out_label,\n",
|
91 |
+
" title=\"Pet classifier\")"
|
92 |
+
]
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"cell_type": "code",
|
96 |
+
"execution_count": 16,
|
97 |
+
"id": "32e6f831",
|
98 |
+
"metadata": {
|
99 |
+
"scrolled": true
|
100 |
+
},
|
101 |
+
"outputs": [
|
102 |
+
{
|
103 |
+
"name": "stdout",
|
104 |
+
"output_type": "stream",
|
105 |
+
"text": [
|
106 |
+
"Running on local URL: http://127.0.0.1:7861/\n",
|
107 |
+
"\n",
|
108 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
109 |
+
]
|
110 |
+
},
|
111 |
+
{
|
112 |
+
"data": {
|
113 |
+
"text/plain": [
|
114 |
+
"(<gradio.routes.App at 0x1688dc0d0>, 'http://127.0.0.1:7861/', None)"
|
115 |
+
]
|
116 |
+
},
|
117 |
+
"execution_count": 16,
|
118 |
+
"metadata": {},
|
119 |
+
"output_type": "execute_result"
|
120 |
+
}
|
121 |
+
],
|
122 |
+
"source": [
|
123 |
+
"#|export\n",
|
124 |
+
"iface.launch(inline=False)"
|
125 |
+
]
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"cell_type": "markdown",
|
129 |
+
"id": "01c53c53",
|
130 |
+
"metadata": {},
|
131 |
+
"source": [
|
132 |
+
"export"
|
133 |
+
]
|
134 |
+
},
|
135 |
+
{
|
136 |
+
"cell_type": "code",
|
137 |
+
"execution_count": 17,
|
138 |
+
"id": "40731685",
|
139 |
+
"metadata": {},
|
140 |
+
"outputs": [],
|
141 |
+
"source": [
|
142 |
+
"from nbdev.export import notebook2script"
|
143 |
+
]
|
144 |
+
},
|
145 |
+
{
|
146 |
+
"cell_type": "code",
|
147 |
+
"execution_count": 18,
|
148 |
+
"id": "ea42582a",
|
149 |
+
"metadata": {},
|
150 |
+
"outputs": [
|
151 |
+
{
|
152 |
+
"name": "stdout",
|
153 |
+
"output_type": "stream",
|
154 |
+
"text": [
|
155 |
+
"Converted app-nbdev.ipynb.\n"
|
156 |
+
]
|
157 |
+
}
|
158 |
+
],
|
159 |
+
"source": [
|
160 |
+
"x = 2\n",
|
161 |
+
"notebook2script('app-nbdev.ipynb')"
|
162 |
+
]
|
163 |
+
},
|
164 |
+
{
|
165 |
+
"cell_type": "code",
|
166 |
+
"execution_count": null,
|
167 |
+
"id": "78b0ea16",
|
168 |
+
"metadata": {},
|
169 |
+
"outputs": [],
|
170 |
+
"source": []
|
171 |
+
}
|
172 |
+
],
|
173 |
+
"metadata": {
|
174 |
+
"interpreter": {
|
175 |
+
"hash": "2bfab3daf39c717d5b0b70976ea3368fa383d7e036680b30bd721c6f21472435"
|
176 |
+
},
|
177 |
+
"kernelspec": {
|
178 |
+
"display_name": "Python 3 (ipykernel)",
|
179 |
+
"language": "python",
|
180 |
+
"name": "python3"
|
181 |
+
},
|
182 |
+
"language_info": {
|
183 |
+
"codemirror_mode": {
|
184 |
+
"name": "ipython",
|
185 |
+
"version": 3
|
186 |
+
},
|
187 |
+
"file_extension": ".py",
|
188 |
+
"mimetype": "text/x-python",
|
189 |
+
"name": "python",
|
190 |
+
"nbconvert_exporter": "python",
|
191 |
+
"pygments_lexer": "ipython3",
|
192 |
+
"version": "3.9.12"
|
193 |
+
}
|
194 |
+
},
|
195 |
+
"nbformat": 4,
|
196 |
+
"nbformat_minor": 5
|
197 |
+
}
|
app.py
CHANGED
@@ -1,17 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
def is_cat(x): return x[0].isupper()
|
6 |
|
|
|
7 |
learn = load_learner('model.pkl')
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
def classify_image(img):
|
12 |
pred,idx,probs = learn.predict(img)
|
13 |
return dict(zip(categories, map(float,probs)))
|
14 |
|
|
|
15 |
inp_img = gr.inputs.Image(shape=(200,200))
|
16 |
out_label = gr.outputs.Label()
|
17 |
|
@@ -20,4 +28,5 @@ iface = gr.Interface(fn=classify_image,
|
|
20 |
outputs=out_label,
|
21 |
title="Pet classifier")
|
22 |
|
23 |
-
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).
|
2 |
+
|
3 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'inp_img', 'out_label', 'iface']
|
4 |
+
|
5 |
+
# Cell
|
6 |
from fastai.vision.all import *
|
7 |
import gradio as gr
|
8 |
|
9 |
+
# Cell
|
10 |
+
def is_cat(x): return x[0].isupper()
|
11 |
|
12 |
+
# Cell
|
13 |
learn = load_learner('model.pkl')
|
14 |
|
15 |
+
# Cell
|
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 |
+
# Cell
|
23 |
inp_img = gr.inputs.Image(shape=(200,200))
|
24 |
out_label = gr.outputs.Label()
|
25 |
|
|
|
28 |
outputs=out_label,
|
29 |
title="Pet classifier")
|
30 |
|
31 |
+
# Cell
|
32 |
+
iface.launch(inline=False)
|