nikshep01 commited on
Commit
4c1bcfc
1 Parent(s): e76f48b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -6,14 +6,7 @@ import numpy as np
6
  import os
7
  import sqlite3
8
  from datetime import datetime
9
-
10
- # Establish connection to SQLite database
11
- conn = sqlite3.connect('attendance.db')
12
- c = conn.cursor()
13
-
14
- # Create a table for storing attendance if it doesn't exist
15
- c.execute('''CREATE TABLE IF NOT EXISTS attendance
16
- (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, time TEXT)''')
17
 
18
  st.title("AIMLJan24 - Face Recognition")
19
 
@@ -39,10 +32,22 @@ encodeListknown = [face_recognition.face_encodings(img)[0] for img in Images]
39
  # camera to take photo of user in question
40
  file_name = st.file_uploader("Upload image")
41
 
42
- def add_attendance(name):
43
- username = name
44
- c.execute("INSERT INTO attendance (name, time) VALUES (?, ?)", (username, current_datetime))
45
- conn.commit()
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  if file_name is not None:
48
  col1, col2 = st.columns(2)
@@ -84,7 +89,7 @@ if file_name is not None:
84
  cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
85
 
86
  # Store attendance in SQLite database
87
- add_attendance(name)
88
 
89
  # Display the image with recognized faces
90
  st.image(image, use_column_width=True, output_format="PNG")
 
6
  import os
7
  import sqlite3
8
  from datetime import datetime
9
+ import requests
 
 
 
 
 
 
 
10
 
11
  st.title("AIMLJan24 - Face Recognition")
12
 
 
32
  # camera to take photo of user in question
33
  file_name = st.file_uploader("Upload image")
34
 
35
+ def update_data(names):
36
+ url = "https://20march2024-flask.glitch.me/adduserdata1" # Change this URL to your Glitch endpoint
37
+ success_count = 0
38
+
39
+ for name in names:
40
+ data = {'name': name}
41
+ response = requests.post(url, data=data)
42
+ if response.status_code == 200:
43
+ success_count += 1
44
+ else:
45
+ st.warning(f"Failed to mark attendance for {name}")
46
+
47
+ if success_count == len(names):
48
+ st.success("Attendance marked for all recognized faces. Have a good day!")
49
+ else:
50
+ st.warning("Attendance marked for some faces. Check warnings for details.")
51
 
52
  if file_name is not None:
53
  col1, col2 = st.columns(2)
 
89
  cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
90
 
91
  # Store attendance in SQLite database
92
+ add_attendance(recognized_names)
93
 
94
  # Display the image with recognized faces
95
  st.image(image, use_column_width=True, output_format="PNG")