Spaces:
Running
Running
File size: 1,152 Bytes
f394b7f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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}")
|