Facial__Keypoints__Detection / src /streamlit_app.py
BeyzaTopbas's picture
Update src/streamlit_app.py
f20919f verified
import streamlit as st
import numpy as np
import tensorflow as tf
from PIL import Image
import os
# πŸ‘‡ HIER PLAATSEN (boven load_model)
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 # πŸ”₯ BELANGRIJK
)
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)