oscarvillafuerte's picture
Update app.py
6dfb586 verified
import streamlit as st
import tensorflow as tf
from tensorflow.keras.preprocessing.image import load_img, img_to_array
import numpy as np
def preprocesa_img(img_path):
img = load_img(img_path, color_mode="grayscale", target_size=(28, 28))
img_array = img_to_array(img)
img_array = 255 - img_array # Invertir colores
img_array = img_array.reshape(1, 784) / 255.0 # Aplanar y normalizar
return img_array
# Cargar el modelo
model = tf.keras.models.load_model("identificadordigitos.h5")
st.title("Clasificaci贸n de im谩genes de d铆gitos")
uploaded_file = st.file_uploader("Subir una imagen de un d铆gito", type=["jpg", "png"])
if uploaded_file is not None:
image_array = preprocesa_img(uploaded_file)
# Verificar la imagen preprocesada
st.write("Imagen preprocesada:", image_array)
# Realizar la predicci贸n
preliminar = model.predict(image_array)
st.write("Predicci贸n del modelo (vector de probabilidades):", preliminar)
# Obtener la predicci贸n final
prediccion = np.argmax(preliminar, axis=1)[0]
st.success(f"Predicci贸n: {prediccion}")