Spaces:
Sleeping
Sleeping
| import tensorflow as tf | |
| import numpy as np | |
| import gradio as gr | |
| import cv2 # opencv-python | |
| model = tf.keras.models.load_model("TP_MNIST_CNN_model.h5") | |
| def preprocess_image(img): | |
| img = tf.image.rgb_to_grayscale(img) # Convert to grayscale | |
| img = tf.image.resize(img, (28, 28)) # Resize to model input size | |
| img = img / 255.0 # Normalize pixel values | |
| img = np.expand_dims(img, axis=0) # Add batch dimension | |
| return img | |
| # Function to make predictions | |
| def predict_image(img): | |
| processed_img = preprocess_image(img) | |
| prediction = model.predict(processed_img) | |
| return {str(i): float(prediction[0][i]) for i in range(10)} | |
| gr.Interface( | |
| fn=predict_image, | |
| inputs=gr.Image(), | |
| outputs=gr.Label(num_top_classes=3), | |
| examples=["minst6.png", "mnist1.png", "mnist2_5.png", "mnist69.png"], # Example images for interface | |
| title='Handwritten Digits Classification stage DREAMS Team' | |
| ).launch(share=True) |