File size: 964 Bytes
b6096d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()