charulp2499 commited on
Commit
bfa1884
·
verified ·
1 Parent(s): 2ea3d20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -7,7 +7,7 @@ import numpy as np
7
  # Initialize emotion detector
8
  emotion_detector = FER()
9
 
10
- # Function to process uploaded image
11
  def process_image(image):
12
  frame = np.array(image)
13
  frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) # Convert from PIL to OpenCV format
@@ -42,14 +42,19 @@ def process_image(image):
42
  return cv2.cvtColor(blurred_frame, cv2.COLOR_BGR2RGB) # Convert back to RGB for Streamlit
43
 
44
  # Streamlit UI
45
- st.title("Emotion Recognition App")
46
- st.write("Upload an image to detect emotions.")
47
 
48
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
 
 
 
 
 
 
 
 
 
49
 
50
- if uploaded_file is not None:
51
- image = Image.open(uploaded_file)
52
- st.image(image, caption="Uploaded Image", use_column_width=True)
53
-
54
  processed_image = process_image(image)
55
  st.image(processed_image, caption="Processed Image with Emotions", use_column_width=True)
 
7
  # Initialize emotion detector
8
  emotion_detector = FER()
9
 
10
+ # Function to process image and detect emotions
11
  def process_image(image):
12
  frame = np.array(image)
13
  frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) # Convert from PIL to OpenCV format
 
42
  return cv2.cvtColor(blurred_frame, cv2.COLOR_BGR2RGB) # Convert back to RGB for Streamlit
43
 
44
  # Streamlit UI
45
+ st.title("Real-Time Emotion Recognition")
46
+ st.write("Use the camera or upload an image to detect emotions.")
47
 
48
+ # Camera Input
49
+ camera_image = st.camera_input("Take a picture")
50
+
51
+ # File Upload
52
+ uploaded_file = st.file_uploader("Or upload an image...", type=["jpg", "png", "jpeg"])
53
+
54
+ # Process image if uploaded or captured via camera
55
+ if camera_image or uploaded_file:
56
+ image = Image.open(camera_image if camera_image else uploaded_file)
57
+ st.image(image, caption="Captured Image", use_column_width=True)
58
 
 
 
 
 
59
  processed_image = process_image(image)
60
  st.image(processed_image, caption="Processed Image with Emotions", use_column_width=True)