hightowerr commited on
Commit
c23acfb
·
1 Parent(s): 2f10a4b

updated array issue

Browse files
Files changed (2) hide show
  1. app.ipynb +11 -46
  2. app.py +7 -5
app.ipynb CHANGED
@@ -189,9 +189,10 @@
189
  "except ImportError:\n",
190
  " can_display = False\n",
191
  "\n",
192
- "# #|export\n",
193
- "def on_click_classify(img):\n",
194
- " # img = PILImage.create(btn_upload.data[-1])\n",
 
195
  " out_pl = widgets.Output()\n",
196
  " out_pl.clear_output()\n",
197
  " if can_display:\n",
@@ -201,9 +202,10 @@
201
  " else:\n",
202
  " # Save to a file if display is not available\n",
203
  " img.to_thumb(128, 128).save('output_thumbnail.png')\n",
204
- " # print(\"Thumbnail saved to 'output_thumbnail.png'.\")\n",
 
 
205
  " pred, pred_idx, probs = learn_inf.predict(img)\n",
206
- " # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
207
  " return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'"
208
  ]
209
  },
@@ -237,7 +239,7 @@
237
  },
238
  {
239
  "cell_type": "code",
240
- "execution_count": 46,
241
  "id": "a6e2a398-f6c8-4444-b0f2-e538a1b36da2",
242
  "metadata": {},
243
  "outputs": [
@@ -245,7 +247,7 @@
245
  "name": "stdout",
246
  "output_type": "stream",
247
  "text": [
248
- "Running on local URL: http://127.0.0.1:7865\n",
249
  "\n",
250
  "To create a public link, set `share=True` in `launch()`.\n"
251
  ]
@@ -254,46 +256,9 @@
254
  "data": {
255
  "text/plain": []
256
  },
257
- "execution_count": 46,
258
  "metadata": {},
259
  "output_type": "execute_result"
260
- },
261
- {
262
- "data": {
263
- "text/html": [
264
- "\n",
265
- "<style>\n",
266
- " /* Turns off some styling */\n",
267
- " progress {\n",
268
- " /* gets rid of default border in Firefox and Opera. */\n",
269
- " border: none;\n",
270
- " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
271
- " background-size: auto;\n",
272
- " }\n",
273
- " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
274
- " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
275
- " }\n",
276
- " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
277
- " background: #F44336;\n",
278
- " }\n",
279
- "</style>\n"
280
- ],
281
- "text/plain": [
282
- "<IPython.core.display.HTML object>"
283
- ]
284
- },
285
- "metadata": {},
286
- "output_type": "display_data"
287
- },
288
- {
289
- "data": {
290
- "text/html": [],
291
- "text/plain": [
292
- "<IPython.core.display.HTML object>"
293
- ]
294
- },
295
- "metadata": {},
296
- "output_type": "display_data"
297
  }
298
  ],
299
  "source": [
@@ -316,7 +281,7 @@
316
  },
317
  {
318
  "cell_type": "code",
319
- "execution_count": 31,
320
  "id": "f5c57105-41fe-4d79-a2b0-d52ed75ea6cb",
321
  "metadata": {},
322
  "outputs": [
 
189
  "except ImportError:\n",
190
  " can_display = False\n",
191
  "\n",
192
+ "def on_click_classify(img_array):\n",
193
+ " # Convert numpy array to PIL Image\n",
194
+ " img = Image.fromarray(img_array.astype('uint8'), 'RGB')\n",
195
+ " \n",
196
  " out_pl = widgets.Output()\n",
197
  " out_pl.clear_output()\n",
198
  " if can_display:\n",
 
202
  " else:\n",
203
  " # Save to a file if display is not available\n",
204
  " img.to_thumb(128, 128).save('output_thumbnail.png')\n",
205
+ " print(\"Thumbnail saved to 'output_thumbnail.png'.\")\n",
206
+ " \n",
207
+ " # Assuming learn_inf is already defined and loaded elsewhere in your code\n",
208
  " pred, pred_idx, probs = learn_inf.predict(img)\n",
 
209
  " return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'"
210
  ]
211
  },
 
239
  },
240
  {
241
  "cell_type": "code",
242
+ "execution_count": 48,
243
  "id": "a6e2a398-f6c8-4444-b0f2-e538a1b36da2",
244
  "metadata": {},
245
  "outputs": [
 
247
  "name": "stdout",
248
  "output_type": "stream",
249
  "text": [
250
+ "Running on local URL: http://127.0.0.1:7866\n",
251
  "\n",
252
  "To create a public link, set `share=True` in `launch()`.\n"
253
  ]
 
256
  "data": {
257
  "text/plain": []
258
  },
259
+ "execution_count": 48,
260
  "metadata": {},
261
  "output_type": "execute_result"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  }
263
  ],
264
  "source": [
 
281
  },
282
  {
283
  "cell_type": "code",
284
+ "execution_count": 49,
285
  "id": "f5c57105-41fe-4d79-a2b0-d52ed75ea6cb",
286
  "metadata": {},
287
  "outputs": [
app.py CHANGED
@@ -23,9 +23,10 @@ try:
23
  except ImportError:
24
  can_display = False
25
 
26
- # #|export
27
- def on_click_classify(img):
28
- # img = PILImage.create(btn_upload.data[-1])
 
29
  out_pl = widgets.Output()
30
  out_pl.clear_output()
31
  if can_display:
@@ -35,9 +36,10 @@ def on_click_classify(img):
35
  else:
36
  # Save to a file if display is not available
37
  img.to_thumb(128, 128).save('output_thumbnail.png')
38
- # print("Thumbnail saved to 'output_thumbnail.png'.")
 
 
39
  pred, pred_idx, probs = learn_inf.predict(img)
40
- # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
41
  return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
42
 
43
  # %% app.ipynb 17
 
23
  except ImportError:
24
  can_display = False
25
 
26
+ def on_click_classify(img_array):
27
+ # Convert numpy array to PIL Image
28
+ img = Image.fromarray(img_array.astype('uint8'), 'RGB')
29
+
30
  out_pl = widgets.Output()
31
  out_pl.clear_output()
32
  if can_display:
 
36
  else:
37
  # Save to a file if display is not available
38
  img.to_thumb(128, 128).save('output_thumbnail.png')
39
+ print("Thumbnail saved to 'output_thumbnail.png'.")
40
+
41
+ # Assuming learn_inf is already defined and loaded elsewhere in your code
42
  pred, pred_idx, probs = learn_inf.predict(img)
 
43
  return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
44
 
45
  # %% app.ipynb 17