Spaces:
Sleeping
Sleeping
import cv2 | |
import streamlit as st | |
from PIL import Image | |
import numpy as np | |
from tensorflow.keras.preprocessing import image | |
from tensorflow.keras.applications.vgg16 import preprocess_input | |
import tensorflow as tf | |
from base64 import b64decode, b64encode | |
import PIL | |
import io | |
import html | |
import time | |
from facenet_pytorch import MTCNN | |
model_file_path = 'models/bmi.h5' | |
model = tf.keras.models.load_model(model_file_path) | |
# Preprocess the images for VGG16 | |
def preprocess_image(img_path): | |
img = image.load_img(img_path, target_size = (224, 224)) | |
img = image.img_to_array(img) | |
img = np.expand_dims(img, axis = 0) | |
img = preprocess_input(img)/255. | |
return img | |
def main(): | |
st.title("BMI Prediction from Camera Image") | |
st.write("This app predicts the BMI of a person from an image captured using the camera.") | |
# Capture an image from the camera using streamlit-media's camera_input function | |
img_file_buffer = st.camera_input("Take a picture") | |
if img_file_buffer is not None: | |
embeddings = preprocess_image(img_file_buffer) | |
bmi = model.predict(embeddings) | |
st.write(f"Your BMI is {round(bmi[0][0] - 8,2)}") | |
if __name__ == '__main__': | |
main() | |