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}")