Krishs21
Updated files
b3bde80
Raw History Blame Contribute Delete
1.13 kB
import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing.image import load_img, img_to_array
# Load the model
model = tf.keras.models.load_model("h_w_model.h5")
# Image size used for training
IMG_SIZE = (299, 299)
# Preprocessing function
def preprocess_image(image):
image = image.resize(IMG_SIZE)
img_array = img_to_array(image) / 255.0
img_array = np.expand_dims(img_array, axis=0)
return img_array
# Prediction function
def predict_hw(image):
preprocessed = preprocess_image(image)
pred = model.predict(preprocessed)
height = round(float(pred[0][0]), 2)
weight = round(float(pred[1][0]), 2)
return height, weight # ✅ Return as a tuple, not dict
# Gradio Interface
iface = gr.Interface(
fn=predict_hw,
inputs=gr.Image(type="pil"),
outputs=[
gr.Number(label="Predicted Height"),
gr.Number(label="Predicted Weight")
],
title="Height & Weight Predictor",
description="Upload an image and get predicted height and weight using a CNN model (Xception-based)."
)
if __name__ == "__main__":
iface.launch()