File size: 1,440 Bytes
f077ba0
 
 
 
 
 
 
 
 
 
 
52c23b9
c06620c
7e0c35b
c06620c
f077ba0
 
 
 
 
 
52c23b9
 
 
 
 
 
 
 
 
 
 
 
 
 
f077ba0
 
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
35
36
37
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()