Spaces:
Sleeping
Sleeping
dmitryhits
commited on
Commit
·
38c5da5
1
Parent(s):
841823d
removes share
Browse files- .ipynb_checkpoints/weed_classifier-checkpoint.ipynb +310 -0
- app.py +1 -1
- flagged/log.csv +2 -0
- weed_classifier.ipynb +310 -0
- weed_classifier/__init__.py +1 -0
- weed_classifier/app.py +28 -0
.ipynb_checkpoints/weed_classifier-checkpoint.ipynb
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "31c36b68-0f95-4646-97ab-ac2da301f438",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"#| default_exp app"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"cell_type": "code",
|
| 15 |
+
"execution_count": null,
|
| 16 |
+
"id": "636de1ca-8681-4362-b6d1-f55bce2164f5",
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"outputs": [],
|
| 19 |
+
"source": [
|
| 20 |
+
"#| export\n",
|
| 21 |
+
"from fastai.vision.all import *\n",
|
| 22 |
+
"import gradio as gr\n",
|
| 23 |
+
"import skimage"
|
| 24 |
+
]
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"cell_type": "code",
|
| 28 |
+
"execution_count": null,
|
| 29 |
+
"id": "822ac457-393f-4b07-a333-430ff117a4fc",
|
| 30 |
+
"metadata": {},
|
| 31 |
+
"outputs": [],
|
| 32 |
+
"source": [
|
| 33 |
+
"#| export \n",
|
| 34 |
+
"learn = load_learner('export.pkl')"
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"cell_type": "code",
|
| 39 |
+
"execution_count": null,
|
| 40 |
+
"id": "d930004f",
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [],
|
| 43 |
+
"source": [
|
| 44 |
+
"#| export\n",
|
| 45 |
+
"labels = learn.dls.vocab\n",
|
| 46 |
+
"def predict(img):\n",
|
| 47 |
+
" img = PILImage.create(img)\n",
|
| 48 |
+
" pred,pred_idx,probs = learn.predict(img)\n",
|
| 49 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"cell_type": "code",
|
| 54 |
+
"execution_count": null,
|
| 55 |
+
"id": "e70d82aa",
|
| 56 |
+
"metadata": {},
|
| 57 |
+
"outputs": [
|
| 58 |
+
{
|
| 59 |
+
"name": "stderr",
|
| 60 |
+
"output_type": "stream",
|
| 61 |
+
"text": [
|
| 62 |
+
"/Users/hits/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",
|
| 63 |
+
" warnings.warn(\n",
|
| 64 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
| 65 |
+
" warnings.warn(value)\n",
|
| 66 |
+
"/Users/hits/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",
|
| 67 |
+
" warnings.warn(\n",
|
| 68 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
| 69 |
+
" warnings.warn(value)\n"
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"name": "stdout",
|
| 74 |
+
"output_type": "stream",
|
| 75 |
+
"text": [
|
| 76 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
| 77 |
+
"Running on public URL: https://e415e3b5031b999f83.gradio.live\n",
|
| 78 |
+
"\n",
|
| 79 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"data": {
|
| 84 |
+
"text/html": [
|
| 85 |
+
"<div><iframe src=\"https://e415e3b5031b999f83.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 86 |
+
],
|
| 87 |
+
"text/plain": [
|
| 88 |
+
"<IPython.core.display.HTML object>"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
"metadata": {},
|
| 92 |
+
"output_type": "display_data"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"data": {
|
| 96 |
+
"text/plain": []
|
| 97 |
+
},
|
| 98 |
+
"execution_count": null,
|
| 99 |
+
"metadata": {},
|
| 100 |
+
"output_type": "execute_result"
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"data": {
|
| 104 |
+
"text/html": [
|
| 105 |
+
"\n",
|
| 106 |
+
"<style>\n",
|
| 107 |
+
" /* Turns off some styling */\n",
|
| 108 |
+
" progress {\n",
|
| 109 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 110 |
+
" border: none;\n",
|
| 111 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 112 |
+
" background-size: auto;\n",
|
| 113 |
+
" }\n",
|
| 114 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 115 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 116 |
+
" }\n",
|
| 117 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 118 |
+
" background: #F44336;\n",
|
| 119 |
+
" }\n",
|
| 120 |
+
"</style>\n"
|
| 121 |
+
],
|
| 122 |
+
"text/plain": [
|
| 123 |
+
"<IPython.core.display.HTML object>"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
"metadata": {},
|
| 127 |
+
"output_type": "display_data"
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"data": {
|
| 131 |
+
"text/html": [],
|
| 132 |
+
"text/plain": [
|
| 133 |
+
"<IPython.core.display.HTML object>"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
"metadata": {},
|
| 137 |
+
"output_type": "display_data"
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"data": {
|
| 141 |
+
"text/html": [
|
| 142 |
+
"\n",
|
| 143 |
+
"<style>\n",
|
| 144 |
+
" /* Turns off some styling */\n",
|
| 145 |
+
" progress {\n",
|
| 146 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 147 |
+
" border: none;\n",
|
| 148 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 149 |
+
" background-size: auto;\n",
|
| 150 |
+
" }\n",
|
| 151 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 152 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 153 |
+
" }\n",
|
| 154 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 155 |
+
" background: #F44336;\n",
|
| 156 |
+
" }\n",
|
| 157 |
+
"</style>\n"
|
| 158 |
+
],
|
| 159 |
+
"text/plain": [
|
| 160 |
+
"<IPython.core.display.HTML object>"
|
| 161 |
+
]
|
| 162 |
+
},
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"output_type": "display_data"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"data": {
|
| 168 |
+
"text/html": [],
|
| 169 |
+
"text/plain": [
|
| 170 |
+
"<IPython.core.display.HTML object>"
|
| 171 |
+
]
|
| 172 |
+
},
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"output_type": "display_data"
|
| 175 |
+
}
|
| 176 |
+
],
|
| 177 |
+
"source": [
|
| 178 |
+
"gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)"
|
| 179 |
+
]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"cell_type": "code",
|
| 183 |
+
"execution_count": null,
|
| 184 |
+
"id": "d613b05a-d29e-438b-80d8-0ed503341ad2",
|
| 185 |
+
"metadata": {},
|
| 186 |
+
"outputs": [
|
| 187 |
+
{
|
| 188 |
+
"name": "stderr",
|
| 189 |
+
"output_type": "stream",
|
| 190 |
+
"text": [
|
| 191 |
+
"/Users/hits/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",
|
| 192 |
+
" warnings.warn(\n",
|
| 193 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
| 194 |
+
" warnings.warn(value)\n",
|
| 195 |
+
"/Users/hits/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",
|
| 196 |
+
" warnings.warn(\n",
|
| 197 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
| 198 |
+
" warnings.warn(value)\n"
|
| 199 |
+
]
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"name": "stdout",
|
| 203 |
+
"output_type": "stream",
|
| 204 |
+
"text": [
|
| 205 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 206 |
+
"Running on public URL: https://d712faf71e19ec6ec0.gradio.live\n",
|
| 207 |
+
"\n",
|
| 208 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
|
| 209 |
+
]
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"data": {
|
| 213 |
+
"text/html": [
|
| 214 |
+
"<div><iframe src=\"https://d712faf71e19ec6ec0.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 215 |
+
],
|
| 216 |
+
"text/plain": [
|
| 217 |
+
"<IPython.core.display.HTML object>"
|
| 218 |
+
]
|
| 219 |
+
},
|
| 220 |
+
"metadata": {},
|
| 221 |
+
"output_type": "display_data"
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"data": {
|
| 225 |
+
"text/plain": []
|
| 226 |
+
},
|
| 227 |
+
"execution_count": null,
|
| 228 |
+
"metadata": {},
|
| 229 |
+
"output_type": "execute_result"
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"data": {
|
| 233 |
+
"text/html": [
|
| 234 |
+
"\n",
|
| 235 |
+
"<style>\n",
|
| 236 |
+
" /* Turns off some styling */\n",
|
| 237 |
+
" progress {\n",
|
| 238 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 239 |
+
" border: none;\n",
|
| 240 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 241 |
+
" background-size: auto;\n",
|
| 242 |
+
" }\n",
|
| 243 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 244 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 245 |
+
" }\n",
|
| 246 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 247 |
+
" background: #F44336;\n",
|
| 248 |
+
" }\n",
|
| 249 |
+
"</style>\n"
|
| 250 |
+
],
|
| 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 |
+
"text/plain": [
|
| 262 |
+
"<IPython.core.display.HTML object>"
|
| 263 |
+
]
|
| 264 |
+
},
|
| 265 |
+
"metadata": {},
|
| 266 |
+
"output_type": "display_data"
|
| 267 |
+
}
|
| 268 |
+
],
|
| 269 |
+
"source": [
|
| 270 |
+
"#| export\n",
|
| 271 |
+
"title = \"Weed Classifier\"\n",
|
| 272 |
+
"description = \"A weed classifier trained on the Kaggle V2 Plant Seedling dataset with fastai. Dataset has mostly african weeds in it at the moment.\"\n",
|
| 273 |
+
"article=\"<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>\"\n",
|
| 274 |
+
"examples = ['SugarBeet.png']\n",
|
| 275 |
+
"interpretation='default'\n",
|
| 276 |
+
"enable_queue=True\n",
|
| 277 |
+
"gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)"
|
| 278 |
+
]
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"cell_type": "code",
|
| 282 |
+
"execution_count": null,
|
| 283 |
+
"id": "380fbba3-1ef1-4ff2-8ea4-d23fe1dca731",
|
| 284 |
+
"metadata": {},
|
| 285 |
+
"outputs": [],
|
| 286 |
+
"source": [
|
| 287 |
+
"#| hide\n",
|
| 288 |
+
"from nbdev.export import nb_export\n",
|
| 289 |
+
"nb_export('weed_classifier.ipynb')"
|
| 290 |
+
]
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"cell_type": "code",
|
| 294 |
+
"execution_count": null,
|
| 295 |
+
"id": "e9077dd2-dee2-42b8-b2d1-59e5871315ed",
|
| 296 |
+
"metadata": {},
|
| 297 |
+
"outputs": [],
|
| 298 |
+
"source": []
|
| 299 |
+
}
|
| 300 |
+
],
|
| 301 |
+
"metadata": {
|
| 302 |
+
"kernelspec": {
|
| 303 |
+
"display_name": "python3",
|
| 304 |
+
"language": "python",
|
| 305 |
+
"name": "python3"
|
| 306 |
+
}
|
| 307 |
+
},
|
| 308 |
+
"nbformat": 4,
|
| 309 |
+
"nbformat_minor": 5
|
| 310 |
+
}
|
app.py
CHANGED
|
@@ -25,4 +25,4 @@ article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog
|
|
| 25 |
examples = ['SugarBeet.png']
|
| 26 |
interpretation='default'
|
| 27 |
enable_queue=True
|
| 28 |
-
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(
|
|
|
|
| 25 |
examples = ['SugarBeet.png']
|
| 26 |
interpretation='default'
|
| 27 |
enable_queue=True
|
| 28 |
+
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
img,output,flag,username,timestamp
|
| 2 |
+
,,,,2023-05-08 16:59:25.662113
|
weed_classifier.ipynb
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "31c36b68-0f95-4646-97ab-ac2da301f438",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"#| default_exp app"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"cell_type": "code",
|
| 15 |
+
"execution_count": null,
|
| 16 |
+
"id": "636de1ca-8681-4362-b6d1-f55bce2164f5",
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"outputs": [],
|
| 19 |
+
"source": [
|
| 20 |
+
"#| export\n",
|
| 21 |
+
"from fastai.vision.all import *\n",
|
| 22 |
+
"import gradio as gr\n",
|
| 23 |
+
"import skimage"
|
| 24 |
+
]
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"cell_type": "code",
|
| 28 |
+
"execution_count": null,
|
| 29 |
+
"id": "822ac457-393f-4b07-a333-430ff117a4fc",
|
| 30 |
+
"metadata": {},
|
| 31 |
+
"outputs": [],
|
| 32 |
+
"source": [
|
| 33 |
+
"#| export \n",
|
| 34 |
+
"learn = load_learner('export.pkl')"
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"cell_type": "code",
|
| 39 |
+
"execution_count": null,
|
| 40 |
+
"id": "d930004f",
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [],
|
| 43 |
+
"source": [
|
| 44 |
+
"#| export\n",
|
| 45 |
+
"labels = learn.dls.vocab\n",
|
| 46 |
+
"def predict(img):\n",
|
| 47 |
+
" img = PILImage.create(img)\n",
|
| 48 |
+
" pred,pred_idx,probs = learn.predict(img)\n",
|
| 49 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"cell_type": "code",
|
| 54 |
+
"execution_count": null,
|
| 55 |
+
"id": "e70d82aa",
|
| 56 |
+
"metadata": {},
|
| 57 |
+
"outputs": [
|
| 58 |
+
{
|
| 59 |
+
"name": "stderr",
|
| 60 |
+
"output_type": "stream",
|
| 61 |
+
"text": [
|
| 62 |
+
"/Users/hits/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",
|
| 63 |
+
" warnings.warn(\n",
|
| 64 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
| 65 |
+
" warnings.warn(value)\n",
|
| 66 |
+
"/Users/hits/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",
|
| 67 |
+
" warnings.warn(\n",
|
| 68 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
| 69 |
+
" warnings.warn(value)\n"
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"name": "stdout",
|
| 74 |
+
"output_type": "stream",
|
| 75 |
+
"text": [
|
| 76 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
| 77 |
+
"Running on public URL: https://e415e3b5031b999f83.gradio.live\n",
|
| 78 |
+
"\n",
|
| 79 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"data": {
|
| 84 |
+
"text/html": [
|
| 85 |
+
"<div><iframe src=\"https://e415e3b5031b999f83.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 86 |
+
],
|
| 87 |
+
"text/plain": [
|
| 88 |
+
"<IPython.core.display.HTML object>"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
"metadata": {},
|
| 92 |
+
"output_type": "display_data"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"data": {
|
| 96 |
+
"text/plain": []
|
| 97 |
+
},
|
| 98 |
+
"execution_count": null,
|
| 99 |
+
"metadata": {},
|
| 100 |
+
"output_type": "execute_result"
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"data": {
|
| 104 |
+
"text/html": [
|
| 105 |
+
"\n",
|
| 106 |
+
"<style>\n",
|
| 107 |
+
" /* Turns off some styling */\n",
|
| 108 |
+
" progress {\n",
|
| 109 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 110 |
+
" border: none;\n",
|
| 111 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 112 |
+
" background-size: auto;\n",
|
| 113 |
+
" }\n",
|
| 114 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 115 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 116 |
+
" }\n",
|
| 117 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 118 |
+
" background: #F44336;\n",
|
| 119 |
+
" }\n",
|
| 120 |
+
"</style>\n"
|
| 121 |
+
],
|
| 122 |
+
"text/plain": [
|
| 123 |
+
"<IPython.core.display.HTML object>"
|
| 124 |
+
]
|
| 125 |
+
},
|
| 126 |
+
"metadata": {},
|
| 127 |
+
"output_type": "display_data"
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"data": {
|
| 131 |
+
"text/html": [],
|
| 132 |
+
"text/plain": [
|
| 133 |
+
"<IPython.core.display.HTML object>"
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
"metadata": {},
|
| 137 |
+
"output_type": "display_data"
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"data": {
|
| 141 |
+
"text/html": [
|
| 142 |
+
"\n",
|
| 143 |
+
"<style>\n",
|
| 144 |
+
" /* Turns off some styling */\n",
|
| 145 |
+
" progress {\n",
|
| 146 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 147 |
+
" border: none;\n",
|
| 148 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 149 |
+
" background-size: auto;\n",
|
| 150 |
+
" }\n",
|
| 151 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 152 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 153 |
+
" }\n",
|
| 154 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 155 |
+
" background: #F44336;\n",
|
| 156 |
+
" }\n",
|
| 157 |
+
"</style>\n"
|
| 158 |
+
],
|
| 159 |
+
"text/plain": [
|
| 160 |
+
"<IPython.core.display.HTML object>"
|
| 161 |
+
]
|
| 162 |
+
},
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"output_type": "display_data"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"data": {
|
| 168 |
+
"text/html": [],
|
| 169 |
+
"text/plain": [
|
| 170 |
+
"<IPython.core.display.HTML object>"
|
| 171 |
+
]
|
| 172 |
+
},
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"output_type": "display_data"
|
| 175 |
+
}
|
| 176 |
+
],
|
| 177 |
+
"source": [
|
| 178 |
+
"gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)"
|
| 179 |
+
]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"cell_type": "code",
|
| 183 |
+
"execution_count": null,
|
| 184 |
+
"id": "d613b05a-d29e-438b-80d8-0ed503341ad2",
|
| 185 |
+
"metadata": {},
|
| 186 |
+
"outputs": [
|
| 187 |
+
{
|
| 188 |
+
"name": "stderr",
|
| 189 |
+
"output_type": "stream",
|
| 190 |
+
"text": [
|
| 191 |
+
"/Users/hits/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",
|
| 192 |
+
" warnings.warn(\n",
|
| 193 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
| 194 |
+
" warnings.warn(value)\n",
|
| 195 |
+
"/Users/hits/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",
|
| 196 |
+
" warnings.warn(\n",
|
| 197 |
+
"/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
| 198 |
+
" warnings.warn(value)\n"
|
| 199 |
+
]
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"name": "stdout",
|
| 203 |
+
"output_type": "stream",
|
| 204 |
+
"text": [
|
| 205 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 206 |
+
"Running on public URL: https://d712faf71e19ec6ec0.gradio.live\n",
|
| 207 |
+
"\n",
|
| 208 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
|
| 209 |
+
]
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"data": {
|
| 213 |
+
"text/html": [
|
| 214 |
+
"<div><iframe src=\"https://d712faf71e19ec6ec0.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 215 |
+
],
|
| 216 |
+
"text/plain": [
|
| 217 |
+
"<IPython.core.display.HTML object>"
|
| 218 |
+
]
|
| 219 |
+
},
|
| 220 |
+
"metadata": {},
|
| 221 |
+
"output_type": "display_data"
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"data": {
|
| 225 |
+
"text/plain": []
|
| 226 |
+
},
|
| 227 |
+
"execution_count": null,
|
| 228 |
+
"metadata": {},
|
| 229 |
+
"output_type": "execute_result"
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"data": {
|
| 233 |
+
"text/html": [
|
| 234 |
+
"\n",
|
| 235 |
+
"<style>\n",
|
| 236 |
+
" /* Turns off some styling */\n",
|
| 237 |
+
" progress {\n",
|
| 238 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
| 239 |
+
" border: none;\n",
|
| 240 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
| 241 |
+
" background-size: auto;\n",
|
| 242 |
+
" }\n",
|
| 243 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
| 244 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
| 245 |
+
" }\n",
|
| 246 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
| 247 |
+
" background: #F44336;\n",
|
| 248 |
+
" }\n",
|
| 249 |
+
"</style>\n"
|
| 250 |
+
],
|
| 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 |
+
"text/plain": [
|
| 262 |
+
"<IPython.core.display.HTML object>"
|
| 263 |
+
]
|
| 264 |
+
},
|
| 265 |
+
"metadata": {},
|
| 266 |
+
"output_type": "display_data"
|
| 267 |
+
}
|
| 268 |
+
],
|
| 269 |
+
"source": [
|
| 270 |
+
"#| export\n",
|
| 271 |
+
"title = \"Weed Classifier\"\n",
|
| 272 |
+
"description = \"A weed classifier trained on the Kaggle V2 Plant Seedling dataset with fastai. Dataset has mostly african weeds in it at the moment.\"\n",
|
| 273 |
+
"article=\"<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>\"\n",
|
| 274 |
+
"examples = ['SugarBeet.png']\n",
|
| 275 |
+
"interpretation='default'\n",
|
| 276 |
+
"enable_queue=True\n",
|
| 277 |
+
"gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)"
|
| 278 |
+
]
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"cell_type": "code",
|
| 282 |
+
"execution_count": null,
|
| 283 |
+
"id": "380fbba3-1ef1-4ff2-8ea4-d23fe1dca731",
|
| 284 |
+
"metadata": {},
|
| 285 |
+
"outputs": [],
|
| 286 |
+
"source": [
|
| 287 |
+
"#| hide\n",
|
| 288 |
+
"from nbdev.export import nb_export\n",
|
| 289 |
+
"nb_export('weed_classifier.ipynb')"
|
| 290 |
+
]
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"cell_type": "code",
|
| 294 |
+
"execution_count": null,
|
| 295 |
+
"id": "e9077dd2-dee2-42b8-b2d1-59e5871315ed",
|
| 296 |
+
"metadata": {},
|
| 297 |
+
"outputs": [],
|
| 298 |
+
"source": []
|
| 299 |
+
}
|
| 300 |
+
],
|
| 301 |
+
"metadata": {
|
| 302 |
+
"kernelspec": {
|
| 303 |
+
"display_name": "python3",
|
| 304 |
+
"language": "python",
|
| 305 |
+
"name": "python3"
|
| 306 |
+
}
|
| 307 |
+
},
|
| 308 |
+
"nbformat": 4,
|
| 309 |
+
"nbformat_minor": 5
|
| 310 |
+
}
|
weed_classifier/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__version__ = "0.0.1"
|
weed_classifier/app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../weed_classifier.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['learn', 'labels', 'title', 'description', 'article', 'examples', 'interpretation', 'enable_queue', 'predict']
|
| 5 |
+
|
| 6 |
+
# %% ../weed_classifier.ipynb 1
|
| 7 |
+
from fastai.vision.all import *
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import skimage
|
| 10 |
+
|
| 11 |
+
# %% ../weed_classifier.ipynb 2
|
| 12 |
+
learn = load_learner('export.pkl')
|
| 13 |
+
|
| 14 |
+
# %% ../weed_classifier.ipynb 3
|
| 15 |
+
labels = learn.dls.vocab
|
| 16 |
+
def predict(img):
|
| 17 |
+
img = PILImage.create(img)
|
| 18 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 19 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 20 |
+
|
| 21 |
+
# %% ../weed_classifier.ipynb 5
|
| 22 |
+
title = "Weed Classifier"
|
| 23 |
+
description = "A weed classifier trained on the Kaggle V2 Plant Seedling dataset with fastai. Dataset has mostly african weeds in it at the moment."
|
| 24 |
+
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
| 25 |
+
examples = ['SugarBeet.png']
|
| 26 |
+
interpretation='default'
|
| 27 |
+
enable_queue=True
|
| 28 |
+
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)
|