Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
def preprocesa_img(img_path):
|
| 7 |
+
img = load_img(img_path, color_mode="grayscale", target_size=(28, 28))
|
| 8 |
+
img_array = img_to_array(img)
|
| 9 |
+
img_array = 255 - img_array
|
| 10 |
+
img_array = img_array.reshape(1, 784) / 255.0
|
| 11 |
+
return img_array
|
| 12 |
+
|
| 13 |
+
model = tf.keras.models.load_model("identificadordigitos.h5")
|
| 14 |
+
st.title("Clasificaci贸n de im谩genes de d铆gitos")
|
| 15 |
+
|
| 16 |
+
uploaded_file = st.file_uploader("Subir una imagen de un d铆gito", type=["jpg", "png"])
|
| 17 |
+
|
| 18 |
+
if uploaded_file is not None:
|
| 19 |
+
image_array = preprocesa_img(uploaded_file)
|
| 20 |
+
|
| 21 |
+
st.write("Imagen preprocesada:", image_array)
|
| 22 |
+
|
| 23 |
+
preliminar = model.predict(image_array)
|
| 24 |
+
|
| 25 |
+
st.write("Predicci贸n del modelo (vector de probabilidades):", preliminar)
|
| 26 |
+
prediccion = np.argmax(preliminar, axis=1)[0]
|
| 27 |
+
st.success(f"Predicci贸n: {prediccion}")
|