| import streamlit as st |
| import numpy as np |
| import tensorflow as tf |
| from PIL import Image |
| import os |
|
|
| |
| MODEL_PATH = "/app/src/facial_keypoints_resnet.h5" |
|
|
| st.set_page_config( |
| page_title="Facial Keypoints Detection", |
| layout="centered" |
| ) |
|
|
| @st.cache_resource |
| def load_model(): |
| return tf.keras.models.load_model( |
| MODEL_PATH, |
| compile=False |
| ) |
|
|
|
|
| st.title("Facial Keypoints Detection") |
| st.write("Upload a face image and the model will predict facial keypoints.") |
|
|
| model = load_model() |
|
|
|
|
| uploaded_file = st.file_uploader( |
| "Upload an image", |
| type=["jpg", "png", "jpeg"] |
| ) |
|
|
| if uploaded_file is not None: |
| image = Image.open(uploaded_file).convert("L") |
| image = image.resize((96, 96)) |
|
|
| st.image(image, caption="Uploaded image", width=250) |
|
|
| img_array = np.array(image).reshape(1, 96, 96, 1) / 255.0 |
| preds = model.predict(img_array)[0] |
|
|
| keypoints = preds.reshape(-1, 2) |
|
|
| st.subheader("Predicted Keypoints (x, y)") |
| st.write(keypoints) |
|
|