nikshep01 commited on
Commit
b437af2
·
verified ·
1 Parent(s): 433baf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -35,22 +35,21 @@ file_name = st.camera_input("Upload image")
35
 
36
 
37
 
38
- def add_attendance(names):
39
  url = "https://ai-ml-project.glitch.me/adduserdata1" # Change this URL to your Glitch endpoint
40
- success_count = 0
41
- print(len(names))
42
-
43
  data = {'name': name}
44
- response = requests.get(url, data=data)
45
- if response.status_code == 200:
46
- success_count += 1
47
- else:
48
- st.warning(f"Failed to mark attendance for {name}")
49
-
50
- if success_count == len(names):
51
- st.success("Attendance marked for all recognized faces. Have a good day!")
52
- else:
53
- st.success("Attendance marked for some faces. Check warnings for details.")
 
 
54
 
55
  if file_name is not None:
56
  col1, col2 = st.columns(2)
@@ -83,7 +82,8 @@ if file_name is not None:
83
 
84
  # Append recognized name to the list
85
  recognized_names.append(name)
86
-
 
87
  # Draw rectangle around the face
88
  y1, x2, y2, x1 = faceLoc
89
  y1, x2, y2, x1 = (y1 * 4), (x2 * 4), (y2 * 4) ,(x1 * 4)
 
35
 
36
 
37
 
38
+ def add_attendance(name):
39
  url = "https://ai-ml-project.glitch.me/adduserdata1" # Change this URL to your Glitch endpoint
 
 
 
40
  data = {'name': name}
41
+ try:
42
+ response = requests.get(url, data=data, timeout=10)
43
+ if response.status_code == 200:
44
+ st.success(f"Attendance marked for {name}")
45
+ else:
46
+ st.warning(f"Failed to mark attendance for {name}. Status code: {response.status_code}")
47
+ except requests.exceptions.ConnectionError:
48
+ st.error(f"Failed to connect to the server for {name}. Please check the server.")
49
+ except requests.exceptions.Timeout:
50
+ st.error(f"Request timed out for {name}.")
51
+ except Exception as e:
52
+ st.error(f"An unexpected error occurred for {name}: {str(e)}")
53
 
54
  if file_name is not None:
55
  col1, col2 = st.columns(2)
 
82
 
83
  # Append recognized name to the list
84
  recognized_names.append(name)
85
+
86
+
87
  # Draw rectangle around the face
88
  y1, x2, y2, x1 = faceLoc
89
  y1, x2, y2, x1 = (y1 * 4), (x2 * 4), (y2 * 4) ,(x1 * 4)