Rasleen commited on
Commit
bd7dcdf
Β·
verified Β·
1 Parent(s): 95edef9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -43
app.py CHANGED
@@ -82,47 +82,49 @@ with about_tab:
82
  """)
83
 
84
  with app_tab:
85
- enable = st.checkbox("Enable camera")
86
- picture = st.camera_input("Take a picture", disabled=not enable)
87
-
88
- if picture is not None:
89
- with st.spinner("Analyzing face..."):
90
- image_pil = Image.open(picture)
91
- matches, image_bgr = prod_function(app, image_paths, image_pil)
92
-
93
- if not matches:
94
- st.warning("No face detected in the captured image.")
95
- else:
96
- # st.write("Similarity Scores:", prediction_scores)
97
- for match in matches:
98
- x1, y1, x2, y2 = match['bbox']
99
- name = match['name']
100
- color = (0, 255, 0) if name != "Unknown" else (0, 0, 255)
101
- cv2.rectangle(image_bgr, (x1, y1), (x2, y2), color, 2)
102
- cv2.putText(image_bgr, name, (x1, y2 + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2)
103
 
104
- if name != "Unknown":
105
- # recognized = False
106
- # for score, idx in matches:
107
- # if matched_score >= 0.6:
108
- # matched_name = os.path.basename(image_paths[match_idx]).split('.')[0]
109
- # st.success(f"βœ… Welcome: {matched_name}")
110
- # recognizes=True
111
-
112
- # Send attendance via POST
113
- url = "https://nielit-attendance.glitch.me/adds"
114
- data = {'rno': 15, 'sname': matched_name, 'sclass': 7}
115
- try:
116
- response = requests.post(url, data=data)
117
- if response.status_code == 200:
118
- st.success(f"Attendance marked successfully for {matched_name}.")
119
- else:
120
- st.warning(f"Failed to update attendance for {matched_name}.")
121
- except Exception as e:
122
- st.error(f"Request failed: {e}")
123
- else:
124
- st.warning("❌ Face match not found or too low confidence.")
125
-
126
- # Convert back to RGB for display
127
- image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
128
- st.image(image_rgb, caption="Detected Faces", use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
82
  """)
83
 
84
  with app_tab:
85
+ col1, col2 = st.columns(2)
86
+ with col1:
87
+ enable = st.checkbox("Enable camera")
88
+ picture = st.camera_input("Take a picture", disabled=not enable)
89
+ with col2:
90
+ if picture is not None:
91
+ with st.spinner("Analyzing face..."):
92
+ image_pil = Image.open(picture)
93
+ matches, image_bgr = prod_function(app, image_paths, image_pil)
 
 
 
 
 
 
 
 
 
94
 
95
+ if not matches:
96
+ st.warning("No face detected in the captured image.")
97
+ else:
98
+ # st.write("Similarity Scores:", prediction_scores)
99
+ for match in matches:
100
+ x1, y1, x2, y2 = match['bbox']
101
+ name = match['name']
102
+ color = (0, 255, 0) if name != "Unknown" else (0, 0, 255)
103
+ cv2.rectangle(image_bgr, (x1, y1), (x2, y2), color, 2)
104
+ cv2.putText(image_bgr, name, (x1, y2 + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2)
105
+
106
+ if name != "Unknown":
107
+ # recognized = False
108
+ # for score, idx in matches:
109
+ # if matched_score >= 0.6:
110
+ # matched_name = os.path.basename(image_paths[match_idx]).split('.')[0]
111
+ # st.success(f"βœ… Welcome: {matched_name}")
112
+ # recognizes=True
113
+
114
+ # Send attendance via POST
115
+ url = "https://nielit-attendance.glitch.me/adds"
116
+ data = {'rno': 15, 'sname': matched_name, 'sclass': 7}
117
+ try:
118
+ response = requests.post(url, data=data)
119
+ if response.status_code == 200:
120
+ st.success(f"Attendance marked successfully for {matched_name}.")
121
+ else:
122
+ st.warning(f"Failed to update attendance for {matched_name}.")
123
+ except Exception as e:
124
+ st.error(f"Request failed: {e}")
125
+ else:
126
+ st.warning("❌ Face match not found or too low confidence.")
127
+
128
+ # Convert back to RGB for display
129
+ image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
130
+ st.image(image_rgb, caption="Detected Faces", use_container_width=True)