|
from PIL import Image |
|
import numpy as np |
|
import gradio as gr |
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
model = load_model('mio_modello.h5') |
|
|
|
|
|
def preprocess_image(image): |
|
image = Image.fromarray(image) |
|
image = image.resize((64, 64)) |
|
image_array = np.array(image) / 255.0 |
|
image_array = np.expand_dims(image_array, axis=0) |
|
return image_array |
|
|
|
|
|
def classify_image(image): |
|
image_array = preprocess_image(image) |
|
prediction = model.predict(image_array) |
|
predicted_class_idx = np.argmax(prediction) |
|
|
|
|
|
class_labels = ['Chihuahua', 'Muffin'] |
|
return class_labels[predicted_class_idx] |
|
|
|
|
|
interface = gr.Interface( |
|
fn=classify_image, |
|
inputs=gr.Image(type="numpy"), |
|
outputs="label", |
|
title="Chihuahua vs Muffin Classifier", |
|
description="Carica un'immagine e scopri se è un Chihuahua o un Muffin!" |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|
|
|
|
|