import streamlit as st from PIL import Image, ImageOps import numpy as np import requests # Function for image preprocessing def preprocess_image(image): # Convert image to grayscale gray_image = ImageOps.grayscale(image) # Resize the image to 48x48 (common for emotion recognition models) resized_image = gray_image.resize((48, 48)) # Convert the image to a numpy array image_array = np.array(resized_image) # Normalize the image array (values between 0 and 1) normalized_image = image_array / 255.0 return normalized_image # Title and description st.title("Emotion Recognition for Autism Support") st.write("Upload an image, and the app will help identify emotions.") # Upload image section uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) if uploaded_file: # Load the image using PIL image = Image.open(uploaded_file) st.image(image, caption="Uploaded Image", use_column_width=True) st.success("Image uploaded successfully!") # Preprocess the image st.write("Preprocessing the image for emotion recognition...") preprocessed_image = preprocess_image(image) st.write("Preprocessing complete. Ready for emotion analysis.") # Display preprocessed image st.image(Image.fromarray((preprocessed_image * 255).astype('uint8')), caption="Preprocessed Image") # Placeholder for emotion recognition (to be integrated with a model later) st.info("Emotion recognition will be added in the next step.") # Footer st.write("---") st.write("Developed to assist children with autism in recognizing emotions.")