Spaces:
Runtime error
Runtime error
Kyle Dampier
commited on
Commit
•
f213495
1
Parent(s):
4789c9d
added comments and expander of the resized image
Browse files
app.py
CHANGED
@@ -36,17 +36,21 @@ canvas_result = st_canvas(
|
|
36 |
|
37 |
if canvas_result.image_data is not None:
|
38 |
|
|
|
39 |
im = ImageOps.grayscale(Image.fromarray(canvas_result.image_data.astype(
|
40 |
'uint8'), mode="RGBA")).resize((28, 28))
|
41 |
|
|
|
42 |
data = img_to_array(im)
|
43 |
data = data / 255
|
44 |
data = data.reshape(1, 28, 28, 1)
|
45 |
data = data.astype('float32')
|
46 |
|
|
|
47 |
st.write('### Predicted Digit')
|
48 |
prediction = model.predict(data)
|
49 |
|
|
|
50 |
result = plt.figure(figsize=(12, 3))
|
51 |
plt.bar(range(10), prediction[0])
|
52 |
plt.xticks(range(10))
|
@@ -56,6 +60,8 @@ if canvas_result.image_data is not None:
|
|
56 |
plt.ylim(0, 1)
|
57 |
st.write(result)
|
58 |
|
59 |
-
|
60 |
-
st.
|
61 |
-
|
|
|
|
|
|
36 |
|
37 |
if canvas_result.image_data is not None:
|
38 |
|
39 |
+
# Get image data from canvas
|
40 |
im = ImageOps.grayscale(Image.fromarray(canvas_result.image_data.astype(
|
41 |
'uint8'), mode="RGBA")).resize((28, 28))
|
42 |
|
43 |
+
# Convert image to array and reshape
|
44 |
data = img_to_array(im)
|
45 |
data = data / 255
|
46 |
data = data.reshape(1, 28, 28, 1)
|
47 |
data = data.astype('float32')
|
48 |
|
49 |
+
# Predict digit
|
50 |
st.write('### Predicted Digit')
|
51 |
prediction = model.predict(data)
|
52 |
|
53 |
+
# Plot prediction
|
54 |
result = plt.figure(figsize=(12, 3))
|
55 |
plt.bar(range(10), prediction[0])
|
56 |
plt.xticks(range(10))
|
|
|
60 |
plt.ylim(0, 1)
|
61 |
st.write(result)
|
62 |
|
63 |
+
# Show resized image
|
64 |
+
with st.expander('Show Resized Image'):
|
65 |
+
st.write("The image needs to be resized, because it can only input 28x28 images")
|
66 |
+
st.image(im, caption='Resized Image', width=28*9)
|
67 |
+
|