Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def save_hash(enrollment, img_hash):
|
|
| 27 |
|
| 28 |
# Create a consistent hash from image
|
| 29 |
def image_hash(image):
|
| 30 |
-
image = image.resize((100, 100)).convert("L")
|
| 31 |
return hashlib.md5(image.tobytes()).hexdigest()
|
| 32 |
|
| 33 |
# Main registration logic
|
|
@@ -46,17 +46,15 @@ def register_student(image, enrollment, name):
|
|
| 46 |
# Load existing image hashes
|
| 47 |
existing_hashes = load_hashes()
|
| 48 |
|
| 49 |
-
# Check if the same image
|
| 50 |
-
if new_hash in existing_hashes.values():
|
| 51 |
-
return "This image is already registered with another Enrollment ID!"
|
| 52 |
-
|
| 53 |
-
# Check if enrollment ID already exists with a different image
|
| 54 |
if enrollment in existing_hashes:
|
| 55 |
existing_hash = existing_hashes[enrollment]
|
| 56 |
-
if new_hash
|
|
|
|
|
|
|
| 57 |
return f"Enrollment ID {enrollment} is already used with a different image!"
|
| 58 |
|
| 59 |
-
#
|
| 60 |
image_path = os.path.join(trainimage_path, f"User.{enrollment}.jpg")
|
| 61 |
image.save(image_path)
|
| 62 |
save_hash(enrollment, new_hash)
|
|
|
|
| 27 |
|
| 28 |
# Create a consistent hash from image
|
| 29 |
def image_hash(image):
|
| 30 |
+
image = image.resize((100, 100)).convert("L") # Resize for consistency
|
| 31 |
return hashlib.md5(image.tobytes()).hexdigest()
|
| 32 |
|
| 33 |
# Main registration logic
|
|
|
|
| 46 |
# Load existing image hashes
|
| 47 |
existing_hashes = load_hashes()
|
| 48 |
|
| 49 |
+
# Check if the same image is already registered with the same ID
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
if enrollment in existing_hashes:
|
| 51 |
existing_hash = existing_hashes[enrollment]
|
| 52 |
+
if new_hash == existing_hash:
|
| 53 |
+
return f"Image already registered with the same image and Enrollment ID {enrollment}."
|
| 54 |
+
else:
|
| 55 |
return f"Enrollment ID {enrollment} is already used with a different image!"
|
| 56 |
|
| 57 |
+
# If new enrollment, save image and record hash
|
| 58 |
image_path = os.path.join(trainimage_path, f"User.{enrollment}.jpg")
|
| 59 |
image.save(image_path)
|
| 60 |
save_hash(enrollment, new_hash)
|