oscarvillafuerte
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,31 @@
|
|
1 |
import streamlit as st
|
2 |
import tensorflow as tf
|
3 |
-
from tensorflow.keras.preprocessing.image import
|
4 |
-
from PIL import Image
|
5 |
import numpy as np
|
6 |
|
7 |
def preprocesa_img(img_path):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
model = tf.keras.models.load_model("identificadordigitos.h5")
|
15 |
-
st.title("Clasificaci贸n de
|
16 |
|
17 |
-
uploaded_file = st.file_uploader("Subir una imagen de un
|
18 |
|
19 |
if uploaded_file is not None:
|
20 |
image_array = preprocesa_img(uploaded_file)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
preliminar = model.predict(preimg_flat)
|
25 |
|
26 |
-
|
27 |
-
|
|
|
28 |
|
29 |
-
|
|
|
|
|
|
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 # Invertir colores
|
10 |
+
img_array = img_array.reshape(1, 784) / 255.0 # Aplanar y normalizar
|
11 |
+
return img_array
|
12 |
+
|
13 |
+
# Cargar el modelo
|
14 |
model = tf.keras.models.load_model("identificadordigitos.h5")
|
15 |
+
st.title("Clasificaci贸n de im谩genes de d铆gitos")
|
16 |
|
17 |
+
uploaded_file = st.file_uploader("Subir una imagen de un d铆gito", type=["jpg", "png"])
|
18 |
|
19 |
if uploaded_file is not None:
|
20 |
image_array = preprocesa_img(uploaded_file)
|
21 |
|
22 |
+
# Verificar la imagen preprocesada
|
23 |
+
st.write("Imagen preprocesada:", image_array)
|
|
|
24 |
|
25 |
+
# Realizar la predicci贸n
|
26 |
+
preliminar = model.predict(image_array)
|
27 |
+
st.write("Predicci贸n del modelo (vector de probabilidades):", preliminar)
|
28 |
|
29 |
+
# Obtener la predicci贸n final
|
30 |
+
prediccion = np.argmax(preliminar, axis=1)[0]
|
31 |
+
st.success(f"Predicci贸n: {prediccion}")
|