Spaces:
Sleeping
Sleeping
File size: 1,160 Bytes
01add57 f8b4541 01add57 f8b4541 01add57 7983904 01add57 f8b4541 01add57 f8b4541 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import streamlit as st
from PIL import Image
import numpy as np
import cv2
from tensorflow.keras.models import load_model
import os
# Ensure the 'upload' directory exists
upload_folder = 'uploads'
if not os.path.exists(upload_folder):
os.makedirs(upload_folder)
# Load the pre-trained model
model = load_model("gender_detector.keras")
def get_result(img_path):
img = cv2.imread(img_path)
img_resize = cv2.resize(img, (224, 224))
img_resize = np.array(img_resize, dtype=np.float32)
img_resize /= 255.0
img_input = img_resize.reshape(1, 224, 224, 3)
prediction = model.predict(img_input)
if prediction[0][0] < 0.5:
return "He is a Men 🚹"
else:
return "She is a Women 🚺"
st.title("Let\'s detect the gender 🚹🚺")
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_image is not None:
image = Image.open(uploaded_image)
image_path = os.path.join(upload_folder, uploaded_image.name)
image.save(image_path)
output = get_result(image_path)
st.write(output)
st.image(image, use_container_width=True)
|