Spaces:
Build error
Build error
| # import gradio as gr | |
| # import numpy as np | |
| # from modelutil import create_model | |
| # def predict_digit(image): | |
| # try: | |
| # if image == None: pass | |
| # except: | |
| # model = create_model() | |
| # predictions = model.predict(image.reshape(1, 28, 28)) | |
| # return np.argmax(predictions) | |
| # gr.Interface( | |
| # title="MNIST Digit Classifier by Papa Sega", | |
| # fn=predict_digit, | |
| # inputs=gr.Sketchpad( label="Draw a digit"), | |
| # outputs="number", | |
| # live=True | |
| # ).launch() | |
| import tensorflow as tf | |
| import gradio as gr | |
| import numpy as np | |
| # Load the CNN model from the .h5 file | |
| model = tf.keras.models.load_model('mnist_cnn_model.h5') | |
| def predict_digit(image): | |
| # Preprocess the input image | |
| image = np.expand_dims(image, axis=0) # Add batch dimension | |
| image = image / 255.0 # Normalize pixel values | |
| # Make predictions | |
| predictions = model.predict(image) | |
| # Get the predicted digit | |
| predicted_digit = np.argmax(predictions) | |
| return predicted_digit | |
| # Define Gradio interface | |
| gr.Interface( | |
| title="MNIST Digit Classifier by Papa Sega", | |
| fn=predict_digit, | |
| inputs=gr.Sketchpad(label="Draw a digit", height=800, width=600), | |
| outputs="number", | |
| live=True | |
| ).launch(debug=True) | |