Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import cv2
|
2 |
import numpy as np
|
3 |
import streamlit as st
|
4 |
from tensorflow.keras.preprocessing.image import img_to_array
|
@@ -29,42 +28,31 @@ with st.container():
|
|
29 |
st.header("π Eye Status")
|
30 |
status_placeholder = st.markdown("**Status:** Waiting for webcam input...")
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
status_color = "red"
|
61 |
-
|
62 |
-
# Update UI with the prediction status
|
63 |
-
status_placeholder.markdown(f"**Status:** <span style='color:{status_color}'>{status}</span>", unsafe_allow_html=True)
|
64 |
-
|
65 |
-
# Display the video feed
|
66 |
-
FRAME_WINDOW.image(frame_rgb)
|
67 |
-
|
68 |
-
# Release resources when the checkbox is unchecked
|
69 |
-
cap.release()
|
70 |
-
cv2.destroyAllWindows()
|
|
|
|
|
1 |
import numpy as np
|
2 |
import streamlit as st
|
3 |
from tensorflow.keras.preprocessing.image import img_to_array
|
|
|
28 |
st.header("π Eye Status")
|
29 |
status_placeholder = st.markdown("**Status:** Waiting for webcam input...")
|
30 |
|
31 |
+
# Webcam input using Streamlit's camera_input widget
|
32 |
+
if run:
|
33 |
+
camera_input = st.camera_input("Capture image")
|
34 |
+
|
35 |
+
if camera_input:
|
36 |
+
# Convert the image to RGB format and resize it for prediction
|
37 |
+
img_resized = cv2.resize(camera_input, (IMG_SIZE, IMG_SIZE))
|
38 |
+
|
39 |
+
# Preprocess the image
|
40 |
+
img_array = img_to_array(img_resized) / 255.0
|
41 |
+
img_array = np.expand_dims(img_array, axis=0)
|
42 |
+
|
43 |
+
# Predict eye status
|
44 |
+
prediction = model.predict(img_array)
|
45 |
+
|
46 |
+
# Update prediction status
|
47 |
+
if prediction[0][0] > 0.8:
|
48 |
+
status = "Eye is Open π"
|
49 |
+
status_color = "green"
|
50 |
+
else:
|
51 |
+
status = "Eye is Closed π΄"
|
52 |
+
status_color = "red"
|
53 |
+
|
54 |
+
# Update UI with the prediction status
|
55 |
+
status_placeholder.markdown(f"**Status:** <span style='color:{status_color}'>{status}</span>", unsafe_allow_html=True)
|
56 |
+
|
57 |
+
# Display the webcam feed
|
58 |
+
FRAME_WINDOW.image(camera_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|