oscarvillafuerte's picture
Create app.py
d090700 verified
raw
history blame
919 Bytes
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
img_array = img_array.reshape(1, 784) / 255.0
return img_array
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)
st.write("Imagen preprocesada:", image_array)
preliminar = model.predict(image_array)
st.write("Predicci贸n del modelo (vector de probabilidades):", preliminar)
prediccion = np.argmax(preliminar, axis=1)[0]
st.success(f"Predicci贸n: {prediccion}")