Spaces:
Running
Running
import gradio as gr | |
import numpy as np | |
import tensorflow as tf | |
import cv2 | |
# Load your trained model | |
#model = tf.keras.models.load_model('path_to_your_model.h5') | |
def predict_gender(image): | |
# Convert image to format expected by your model & preprocess | |
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) | |
img = cv2.resize(img, (224, 224)) # Example size | |
img = img / 255.0 # Normalizing | |
img = np.expand_dims(img, axis=0) | |
prediction = model.predict(img) | |
# Assuming binary classification with a single output neuron | |
return "Male" if prediction[0] < 0.5 else "Female" | |
# Define Gradio interface | |
iface = gr.Interface( | |
fn=predict_gender, | |
inputs=gr.inputs.Image(type="webcam", label="Capture an Image from Webcam"), | |
outputs=gr.outputs.Label(), | |
live=True | |
) | |
iface.launch() |