Instructions to use Mr00Magician/Number-Recogniser-api with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Mr00Magician/Number-Recogniser-api with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://Mr00Magician/Number-Recogniser-api") - Notebooks
- Google Colab
- Kaggle
File size: 601 Bytes
45df5ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from flask import Flask, request
import numpy as np
import tensorflow as tf
import cv2
app = Flask(__name__)
loaded_CNN = tf.keras.models.load_model('CNN_extended_dataset.h5')
@app.route('/get-prediction', methods = ['POST'])
def get_prediction():
img_array = request.json.get('data')
img_array = np.array(img_array, dtype=np.uint8).reshape(400, 400)
img_array = cv2.resize(img_array, (28, 28))
img_array = img_array.reshape(1, 28, 28)
pred = loaded_CNN.predict([img_array])
final_pred = np.argmax(pred)
return str(final_pred)
if __name__ == '__main__':
app.run() |