nadyanvl's picture
Update app.py
c5ac2d2
raw
history blame contribute delete
672 Bytes
import os
import tensorflow as tf
import gradio as gr
import numpy as np
from PIL import Image
# Define the root directory
model = tf.keras.models.load_model("gender_resnet50.h5")
def predict_gender(image):
image = image.resize((224, 224))
image = tf.keras.utils.img_to_array(image)
image = image / 255.0
pred_arr = np.expand_dims(image, axis=0)
result = model.predict(pred_arr)
prob = result[0]
text_res = "Male" if prob >= 0.5 else "Female"
return text_res
# Create the Gradio interface
interface = gr.Interface(fn=predict_gender, inputs=gr.Image(type="pil"), outputs="text")
# Launch the Gradio interface
interface.launch(share=True)