| import streamlit as st |
| from tensorflow.keras.models import load_model |
| from PIL import Image |
| import numpy as np |
|
|
| |
| model = load_model('model.h5', compile=False) |
|
|
| |
| def process_image(img): |
| |
| img = img.resize((128, 128)) |
| img = np.array(img) |
| img = img / 255.0 |
| img = np.expand_dims(img, axis=0) |
| return img |
|
|
| |
| st.title('Age Prediction from Image') |
| st.write("Upload a photo to predict the subject's age.") |
|
|
| |
| st.sidebar.header("Instructions") |
| st.sidebar.write(""" |
| 1. Upload a clear face photo |
| 2. Model will analyze facial features |
| 3. Predicted age appears below image |
| 4. This dataset contains images of people generated by Stable Diffusion. |
| For each image, you are to determine how old the person is. |
| Ages will range between 20 and 90 years old. |
| """) |
|
|
| |
| file = st.file_uploader('Choose an image (JPG, JPEG, PNG)', type=['jpg', 'jpeg', 'png']) |
|
|
| if file is not None: |
| |
| img = Image.open(file).convert('RGB') |
| |
| |
| st.image(img, caption='Uploaded Image', use_column_width=True) |
| |
| |
| processed_image = process_image(img) |
| prediction = model.predict(processed_image) |
| prediction = np.round(prediction).astype(int) |
|
|
| |
| st.subheader("Prediction Result:") |
| st.markdown(f"**Estimated Age:** {prediction[0][0]} years") |
| |
| |
| st.info(""" |
| Note: Predictions are based on patterns learned during training. |
| Results may vary with image quality and lighting conditions. |
| """) |
| |
| st.divider() |
| else: |
| st.write("Please upload an image to begin.") |