Download src/streamlit_app.py from BeyzaTopbas/Facial__Keypoints__Detection: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/BeyzaTopbas/Facial__Keypoints__Detection/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/BeyzaTopbas/Facial__Keypoints__Detection/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/BeyzaTopbas/Facial__Keypoints__Detection/resolve/main/src/streamlit_app.py
1.05 kB
| 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" | |
| ) | |
| 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) | |