pizzasteak / app.py
gusdelact's picture
Upload app.py
7e0c35b verified
import gradio as gr
import numpy as np
from PIL import Image
import tensorflow as tf
modelo = tf.keras.models.load_model("./pizza_vs_steak_gdct_intento1.keras")
# prompt: usando gradio, generar una interfaz para subir una imagen
import numpy as np
def predict_image(img):
img = Image.fromarray(img.astype('uint8')) # Pillow detecta modo automáticamente
img = img.resize((224, 224)) # Ahora coincide con lo que tu modelo espera
img_array = np.array(img) / 1.0 # Normaliza
img_array = np.expand_dims(img_array, axis=0) # Batch dimension
prediction = modelo.predict(img_array)
if prediction[0] > 0.5:
return "Steak"
else:
return "Pizza"
# def predict_image(img):
# img = Image.fromarray(img.astype('uint8'), 'RGB') # Ensure image is in correct format
# img = img.resize((128, 128)) # Resize to model input size
# img_array = np.array(img) / 255.0 # Normalize
# img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
# prediction = modelo.predict(img_array)
# print(prediction)
# # Assuming the model outputs a single value probability for one class (e.g., steak)
# # You might need to adjust this based on your model's output layer
# if prediction[0] > 0.5:
# return "Steak"
# else:
# return "Pizza"
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text", title="Pizza vs Steak Classifier")
iface.launch()