File size: 1,133 Bytes
0564cb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3bde80
 
0564cb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
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()