Spaces:
Sleeping
Sleeping
End-to-end MNIST handwritten digit recognition using a CNN, with a Flask web app featuring real-time canvas-based predictions.
f7da636 verified | import numpy as np | |
| from PIL import Image | |
| import io | |
| def process_image(image_data): | |
| img = Image.open(io.BytesIO(image_data)).convert("L") | |
| img = img.resize((28, 28)) | |
| img = np.array(img) / 255.0 | |
| img = (img > 0.2).astype("float32") | |
| img = img.reshape(1, 28, 28, 1) | |
| return img | |
| def get_prediction(img_array, model): | |
| preds = model.predict(img_array)[0] | |
| digit = int(preds.argmax()) | |
| confidence = float(preds[digit] * 100) | |
| return digit, confidence, preds.tolist() | |