Salman Naqvi commited on
Commit
f3a36de
·
1 Parent(s): 5e24d97

Add more elements to space's interface.

Browse files
README.md CHANGED
@@ -4,10 +4,12 @@ emoji: 🌊
4
  colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
 
7
  sdk_version: 3.3.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
11
  ---
12
 
13
  The workflow works!!!
 
4
  colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
7
+ python_version: 3.10.7
8
  sdk_version: 3.3.1
9
  app_file: app.py
10
  pinned: false
11
  license: apache-2.0
12
+ tags: [disaster relief, image classification]
13
  ---
14
 
15
  The workflow works!!!
app.ipynb CHANGED
@@ -112,6 +112,15 @@
112
  "collapsed": false
113
  }
114
  },
 
 
 
 
 
 
 
 
 
115
  {
116
  "cell_type": "code",
117
  "execution_count": 6,
@@ -119,7 +128,7 @@
119
  "source": [
120
  "#|export\n",
121
  "\n",
122
- "categories = ('Not Flooded', 'Flooded')\n",
123
  "\n",
124
  "def classify_image(image):\n",
125
  " prediction, index, probabilities = learner.predict(image)\n",
@@ -165,9 +174,18 @@
165
  "collapsed": false
166
  }
167
  },
 
 
 
 
 
 
 
 
 
168
  {
169
  "cell_type": "code",
170
- "execution_count": 8,
171
  "outputs": [],
172
  "source": [
173
  "#|export\n",
@@ -175,7 +193,19 @@
175
  "image = gr.Image()\n",
176
  "label = gr.Label()\n",
177
  "examples = [str(image_path) for image_path in Path('images/example_images')\n",
178
- ".rglob('*.jpeg')]"
 
 
 
 
 
 
 
 
 
 
 
 
179
  ],
180
  "metadata": {
181
  "collapsed": false
@@ -201,24 +231,33 @@
201
  "collapsed": false
202
  }
203
  },
 
 
 
 
 
 
 
 
 
204
  {
205
  "cell_type": "code",
206
- "execution_count": 10,
207
  "outputs": [
208
  {
209
  "name": "stdout",
210
  "output_type": "stream",
211
  "text": [
212
- "Running on local URL: http://127.0.0.1:7860\n",
213
  "\n",
214
  "To create a public link, set `share=True` in `launch()`.\n"
215
  ]
216
  },
217
  {
218
  "data": {
219
- "text/plain": "(<gradio.routes.App at 0x16e4f7e20>, 'http://127.0.0.1:7860/', None)"
220
  },
221
- "execution_count": 10,
222
  "metadata": {},
223
  "output_type": "execute_result"
224
  }
@@ -226,8 +265,11 @@
226
  "source": [
227
  "#|export\n",
228
  "\n",
229
- "interface = gr.Interface(fn=classify_image, inputs='image', outputs='label', examples=examples)\n",
230
- "interface.launch(inline=False)"
 
 
 
231
  ],
232
  "metadata": {
233
  "collapsed": false
@@ -244,7 +286,7 @@
244
  },
245
  {
246
  "cell_type": "code",
247
- "execution_count": 11,
248
  "outputs": [],
249
  "source": [
250
  "from nbdev.export import nb_export"
@@ -255,7 +297,7 @@
255
  },
256
  {
257
  "cell_type": "code",
258
- "execution_count": 12,
259
  "outputs": [],
260
  "source": [
261
  "nb_export('app.ipynb', '.')"
 
112
  "collapsed": false
113
  }
114
  },
115
+ {
116
+ "cell_type": "markdown",
117
+ "source": [
118
+ "## Create classification function."
119
+ ],
120
+ "metadata": {
121
+ "collapsed": false
122
+ }
123
+ },
124
  {
125
  "cell_type": "code",
126
  "execution_count": 6,
 
128
  "source": [
129
  "#|export\n",
130
  "\n",
131
+ "categories = 'Not Flooded', 'Flooded',\n",
132
  "\n",
133
  "def classify_image(image):\n",
134
  " prediction, index, probabilities = learner.predict(image)\n",
 
174
  "collapsed": false
175
  }
176
  },
177
+ {
178
+ "cell_type": "markdown",
179
+ "source": [
180
+ "## Intialize attributes for the interface."
181
+ ],
182
+ "metadata": {
183
+ "collapsed": false
184
+ }
185
+ },
186
  {
187
  "cell_type": "code",
188
+ "execution_count": 29,
189
  "outputs": [],
190
  "source": [
191
  "#|export\n",
 
193
  "image = gr.Image()\n",
194
  "label = gr.Label()\n",
195
  "examples = [str(image_path) for image_path in Path('images/example_images')\n",
196
+ ".rglob('*.jpeg')]\n",
197
+ "\n",
198
+ "title = 'Flood Classifier'\n",
199
+ "description = \"An image classifier that can tell whether an image is flooded \" \\\n",
200
+ " \"or not. Works well with images that have a top-down/aeiral \" \\\n",
201
+ " \"view of the land below.\" \\\n",
202
+ " \"This model was trained on the ResNet18 architecture and the \" \\\n",
203
+ " \"fastai library.\" \\\n",
204
+ " \"Check out the associated blog post with the link below!\"\n",
205
+ "article = \"<p style='text-align: center; font-size: 36px'><a \" \\\n",
206
+ " \"href='https://forbo7.github\" \\\n",
207
+ " \".io/ForBlog/fastai/image%20classification/2022/09/12/Detecting\" \\\n",
208
+ " \"-Floods-for-Disaster-Relief.html' targets='_blank'>Blog Post</a></p>'\""
209
  ],
210
  "metadata": {
211
  "collapsed": false
 
231
  "collapsed": false
232
  }
233
  },
234
+ {
235
+ "cell_type": "markdown",
236
+ "source": [
237
+ "## Create the interface."
238
+ ],
239
+ "metadata": {
240
+ "collapsed": false
241
+ }
242
+ },
243
  {
244
  "cell_type": "code",
245
+ "execution_count": 28,
246
  "outputs": [
247
  {
248
  "name": "stdout",
249
  "output_type": "stream",
250
  "text": [
251
+ "Running on local URL: http://127.0.0.1:7869\n",
252
  "\n",
253
  "To create a public link, set `share=True` in `launch()`.\n"
254
  ]
255
  },
256
  {
257
  "data": {
258
+ "text/plain": "(<gradio.routes.App at 0x29d4a8040>, 'http://127.0.0.1:7869/', None)"
259
  },
260
+ "execution_count": 28,
261
  "metadata": {},
262
  "output_type": "execute_result"
263
  }
 
265
  "source": [
266
  "#|export\n",
267
  "\n",
268
+ "# Perhaps I can make the interface below with **kwargs?\n",
269
+ "interface = gr.Interface(fn=classify_image, inputs='image', outputs='label',\n",
270
+ " examples=examples, title=title,\n",
271
+ " description=description, article=article)\n",
272
+ "interface.launch(inline=False, enable_queue=True)"
273
  ],
274
  "metadata": {
275
  "collapsed": false
 
286
  },
287
  {
288
  "cell_type": "code",
289
+ "execution_count": 30,
290
  "outputs": [],
291
  "source": [
292
  "from nbdev.export import nb_export"
 
297
  },
298
  {
299
  "cell_type": "code",
300
+ "execution_count": 31,
301
  "outputs": [],
302
  "source": [
303
  "nb_export('app.ipynb', '.')"
app.py CHANGED
@@ -1,7 +1,8 @@
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
- __all__ = ['learner', 'categories', 'image', 'label', 'examples', 'interface', 'classify_image']
 
5
 
6
  # %% app.ipynb 2
7
  import gradio as gr
@@ -10,19 +11,34 @@ from fastai.vision.all import *
10
  # %% app.ipynb 5
11
  learner = load_learner('model/flood_classifier.pkl')
12
 
13
- # %% app.ipynb 7
14
- categories = ('Not Flooded', 'Flooded')
15
 
16
  def classify_image(image):
17
  prediction, index, probabilities = learner.predict(image)
18
  return dict(zip(categories, map(float, probabilities)))
19
 
20
- # %% app.ipynb 9
21
  image = gr.Image()
22
  label = gr.Label()
23
  examples = [str(image_path) for image_path in Path('images/example_images')
24
  .rglob('*.jpeg')]
25
 
26
- # %% app.ipynb 11
27
- interface = gr.Interface(fn=classify_image, inputs='image', outputs='label', examples=examples)
28
- interface.launch(inline=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
+ __all__ = ['learner', 'categories', 'image', 'label', 'examples', 'title', 'description', 'article', 'interface',
5
+ 'classify_image']
6
 
7
  # %% app.ipynb 2
8
  import gradio as gr
 
11
  # %% app.ipynb 5
12
  learner = load_learner('model/flood_classifier.pkl')
13
 
14
+ # %% app.ipynb 8
15
+ categories = 'Not Flooded', 'Flooded',
16
 
17
  def classify_image(image):
18
  prediction, index, probabilities = learner.predict(image)
19
  return dict(zip(categories, map(float, probabilities)))
20
 
21
+ # %% app.ipynb 11
22
  image = gr.Image()
23
  label = gr.Label()
24
  examples = [str(image_path) for image_path in Path('images/example_images')
25
  .rglob('*.jpeg')]
26
 
27
+ title = 'Flood Classifier'
28
+ description = "An image classifier that can tell whether an image is flooded " \
29
+ "or not. Works well with images that have a top-down/aeiral " \
30
+ "view of the land below." \
31
+ "This model was trained on the ResNet18 architecture and the " \
32
+ "fastai library." \
33
+ "Check out the associated blog post with the link below!"
34
+ article = "<p style='text-align: center; font-size: 36px'><a " \
35
+ "href='https://forbo7.github" \
36
+ ".io/ForBlog/fastai/image%20classification/2022/09/12/Detecting" \
37
+ "-Floods-for-Disaster-Relief.html' targets='_blank'>Blog Post</a></p>'"
38
+
39
+ # %% app.ipynb 14
40
+ # Perhaps I can make the interface below with **kwargs?
41
+ interface = gr.Interface(fn=classify_image, inputs='image', outputs='label',
42
+ examples=examples, title=title,
43
+ description=description, article=article)
44
+ interface.launch(inline=False, enable_queue=True)
flagged/image/tmp6dcva8py.jpg ADDED
flagged/image/tmpvd6_25r3.jpg ADDED
flagged/log.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ image,output,flag,username,timestamp
2
+ /Users/salmannaqvi/DataspellProjects/FloodDetector/flagged/image/tmpvd6_25r3.jpg,/Users/salmannaqvi/DataspellProjects/FloodDetector/flagged/output/tmp12mf7l3w.json,,,2022-09-17 19:10:43.606594
3
+ ,,,,2022-09-17 19:19:07.108909
4
+ /Users/salmannaqvi/DataspellProjects/FloodDetector/flagged/image/tmp6dcva8py.jpg,,,,2022-09-17 19:19:09.166293
flagged/output/tmp12mf7l3w.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"label": "Flooded", "confidences": [{"label": "Flooded", "confidence": 0.531377911567688}, {"label": "Not Flooded", "confidence": 0.4686220586299896}]}
runtime.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-3.10.7