Ahmadkhan12 commited on
Commit
46274ff
·
verified ·
1 Parent(s): df01c5c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image, ImageOps
3
+ import numpy as np
4
+ import requests
5
+
6
+ # Function for image preprocessing
7
+ def preprocess_image(image):
8
+ # Convert image to grayscale
9
+ gray_image = ImageOps.grayscale(image)
10
+ # Resize the image to 48x48 (common for emotion recognition models)
11
+ resized_image = gray_image.resize((48, 48))
12
+ # Convert the image to a numpy array
13
+ image_array = np.array(resized_image)
14
+ # Normalize the image array (values between 0 and 1)
15
+ normalized_image = image_array / 255.0
16
+ return normalized_image
17
+
18
+ # Title and description
19
+ st.title("Emotion Recognition for Autism Support")
20
+ st.write("Upload an image, and the app will help identify emotions.")
21
+
22
+ # Upload image section
23
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
24
+
25
+ if uploaded_file:
26
+ # Load the image using PIL
27
+ image = Image.open(uploaded_file)
28
+ st.image(image, caption="Uploaded Image", use_column_width=True)
29
+ st.success("Image uploaded successfully!")
30
+
31
+ # Preprocess the image
32
+ st.write("Preprocessing the image for emotion recognition...")
33
+ preprocessed_image = preprocess_image(image)
34
+ st.write("Preprocessing complete. Ready for emotion analysis.")
35
+
36
+ # Display preprocessed image
37
+ st.image(Image.fromarray((preprocessed_image * 255).astype('uint8')), caption="Preprocessed Image")
38
+
39
+ # Placeholder for emotion recognition (to be integrated with a model later)
40
+ st.info("Emotion recognition will be added in the next step.")
41
+
42
+ # Footer
43
+ st.write("---")
44
+ st.write("Developed to assist children with autism in recognizing emotions.")