Spaces:
Sleeping
Sleeping
import tensorflow as tf | |
import gradio as gr | |
import numpy as npd | |
from PIL import Image | |
loaded_model = tf.keras.models.load_model('digit_recognition_model.h5') | |
def recognize_digit(image): | |
# Preprocess the input image | |
image = Image.fromarray(image).convert('L') # Convert to grayscale | |
image = image.resize((28, 28)) # Resize to 28x28 | |
image = np.array(image) | |
image = image / 255.0 # Normalize the pixel values | |
# Make a prediction using the loaded model | |
image = np.expand_dims(image, axis=0) # Add a batch dimension | |
prediction = loaded_model.predict(image) | |
predicted_digit = np.argmax(prediction) | |
return str(predicted_digit) | |
iface = gr.Interface(fn=recognize_digit, inputs="image", outputs="text") | |
iface.launch(share = True) | |