oscarvillafuerte commited on
Commit
6dfb586
verified
1 Parent(s): 5835a60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -1,29 +1,31 @@
1
  import streamlit as st
2
  import tensorflow as tf
3
- from tensorflow.keras.preprocessing.image import img_to_array, load_img
4
- from PIL import Image
5
  import numpy as np
6
 
7
  def preprocesa_img(img_path):
8
- img= load_img(img_path, color_mode = "grayscale", target_size=(28,28))
9
- img_array = img_to_array(img)
10
- img_array = 255-img_array
11
- img_array = np.expand_dims(img_array, axis = 0)
12
- return img_array
13
-
 
14
  model = tf.keras.models.load_model("identificadordigitos.h5")
15
- st.title("Clasificaci贸n de imagenes")
16
 
17
- uploaded_file = st.file_uploader("Subir una imagen de un digito", type =["jpg", "png"])
18
 
19
  if uploaded_file is not None:
20
  image_array = preprocesa_img(uploaded_file)
21
 
22
- model = tf.keras.models.load_model("identificadordigitos.h5")
23
- preimg_flat = image_array.reshape(1, 784)
24
- preliminar = model.predict(preimg_flat)
25
 
26
- st.write(preliminar)
27
- prediccion = np.argmax(preliminar, axis=1)
 
28
 
29
- st.write(prediccion)
 
 
 
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}")