| import streamlit as st |
| import numpy as np |
| from tensorflow.keras.models import load_model |
| from PIL import Image |
|
|
| |
| model_cnn = load_model('MNIST_conv.h5') |
| model_mlp = load_model('MNIST.h5') |
| model_cnn_v2 = load_model('mnist_conv (1).h5') |
| |
| class_labels = { |
| 0: "Cero", |
| 1: "Uno", |
| 2: "Dos", |
| 3: "Tres", |
| 4: "Cuatro", |
| 5: "Cinco", |
| 6: "Seis", |
| 7: "Siete", |
| 8: "Ocho", |
| 9: "Nueve" |
| } |
|
|
| |
| def prepare_image(image): |
| image = image.convert('L') |
| image = image.resize((28, 28)) |
| image_array = np.array(image) |
| image_array = image_array / 255.0 |
| image_array = image_array.reshape(1, 28, 28, 1) |
| return image_array |
|
|
| |
| st.title("Predicci贸n de Moda con Modelos") |
|
|
| |
| model_choice = st.selectbox("Selecciona el modelo:", ("Modelo Convolucional", "Modelo No Convolucional", "Modelo Convolucional (10 epocas mas (30))")) |
|
|
| |
| uploaded_file = st.file_uploader("Sube una imagen de 28x28 en escala de grises", type=["png", "jpg", "jpeg"]) |
|
|
| |
| if uploaded_file is not None: |
| |
| image = Image.open(uploaded_file) |
| st.image(image, caption='Imagen subida', use_column_width=True) |
|
|
| |
| prepared_image = prepare_image(image) |
|
|
| |
| if model_choice == "Modelo Convolucional": |
| prediction = model_cnn.predict(prepared_image) |
| |
| elif model_choice == "Modelo No Convolucional": |
| prediction = model_mlp.predict(prepared_image) |
| else: |
| prediction = model_cnn_v2.predict(prepared_image) |
| predicted_class = np.argmax(prediction, axis=1)[0] |
|
|
| |
| predicted_label = class_labels[predicted_class] |
|
|
| |
| st.success(f"La predicci贸n es: {predicted_label}") |