lokesh2002 commited on
Commit
b035cb5
·
verified ·
1 Parent(s): 2d1fb5c

Initial commit

Browse files
Files changed (5) hide show
  1. app.py +73 -0
  2. le.pkl +3 -0
  3. randomforest.pkl +3 -0
  4. requirements.txt +6 -0
  5. scaler.pkl +3 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import cv2
4
+ import numpy as np
5
+ import pandas as pd
6
+ import streamlit as st
7
+ import joblib
8
+
9
+ SCALER_PATH = r"C:\Users\Kumar\Desktop\Driver-pose-detection\scaler.pkl"
10
+ ENCODER_PATH = r"C:\Users\Kumar\Desktop\Driver-pose-detection\le.pkl"
11
+ MODEL_PATH = r"C:\Users\Kumar\Desktop\Driver-pose-detection\randomforest.pkl"
12
+
13
+ scaler = joblib.load(SCALER_PATH)
14
+ encoder = joblib.load(ENCODER_PATH)
15
+ model = joblib.load(MODEL_PATH)
16
+ pred = None
17
+ def live_data_pred(cam_input):
18
+ bytes_data = cam_input.getvalue()
19
+
20
+ cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), 0)
21
+ resize_img = cv2.resize(cv2_img, (256, 256), interpolation=cv2.INTER_CUBIC)
22
+ flattened_img = resize_img.flatten()
23
+ flattened_img = np.reshape(flattened_img, (1, -1))
24
+
25
+ scaled_input = scaler.transform(flattened_img)
26
+ prediction = model.predict(scaled_input)
27
+ prediction = encoder.inverse_transform(prediction)
28
+
29
+ return prediction
30
+
31
+ def pick_gif(prediction):
32
+ pass
33
+
34
+
35
+
36
+
37
+ st.set_page_config(page_title="Driver Posture Alert System", layout='wide')
38
+ st.markdown("## Driver Posture Detection and Alert System")
39
+ st.markdown(">A user friendly platform Indepedent application to detect the real time posture of the driver and provides appropriate actions")
40
+
41
+ with st.sidebar:
42
+ st.markdown("#### Choose the Input type")
43
+ opt = st.selectbox(
44
+ "Select the type of input",
45
+ ("Live camera input", "Captured input"),
46
+ index = None
47
+ )
48
+
49
+ if opt == "Live camera input":
50
+ cam_input = st.camera_input("Live input")
51
+ if cam_input is not None:
52
+ pred = live_data_pred(cam_input)
53
+ st.write(f"{pred}")
54
+ #gif_path = pick_gif(pred)
55
+
56
+ elif opt == "Captured input":
57
+ cam_input = st.file_uploader(
58
+ label="Upload captured image",
59
+ type= ["png", "jpg", "jpeg"]
60
+ )
61
+ if cam_input is not None:
62
+ pred = live_data_pred(cam_input)
63
+
64
+
65
+ if pred is not None:
66
+ st.markdown("### Image Captured - Prediction")
67
+ st.write(f"{pred[0].capitalize()}")
68
+ else:
69
+ st.markdown("#### Waiting for Input...")
70
+
71
+
72
+
73
+
le.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2268c2e08f8355a3e0f807d2d7dc5704d3172677bf80ff4e184df20e63bdcaca
3
+ size 607
randomforest.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c1cc348de0dd23c18a35f0be37f1bd63b2f594c79f38e79d6bc7af5d948875c
3
+ size 3124225
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ joblib
2
+ pandas
3
+ numpy
4
+ scikit-learn
5
+ opencv-python
6
+ streamlit
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3574c855404a5ccd463e480368107285eeeac9c98bdb487ca456b1b8f62e5f4d
3
+ size 1573479