Boy-Or-Girl / app.py
szili2011's picture
Create app.py
b6096d5 verified
raw
history blame
964 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load the trained model (ensure the model file is uploaded)
model = tf.keras.models.load_model('best_model.h5')
# Define the prediction function
def classify_image(img):
img = img.resize((150, 150)) # Resize to match model input
img = np.array(img) / 255.0 # Normalize pixel values
img = np.expand_dims(img, axis=0) # Add batch dimension
# Make prediction
prediction = model.predict(img)
class_names = ['Boy', 'Girl'] # Labels for prediction
predicted_class = class_names[np.argmax(prediction)]
return predicted_class
# Create Gradio interface
interface = gr.Interface(
fn=classify_image,
inputs=gr.inputs.Image(type="pil"),
outputs=gr.outputs.Label(),
title="Boy or Girl Classifier",
description="Upload an image, and the model will predict whether it's a boy or a girl."
)
# Launch the app
interface.launch()