Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,8 @@ import cv2
|
|
3 |
import numpy as np
|
4 |
import csv
|
5 |
from datetime import datetime
|
6 |
-
from flask import Flask,render_template
|
7 |
-
from flask_socketio import SocketIO,emit
|
8 |
-
import base64
|
9 |
-
|
10 |
-
|
11 |
-
app = Flask(__name__)
|
12 |
-
app.config['SECRET_KEY'] = 'secret!'
|
13 |
-
socket = SocketIO(app,async_mode="eventlet")
|
14 |
-
|
15 |
-
|
16 |
-
###################################
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# video_capture=cv2.VideoCapture(1)
|
21 |
-
# if not video_capture.isOpened():
|
22 |
-
# print("Failed to open the video capture.")
|
23 |
-
# exit()
|
24 |
-
|
25 |
-
|
26 |
|
|
|
27 |
|
28 |
sir_image=face_recognition.load_image_file("photos/sir.jpeg")
|
29 |
sir_encoding=face_recognition.face_encodings(sir_image)[0]
|
@@ -52,29 +33,15 @@ f=open(current_date+'.csv','w+',newline='')
|
|
52 |
lnwriter=csv.writer(f)
|
53 |
|
54 |
############################
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
# Decode the base64 data to bytes
|
59 |
-
image_bytes = base64.b64decode(base64_data)
|
60 |
-
# Convert the bytes to numpy array
|
61 |
-
image_array = np.frombuffer(image_bytes, dtype=np.uint8)
|
62 |
-
# Decode the numpy array as an image using OpenCV
|
63 |
-
image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
|
64 |
-
return image
|
65 |
-
|
66 |
-
@socket.on("connect")
|
67 |
-
def test_connect():
|
68 |
-
print("Connected")
|
69 |
-
emit("my response", {"data": "Connected"})
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
while True:
|
75 |
-
|
76 |
-
frame=base64_to_image(image)
|
77 |
-
|
78 |
small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
|
79 |
rgb_small_frame=small_frame[:,:,::-1]
|
80 |
if s:
|
@@ -99,16 +66,8 @@ def receive_image(image):
|
|
99 |
cv2.imshow("attendence system",frame)
|
100 |
if cv2.waitKey(1) & 0xFF==ord('q'):
|
101 |
break
|
102 |
-
|
|
|
103 |
f.close()
|
104 |
-
|
105 |
-
|
106 |
-
#######################################
|
107 |
-
@app.route("/")
|
108 |
-
def home():
|
109 |
-
return render_template("index.html")
|
110 |
-
|
111 |
-
if __name__ == '__main__':
|
112 |
-
# app.run(debug=True)
|
113 |
-
socket.run(app,host="0.0.0.0", port=7860)
|
114 |
-
#######################################
|
|
|
3 |
import numpy as np
|
4 |
import csv
|
5 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
video_capture=cv2.VideoCapture(0)
|
8 |
|
9 |
sir_image=face_recognition.load_image_file("photos/sir.jpeg")
|
10 |
sir_encoding=face_recognition.face_encodings(sir_image)[0]
|
|
|
33 |
lnwriter=csv.writer(f)
|
34 |
|
35 |
############################
|
36 |
+
import io
|
37 |
+
import streamlit as st
|
38 |
+
bytes_data=None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
img_file_buffer=st.camera_input("Take a picture")
|
41 |
+
if img_file_buffer is not None:
|
42 |
+
|
43 |
while True:
|
44 |
+
_,frame=video_capture.read()
|
|
|
|
|
45 |
small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)
|
46 |
rgb_small_frame=small_frame[:,:,::-1]
|
47 |
if s:
|
|
|
66 |
cv2.imshow("attendence system",frame)
|
67 |
if cv2.waitKey(1) & 0xFF==ord('q'):
|
68 |
break
|
69 |
+
video_capture.release()
|
70 |
+
cv2.destroyAllWindows()
|
71 |
f.close()
|
72 |
+
if bytes_data is None:
|
73 |
+
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|