nikshep01 commited on
Commit
784a4d1
·
verified ·
1 Parent(s): 212d983

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -6,6 +6,8 @@ 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')
@@ -44,6 +46,43 @@ def add_attendance(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)
49
 
@@ -84,7 +123,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
+ from huggingface_hub import Repository
10
+ import pandas as pd
11
 
12
  # Establish connection to SQLite database
13
  conn = sqlite3.connect('attendance.db')
 
46
  c.execute("INSERT INTO attendance (name, time) VALUES (?, ?)", (username, current_datetime))
47
  conn.commit()
48
 
49
+ def addAttendance(name):
50
+ directory_name = "my_directory"
51
+
52
+ # Check if the repository exists, if not, create it
53
+ if not Repository.exists(directory_name):
54
+ repo = Repository.create(directory_name)
55
+ print(f"Repository '{directory_name}' created successfully!")
56
+ else:
57
+ repo = Repository()
58
+
59
+ # Create the directory
60
+ repo.create_directory(directory_name)
61
+
62
+ # Define recognized results (example)
63
+ recognized_results = [
64
+ {"Name": "{name}", "Status": "Present"},
65
+ {"Name": "Alice", "Status": "Absent"},
66
+ {"Name": "Bob", "Status": "Present"}
67
+ ]
68
+
69
+ # Convert recognized results to DataFrame
70
+ df = pd.DataFrame(recognized_results)
71
+
72
+ # Define the path to save the Excel file
73
+ excel_file_path = "recognized_results.xlsx"
74
+
75
+ # Save DataFrame to Excel file
76
+ df.to_excel(excel_file_path, index=False)
77
+
78
+ # Define the destination path within the directory
79
+ destination_path = os.path.join(directory_name, excel_file_path)
80
+
81
+ # Move the Excel file to the destination path
82
+ os.system(f"mv {excel_file_path} {destination_path}")
83
+
84
+ print(f"Excel file '{excel_file_path}' added to directory '{directory_name}' successfully!")
85
+
86
  if file_name is not None:
87
  col1, col2 = st.columns(2)
88
 
 
123
  cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
124
 
125
  # Store attendance in SQLite database
126
+ addAttendance(name)
127
 
128
  # Display the image with recognized faces
129
  st.image(image, use_column_width=True, output_format="PNG")