Spaces:
Sleeping
Sleeping
AbdullahOmar0
commited on
Commit
•
5e6f7f7
1
Parent(s):
3e828cc
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as npd
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
|
7 |
+
loaded_model = tf.keras.models.load_model('digit_recognition_model.h5')
|
8 |
+
|
9 |
+
def recognize_digit(image):
|
10 |
+
# Preprocess the input image
|
11 |
+
image = Image.fromarray(image).convert('L') # Convert to grayscale
|
12 |
+
image = image.resize((28, 28)) # Resize to 28x28
|
13 |
+
image = np.array(image)
|
14 |
+
image = image / 255.0 # Normalize the pixel values
|
15 |
+
|
16 |
+
# Make a prediction using the loaded model
|
17 |
+
image = np.expand_dims(image, axis=0) # Add a batch dimension
|
18 |
+
prediction = loaded_model.predict(image)
|
19 |
+
predicted_digit = np.argmax(prediction)
|
20 |
+
|
21 |
+
return str(predicted_digit)
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=recognize_digit, inputs="image", outputs="text")
|
24 |
+
iface.launch(share = True)
|