Spaces:
Runtime error
Runtime error
Create app_test.py
Browse files- app_test.py +28 -0
app_test.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load the CNN model from the .h5 file
|
| 6 |
+
model = tf.keras.models.load_model('TP_MNIST_CNN_model.h5')
|
| 7 |
+
|
| 8 |
+
def predict_digit(image):
|
| 9 |
+
# Preprocess the input image
|
| 10 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 11 |
+
image = image / 255.0 # Normalize pixel values
|
| 12 |
+
|
| 13 |
+
# Make predictions
|
| 14 |
+
predictions = model.predict(image)
|
| 15 |
+
|
| 16 |
+
# Get the predicted digit
|
| 17 |
+
predicted_digit = np.argmax(predictions)
|
| 18 |
+
|
| 19 |
+
return predicted_digit
|
| 20 |
+
|
| 21 |
+
# Define Gradio interface
|
| 22 |
+
gr.Interface(
|
| 23 |
+
title="Reconnaissance d'écriture manuscrite des données MNIST by PSW",
|
| 24 |
+
fn=predict_digit,
|
| 25 |
+
inputs=gr.Sketchpad(label="Desinner le chiffre ici", height=300, width=800),
|
| 26 |
+
outputs="number",
|
| 27 |
+
live=True
|
| 28 |
+
).launch(debug=True)
|