import streamlit as st import tensorflow as tf import numpy as np from tensorflow.keras.models import load_model from PIL import Image import matplotlib.pyplot as plt # 📌 Carica il modello MODEL_PATH = "Silva.h5" if not MODEL_PATH: st.error("❌ Modello non trovato! Esegui prima il training.") else: model = load_model(MODEL_PATH) st.write("✅ Modello caricato correttamente!") # 📌 Carica un'immagine per il test uploaded_file = st.file_uploader("📤 Carica un'immagine per testare il modello", type=["jpg", "png", "jpeg"]) if uploaded_file: # Converti l'immagine in formato compatibile image = Image.open(uploaded_file).convert("RGB") image = image.resize((64, 64)) # 📌 Stessa dimensione usata nel training image_array = np.array(image) / 255.0 # Normalizzazione image_array = np.expand_dims(image_array, axis=0) # Aggiungi batch dimension st.image(image, caption="🔍 Immagine di test", use_column_width=True) # 📌 Esegui la previsione prediction = model.predict(image_array) predicted_class = np.argmax(prediction) st.write(f"🔮 **Classe Predetta:** {predicted_class}")