itsanurag commited on
Commit
6fb550c
·
verified ·
1 Parent(s): 8afc213

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -7,16 +7,6 @@ import time
7
  import streamlit as st
8
  import pygame
9
 
10
- # Setting up config for GPU usage
11
- physical_devices = tf.config.list_physical_devices("GPU")
12
- tf.config.experimental.set_memory_growth(physical_devices[0], True)
13
-
14
- # Using Har-cascade classifier from OpenCV
15
- face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
16
-
17
- # Loading the trained model for prediction purpose
18
- model = keras.models.load_model('my_model (1).h5')
19
-
20
  # Initialize Pygame mixer
21
  pygame.mixer.init()
22
 
@@ -25,6 +15,12 @@ def play_alert_sound():
25
  pygame.mixer.music.load(pygame.mixer.Sound(pygame.mixer.get_init())) # Load a simple beep sound
26
  pygame.mixer.music.play()
27
 
 
 
 
 
 
 
28
  # Title for GUI
29
  st.title('Drowsiness Detection')
30
 
@@ -54,10 +50,11 @@ if nav_choice == 'Home':
54
  'dataset used is available <a href="https://www.kaggle.com/kutaykutlu/drowsiness-detection", '
55
  'target="_blank">here</a></font></b>'
56
  , unsafe_allow_html=True)
57
-
58
  # Sleep Detection page
59
  elif nav_choice == 'Sleep Detection':
60
  st.header('Image Prediction')
 
61
  st.success('Please look at your web-cam, while following all the instructions given on the Home page.')
62
  st.warning(
63
  'Keeping the eyes in the same state is important but you can obviously blink your eyes, if they are open!!!')
@@ -106,6 +103,7 @@ elif nav_choice == 'Sleep Detection':
106
  img_container[0].image(frame1, width=250)
107
  img_container[2].image(cv2.cvtColor(eye_1, cv2.COLOR_BGR2RGB), width=150)
108
  img_container[3].image(cv2.cvtColor(eye_2, cv2.COLOR_BGR2RGB), width=150)
 
109
 
110
  # Decision variable for prediction
111
  if e1 == 1 or e2 == 1:
@@ -126,10 +124,11 @@ elif nav_choice == 'Sleep Detection':
126
  finally:
127
  cap.release()
128
 
129
- # If found drowsy, play the alert sound to alert the driver
130
  if decision == 0:
131
  st.error('Eye(s) are closed')
132
  play_alert_sound()
 
133
  else:
134
  st.success('Eyes are Opened')
135
  st.warning('Please select "Stop" and then "Start" to try again')
 
7
  import streamlit as st
8
  import pygame
9
 
 
 
 
 
 
 
 
 
 
 
10
  # Initialize Pygame mixer
11
  pygame.mixer.init()
12
 
 
15
  pygame.mixer.music.load(pygame.mixer.Sound(pygame.mixer.get_init())) # Load a simple beep sound
16
  pygame.mixer.music.play()
17
 
18
+ # Using Har-cascade classifier from OpenCV
19
+ face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
20
+
21
+ # Loading the trained model for prediction purpose
22
+ model = keras.models.load_model('my_model (1).h5')
23
+
24
  # Title for GUI
25
  st.title('Drowsiness Detection')
26
 
 
50
  'dataset used is available <a href="https://www.kaggle.com/kutaykutlu/drowsiness-detection", '
51
  'target="_blank">here</a></font></b>'
52
  , unsafe_allow_html=True)
53
+
54
  # Sleep Detection page
55
  elif nav_choice == 'Sleep Detection':
56
  st.header('Image Prediction')
57
+ cap = 0
58
  st.success('Please look at your web-cam, while following all the instructions given on the Home page.')
59
  st.warning(
60
  'Keeping the eyes in the same state is important but you can obviously blink your eyes, if they are open!!!')
 
103
  img_container[0].image(frame1, width=250)
104
  img_container[2].image(cv2.cvtColor(eye_1, cv2.COLOR_BGR2RGB), width=150)
105
  img_container[3].image(cv2.cvtColor(eye_2, cv2.COLOR_BGR2RGB), width=150)
106
+ print(e1, e2)
107
 
108
  # Decision variable for prediction
109
  if e1 == 1 or e2 == 1:
 
124
  finally:
125
  cap.release()
126
 
127
+ # If found drowsy, then make a beep sound to alert the driver
128
  if decision == 0:
129
  st.error('Eye(s) are closed')
130
  play_alert_sound()
131
+
132
  else:
133
  st.success('Eyes are Opened')
134
  st.warning('Please select "Stop" and then "Start" to try again')