import gradio as gr import tensorflow as tf import numpy as np # Load the Keras model model = tf.keras.models.load_model("denis_mnist_cnn_model.h5") # Define a function to preprocess input and make predictions def predict(image): # Preprocess the image (resize, normalize, etc.) image = tf.image.resize(image, (224, 224)) # Example: Resize to 224x224 image = np.expand_dims(image, axis=0) # Add batch dimension image = image / 255.0 # Normalize pixel values # Perform prediction prediction = model.predict(image) return {"prediction": prediction.tolist()} # Create a Gradio interface interface = gr.Interface( fn=predict, inputs="image", # Text input for comma-separated values outputs="json" # JSON output for prediction results ) # Launch the Gradio app if __name__ == "__main__": interface.launch()