Spaces:
Running
Running
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}") | |