Spaces:
Running
Running
File size: 818 Bytes
d1ffd11 9d84828 d1ffd11 |
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 |
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() |