# import streamlit as st # import pandas as pd # # Security # #passlib,hashlib,bcrypt,scrypt # import hashlib # def make_hashes(password): # return hashlib.sha256(str.encode(password)).hexdigest() # def check_hashes(password,hashed_text): # if make_hashes(password) == hashed_text: # return hashed_text # return False # # DB Management # import sqlite3 # conn = sqlite3.connect('data.db') # c = conn.cursor() # # DB Functions # def create_usertable(): # c.execute('CREATE TABLE IF NOT EXISTS userstable(username TEXT,password TEXT)') # def add_userdata(username,password): # c.execute('INSERT INTO userstable(username,password) VALUES (?,?)',(username,password)) # conn.commit() # def login_user(username,password): # c.execute('SELECT * FROM userstable WHERE username =? AND password = ?',(username,password)) # data = c.fetchall() # return data # def view_all_users(): # c.execute('SELECT * FROM userstable') # data = c.fetchall() # return data # def main(): # """Simple Login App""" # st.title("Simple Login App") # menu = ["Home","Login","SignUp"] # choice = st.sidebar.selectbox("Menu",menu) # if choice == "Home": # st.subheader("Home") # elif choice == "Login": # st.subheader("Login Section") # username = st.sidebar.text_input("User Name") # password = st.sidebar.text_input("Password",type='password') # if st.sidebar.checkbox("Login"): # # if password == '12345': # create_usertable() # hashed_pswd = make_hashes(password) # result = login_user(username,check_hashes(password,hashed_pswd)) # if result: # st.success("Logged In as {}".format(username)) # task = st.selectbox("Task",["Add Post","Analytics","Profiles"]) # if task == "Add Post": # st.subheader("Add Your Post") # elif task == "Analytics": # st.subheader("Analytics") # elif task == "Profiles": # st.subheader("User Profiles") # user_result = view_all_users() # clean_db = pd.DataFrame(user_result,columns=["Username","Password"]) # st.dataframe(clean_db) # else: # st.warning("Incorrect Username/Password") # elif choice == "SignUp": # st.subheader("Create New Account") # new_user = st.text_input("Username") # new_password = st.text_input("Password",type='password') # if st.button("Signup"): # create_usertable() # add_userdata(new_user,make_hashes(new_password)) # st.success("You have successfully created a valid Account") # st.info("Go to Login Menu to login") # if __name__ == '__main__': # main() import cv2 import datetime import imutils import numpy as np from centroidtracker import CentroidTracker import pandas as pd import torch import streamlit as st import mediapipe as mp import cv2 as cv import numpy as np import tempfile import time from PIL import Image import pandas as pd import torch import base64 import streamlit.components.v1 as components import csv import pickle from pathlib import Path import streamlit_authenticator as stauth import os import csv # x-x-x-x-x-x-x-x-x-x-x-x-x-x LOGIN FORM x-x-x-x-x-x-x-x-x data = ["student Count",'Date','Id','Mobile','Watch'] with open('final.csv', 'w') as file: writer = csv.writer(file) writer.writerow(data) import streamlit as st import pandas as pd import hashlib import sqlite3 # if st.button("Open CRM !!"): # # Security # #passlib,hashlib,bcrypt,scrypt # def make_hashes(password): # return hashlib.sha256(str.encode(password)).hexdigest() # def check_hashes(password,hashed_text): # if make_hashes(password) == hashed_text: # return hashed_text # return False # # DB Management # conn = sqlite3.connect('data.db') # c = conn.cursor() # # DB Functions # def create_usertable(): # c.execute('CREATE TABLE IF NOT EXISTS userstable(username TEXT,password TEXT)') # def add_userdata(username,password): # c.execute('INSERT INTO userstable(username,password) VALUES (?,?)',(username,password)) # conn.commit() # def login_user(username,password): # c.execute('SELECT * FROM userstable WHERE username =? AND password = ?',(username,password)) # data = c.fetchall() # return data # def view_all_users(): # c.execute('SELECT * FROM userstable') # data = c.fetchall() # return data # def main(): # """Simple Login App""" # st.title("Simple Login App") # menu = ["Home","Login","SignUp"] # choice = st.sidebar.selectbox("Menu",menu) # if choice == "Home": # st.subheader("Home") # elif choice == "Login": # st.subheader("Login Section") # username = st.sidebar.text_input("User Name") # password = st.sidebar.text_input("Password",type='password') # if st.sidebar.checkbox("Login"): # # if password == '12345': # create_usertable() # hashed_pswd = make_hashes(password) # result = login_user(username,check_hashes(password,hashed_pswd)) # if result: # st.success("Logged In as {}".format(username)) # # task = st.selectbox("Task",["Add Post","Analytics","Profiles"]) # # if task == "Add Post": # # st.subheader("Add Your Post") # # elif task == "Analytics": # # st.subheader("Analytics") # # elif task == "Profiles": # # st.subheader("User Profiles") # # user_result = view_all_users() # # clean_db = pd.DataFrame(user_result,columns=["Username","Password"]) # # st.dataframe(clean_db) # else: # st.warning("Incorrect Username/Password") # elif choice == "SignUp": # st.subheader("Create New Account") # new_user = st.text_input("Username") # new_password = st.text_input("Password",type='password') # if st.button("Signup"): # create_usertable() # add_userdata(new_user,make_hashes(new_password)) # st.success("You have successfully created a valid Account") # st.info("Go to Login Menu to login") # if __name__ == '__main__': # main() date_time = time.strftime("%b %d %Y %-I:%M %p") date = date_time.split() dates = date[0:3] times = date[3:5] # x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-xAPPLICACTION -x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x def non_max_suppression_fast(boxes, overlapThresh): try: if len(boxes) == 0: return [] if boxes.dtype.kind == "i": boxes = boxes.astype("float") pick = [] x1 = boxes[:, 0] y1 = boxes[:, 1] x2 = boxes[:, 2] y2 = boxes[:, 3] area = (x2 - x1 + 1) * (y2 - y1 + 1) idxs = np.argsort(y2) while len(idxs) > 0: last = len(idxs) - 1 i = idxs[last] pick.append(i) xx1 = np.maximum(x1[i], x1[idxs[:last]]) yy1 = np.maximum(y1[i], y1[idxs[:last]]) xx2 = np.minimum(x2[i], x2[idxs[:last]]) yy2 = np.minimum(y2[i], y2[idxs[:last]]) w = np.maximum(0, xx2 - xx1 + 1) h = np.maximum(0, yy2 - yy1 + 1) overlap = (w * h) / area[idxs[:last]] idxs = np.delete(idxs, np.concatenate(([last], np.where(overlap > overlapThresh)[0]))) return boxes[pick].astype("int") except Exception as e: print("Exception occurred in non_max_suppression : {}".format(e)) protopath = "MobileNetSSD_deploy.prototxt" modelpath = "MobileNetSSD_deploy.caffemodel" detector = cv2.dnn.readNetFromCaffe(prototxt=protopath, caffeModel=modelpath) # Only enable it if you are using OpenVino environment # detector.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE) # detector.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU) CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"] tracker = CentroidTracker(maxDisappeared=80, maxDistance=90) st.markdown( """ """, unsafe_allow_html=True, ) hide_streamlit_style = """ """ st.markdown(hide_streamlit_style, unsafe_allow_html=True) # Create Sidebar st.sidebar.title('FaceMesh Sidebar') st.sidebar.subheader('Parameter') # Define available pages in selection box app_mode = st.sidebar.selectbox( 'App Mode', ['About','Application'] ) # Resize Images to fit Container @st.cache() # Get Image Dimensions def image_resize(image, width=None, height=None, inter=cv.INTER_AREA): dim = None (h,w) = image.shape[:2] if width is None and height is None: return image if width is None: r = width/float(w) dim = (int(w*r),height) else: r = width/float(w) dim = width, int(h*r) # Resize image resized = cv.resize(image,dim,interpolation=inter) return resized # About Page # authenticator.logout('Logout','sidebar') if app_mode == 'About': st.title('About Product And Team') st.markdown(''' Imran Bhai Project ''') st.markdown( """ """, unsafe_allow_html=True, ) elif app_mode == 'Application': st.set_option('deprecation.showfileUploaderEncoding', False) use_webcam = st.button('Use Webcam') # record = st.sidebar.checkbox("Record Video") # if record: # st.checkbox('Recording', True) # drawing_spec = mp.solutions.drawing_utils.DrawingSpec(thickness=2, circle_radius=1) # st.sidebar.markdown('---') # ## Add Sidebar and Window style # st.markdown( # """ # # """, # unsafe_allow_html=True, # ) # max_faces = st.sidebar.number_input('Maximum Number of Faces', value=5, min_value=1) # st.sidebar.markdown('---') # detection_confidence = st.sidebar.slider('Min Detection Confidence', min_value=0.0,max_value=1.0,value=0.5) # tracking_confidence = st.sidebar.slider('Min Tracking Confidence', min_value=0.0,max_value=1.0,value=0.5) # st.sidebar.markdown('---') ## Get Video stframe = st.empty() video_file_buffer = st.file_uploader("Upload a Video", type=['mp4', 'mov', 'avi', 'asf', 'm4v']) temp_file = tempfile.NamedTemporaryFile(delete=False) if not video_file_buffer: if use_webcam: video = cv.VideoCapture(0) else: try: video = cv.VideoCapture(1) temp_file.name = video except: pass else: temp_file.write(video_file_buffer.read()) video = cv.VideoCapture(temp_file.name) width = int(video.get(cv.CAP_PROP_FRAME_WIDTH)) height = int(video.get(cv.CAP_PROP_FRAME_HEIGHT)) fps_input = int(video.get(cv.CAP_PROP_FPS)) ## Recording codec = cv.VideoWriter_fourcc('a','v','c','1') out = cv.VideoWriter('output1.mp4', codec, fps_input, (width,height)) st.sidebar.text('Input Video') # st.sidebar.video(temp_file.name) fps = 0 i = 0 drawing_spec = mp.solutions.drawing_utils.DrawingSpec(thickness=2, circle_radius=1) kpil, kpil2, kpil3,kpil4,kpil5, kpil6 = st.columns(6) with kpil: st.markdown('**Frame Rate**') kpil_text = st.markdown('0') with kpil2: st.markdown('**detection ID**') kpil2_text = st.markdown('0') with kpil3: st.markdown('**Mobile**') kpil3_text = st.markdown('0') with kpil4: st.markdown('**Watch**') kpil4_text = st.markdown('0') with kpil5: st.markdown('**Count**') kpil5_text = st.markdown('0') with kpil6: st.markdown('**Img Res**') kpil6_text = st.markdown('0') st.markdown('