import streamlit as st from PIL import Image from tensorflow.keras.models import load_model from keras.preprocessing.image import load_img import numpy as np st.set_page_config( page_title="gender and age prediction", page_icon="✨", layout="centered", initial_sidebar_state="expanded", ) main_image = Image.open('main_banner.png') #load weights model = load_model('Gender_and_Age.keras') gender_dict = {0:'مرد', 1:'زن'} st.image(main_image,use_container_width='auto') st.markdown("

پیش بینی جنسیت و سن از روی عکس

", unsafe_allow_html=True) st.markdown("

omidsakaki.ir

", unsafe_allow_html=True) uploaded_file = st.file_uploader("Upload Image", type=["png","jpg","bmp","jpeg"]) if uploaded_file is not None: image = Image.open(uploaded_file).convert('RGB') st.image(image, caption='input image 📷',use_container_width='auto') image.save('input_image.jpg') img = load_img('input_image.jpg', color_mode='grayscale') img = img.resize((128, 128), Image.Resampling.LANCZOS) img = np.array(img) img = img.reshape(1, 128, 128, 1) img = img/255.0 pred = model.predict(img) pred_gender = gender_dict[round(pred[0][0][0])] pred_age = round(pred[1][0][0]) st.markdown("------") st.write("Predicted Gender:", pred_gender) st.write("Predicted Age:", pred_age) st.markdown("

Made with ❤️ by omid sakaki ghazvini

", unsafe_allow_html=True)