Spaces:
Sleeping
Sleeping
Download app.py from RagedKrish/height_weight_predicter: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/RagedKrish/height_weight_predicter/resolve/main/app.py
- Command line
-
hf download hf://spaces/RagedKrish/height_weight_predicter/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RagedKrish/height_weight_predicter/resolve/main/app.py
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() | |