numberplumber commited on
Commit
10ec889
1 Parent(s): 6c5bb76

Create app.ipynb

Browse files
Files changed (1) hide show
  1. app.ipynb +173 -0
app.ipynb ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 5,
6
+ "id": "6848c5a6-85e6-41f5-9004-a690a77b5509",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from fastai.vision.all import *\n",
11
+ "from fastai.vision.widgets import *\n",
12
+ "import gradio as gr"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 6,
18
+ "id": "f2fd99bd-54cd-42aa-bdbf-74cd795342f1",
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "learn = load_learner('invsv_export.pkl')"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 7,
28
+ "id": "a879266a-83d2-489d-aec1-2b558d8b5cb1",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "labels = learn.dls.vocab\n",
33
+ "def predict(img):\n",
34
+ " img = PILImage.create(img)\n",
35
+ " pred,pred_idx,probs = learn.predict(img)\n",
36
+ " return {labels[i]: float(probs[i]) for i in range(len(labels))}"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": null,
42
+ "id": "dddb3a7e-2d8e-4392-a290-baf9fc5fb8e5",
43
+ "metadata": {},
44
+ "outputs": [
45
+ {
46
+ "data": {
47
+ "text/plain": [
48
+ "\u001b[0;31mType:\u001b[0m list\n",
49
+ "\u001b[0;31mString form:\u001b[0m ['examples/Alliaria petiolata.jpg', 'examples/anthriscus sylvestris.jpg', 'examples/Chondrilla juncea.jpg', 'examples/Conium maculatum.jpg', 'examples/Heracleum mantegazzianum.jpg', 'examples/Pastinaca sativa.jpg']\n",
50
+ "\u001b[0;31mLength:\u001b[0m 6\n",
51
+ "\u001b[0;31mDocstring:\u001b[0m \n",
52
+ "Built-in mutable sequence.\n",
53
+ "\n",
54
+ "If no argument is given, the constructor creates a new empty list.\n",
55
+ "The argument must be an iterable if specified.\n"
56
+ ]
57
+ },
58
+ "metadata": {},
59
+ "output_type": "display_data"
60
+ }
61
+ ],
62
+ "source": [
63
+ "??examples"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 21,
69
+ "id": "6e62c71e-30c5-4451-a9ab-447bec05bb91",
70
+ "metadata": {},
71
+ "outputs": [
72
+ {
73
+ "name": "stderr",
74
+ "output_type": "stream",
75
+ "text": [
76
+ "/usr/local/lib/python3.9/dist-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",
77
+ " warnings.warn(\n",
78
+ "/usr/local/lib/python3.9/dist-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
79
+ " warnings.warn(value)\n",
80
+ "/usr/local/lib/python3.9/dist-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",
81
+ " warnings.warn(\n",
82
+ "/usr/local/lib/python3.9/dist-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
83
+ " warnings.warn(value)\n",
84
+ "/usr/local/lib/python3.9/dist-packages/gradio/deprecation.py:40: UserWarning: `enable_queue` is deprecated in `Interface()`, please use it within `launch()` instead.\n",
85
+ " warnings.warn(value)\n"
86
+ ]
87
+ }
88
+ ],
89
+ "source": [
90
+ "title = \"BC Gov - Invasive Plant Classifier (Class: Provincial Containment)\"\n",
91
+ "description = \"An invasive plant classifier, able to identify invasive plants deemed for 'Provincial Containment' (n=6) by the Government of British Columbia. Model trained on BingSearch Images scraped dataset with fastai. <br />Example Images: <br />(1) *Alliaria petiolata* - Garlic Mustard<br />(2) *Anthriscus sylvestris* - Cow Parsley <br />(3) *Chondrilla juncea* - Rush Skeletonweed <br />(4) *Conium maculatum* - Poison Hemlock <br />(5) *Heracleum mantegazzianum* - Giant Hogweed <br />(6) *Pastinaca sativa* - Wild Parsnip\"\n",
92
+ "examples = ['examples/Alliaria petiolata.jpg', 'examples/anthriscus sylvestris.jpg', 'examples/Chondrilla juncea.jpg', 'examples/Conium maculatum.jpg', 'examples/Heracleum mantegazzianum.jpg', 'examples/Pastinaca sativa.jpg']\n",
93
+ "enable_queue=True\n",
94
+ "\n",
95
+ "iface = gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=6),title=title,description=description,examples=examples,enable_queue=enable_queue)"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": 22,
101
+ "id": "f8017243-6aeb-4dd8-821d-5c50eaad322d",
102
+ "metadata": {},
103
+ "outputs": [
104
+ {
105
+ "name": "stdout",
106
+ "output_type": "stream",
107
+ "text": [
108
+ "Running on local URL: http://127.0.0.1:7864/\n",
109
+ "Running on public URL: https://38910.gradio.app\n",
110
+ "\n",
111
+ "This share link expires in 72 hours. For free permanent hosting, check out Spaces: https://huggingface.co/spaces\n"
112
+ ]
113
+ },
114
+ {
115
+ "data": {
116
+ "text/html": [
117
+ "<div><iframe src=\"https://38910.gradio.app\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
118
+ ],
119
+ "text/plain": [
120
+ "<IPython.core.display.HTML object>"
121
+ ]
122
+ },
123
+ "metadata": {},
124
+ "output_type": "display_data"
125
+ },
126
+ {
127
+ "data": {
128
+ "text/plain": [
129
+ "(<gradio.routes.App at 0x7fa413ba12b0>,\n",
130
+ " 'http://127.0.0.1:7864/',\n",
131
+ " 'https://38910.gradio.app')"
132
+ ]
133
+ },
134
+ "execution_count": 22,
135
+ "metadata": {},
136
+ "output_type": "execute_result"
137
+ }
138
+ ],
139
+ "source": [
140
+ "iface.launch(share=True)"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": null,
146
+ "id": "388b7e1d-237b-4570-861f-17b4f88828d2",
147
+ "metadata": {},
148
+ "outputs": [],
149
+ "source": []
150
+ }
151
+ ],
152
+ "metadata": {
153
+ "kernelspec": {
154
+ "display_name": "Python 3 (ipykernel)",
155
+ "language": "python",
156
+ "name": "python3"
157
+ },
158
+ "language_info": {
159
+ "codemirror_mode": {
160
+ "name": "ipython",
161
+ "version": 3
162
+ },
163
+ "file_extension": ".py",
164
+ "mimetype": "text/x-python",
165
+ "name": "python",
166
+ "nbconvert_exporter": "python",
167
+ "pygments_lexer": "ipython3",
168
+ "version": "3.9.13"
169
+ }
170
+ },
171
+ "nbformat": 4,
172
+ "nbformat_minor": 5
173
+ }