diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6665a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lib +lib64 diff --git a/app.py b/app.py index c28b91d..927470c 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, request, jsonify +from flask import Flask, request, jsonify, render_template, send_from_directory, make_response from flask_cors import CORS import face_recognition import os @@ -23,7 +23,7 @@ if os.path.exists(STUDENT_ENCODINGS_FILE): else: student_encodings = {} -@app.route('/upload_images', methods=['POST']) +@app.route('/upload', methods=['POST']) def upload_images(): student_id = request.form.get('student_id') if 'images' not in request.files or not student_id: @@ -33,6 +33,7 @@ def upload_images(): encodings = [] for image in images: + image_path = os.path.join(STUDENT_IMAGES_DIR, f"{student_id}_{image.filename}") image.save(image_path) @@ -73,4 +74,4 @@ def recognize(): return jsonify({"error": "No face found in the uploaded image"}), 400 if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/app2.py b/app2.py new file mode 100644 index 0000000..d491081 --- /dev/null +++ b/app2.py @@ -0,0 +1,80 @@ +from flask import Flask, request, jsonify, render_template, send_from_directory, make_response +from flask_restful import Api, Resource +import os +import face_recognition +from werkzeug.utils import secure_filename +from PIL import Image +import numpy as np + +app = Flask(__name__) +api = Api(app) + +UPLOAD_FOLDER = 'upload' +if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER) + +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +# Helper function to save image +def save_image(image, roll_number): + roll_number_folder = os.path.join(app.config['UPLOAD_FOLDER'], roll_number) + if not os.path.exists(roll_number_folder): + os.makedirs(roll_number_folder) + image_count = len(os.listdir(roll_number_folder)) + 1 + image_path = os.path.join(roll_number_folder, f"{image_count}.jpg") + image.save(image_path) + return image_path + +# Helper function to load known faces +def load_known_faces(): + known_faces = [] + known_roll_numbers = [] + for roll_number in os.listdir(app.config['UPLOAD_FOLDER']): + roll_number_folder = os.path.join(app.config['UPLOAD_FOLDER'], roll_number) + for filename in os.listdir(roll_number_folder): + image_path = os.path.join(roll_number_folder, filename) + image = face_recognition.load_image_file(image_path) + encodings = face_recognition.face_encodings(image) + if encodings: + known_faces.append(encodings[0]) + known_roll_numbers.append(roll_number) + return known_faces, known_roll_numbers + +class UploadImage(Resource): + def post(self): + roll_number = request.form['roll_number'] + if 'image' not in request.files: + return jsonify({"error": "No image provided"}), 400 + image = request.files['image'] + filename = secure_filename(image.filename) + image = Image.open(image) + image_path = save_image(image, roll_number) + return jsonify({"message": f"Image saved as {image_path}"}), 200 + +class RecognizeStudent(Resource): + def post(self): + if 'image' not in request.files: + return jsonify({"error": "No image provided"}), 400 + image = request.files['image'] + filename = secure_filename(image.filename) + image = face_recognition.load_image_file(image) + unknown_encodings = face_recognition.face_encodings(image) + if not unknown_encodings: + return jsonify({"error": "No faces found in the image"}), 400 + unknown_encoding = unknown_encodings[0] + + known_faces, known_roll_numbers = load_known_faces() + results = face_recognition.compare_faces(known_faces, unknown_encoding) + + if True in results: + matched_index = results.index(True) + roll_number = known_roll_numbers[matched_index] + return jsonify({"roll_number": roll_number}), 200 + else: + return jsonify({"error": "No matching student found"}), 404 + +api.add_resource(UploadImage, '/upload') +api.add_resource(RecognizeStudent, '/recognize') + +if __name__ == '__main__': + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/app3.py b/app3.py new file mode 100644 index 0000000..93a0028 --- /dev/null +++ b/app3.py @@ -0,0 +1,84 @@ +from flask import Flask, request, jsonify, render_template, send_from_directory, make_response +from flask_restful import Api, Resource +import os +import face_recognition +from werkzeug.utils import secure_filename +from PIL import Image +import numpy as np + +app = Flask(__name__) +api = Api(app) + +UPLOAD_FOLDER = 'upload' +if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER) + +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +# Helper function to save image +def save_image(image, roll_number): + roll_number_folder = os.path.join(app.config['UPLOAD_FOLDER'], roll_number) + if not os.path.exists(roll_number_folder): + os.makedirs(roll_number_folder) + image_count = len(os.listdir(roll_number_folder)) + 1 + image_path = os.path.join(roll_number_folder, f"{image_count}.jpg") + image.save(image_path) + return image_path + +# Helper function to load known faces +def load_known_faces(): + known_faces = [] + known_roll_numbers = [] + for roll_number in os.listdir(app.config['UPLOAD_FOLDER']): + roll_number_folder = os.path.join(app.config['UPLOAD_FOLDER'], roll_number) + for filename in os.listdir(roll_number_folder): + image_path = os.path.join(roll_number_folder, filename) + image = face_recognition.load_image_file(image_path) + encodings = face_recognition.face_encodings(image) + if encodings: + known_faces.append(encodings[0]) + known_roll_numbers.append(roll_number) + return known_faces, known_roll_numbers + +@app.route('/') +def index(): + return render_template('./upload.html') + +class UploadImage(Resource): + def post(self): + roll_number = request.form['roll_number'] + if 'image' not in request.files: + return jsonify({"error": "No image provided"}), 400 + image = request.files['image'] + filename = secure_filename(image.filename) + image = Image.open(image) + image_path = save_image(image, roll_number) + return jsonify({"message": f"Image saved as {image_path}"}), 200 + +class RecognizeStudent(Resource): + def post(self): + if 'image' not in request.files: + return jsonify({"error": "No image provided"}), 400 + image = request.files['image'] + filename = secure_filename(image.filename) + image = face_recognition.load_image_file(image) + unknown_encodings = face_recognition.face_encodings(image) + if not unknown_encodings: + return jsonify({"error": "No faces found in the image"}), 400 + unknown_encoding = unknown_encodings[0] + + known_faces, known_roll_numbers = load_known_faces() + results = face_recognition.compare_faces(known_faces, unknown_encoding) + + if True in results: + matched_index = results.index(True) + roll_number = known_roll_numbers[matched_index] + return jsonify({"roll_number": roll_number}), 200 + else: + return jsonify({"error": "No matching student found"}), 404 + +api.add_resource(UploadImage, '/upload') +api.add_resource(RecognizeStudent, '/recognize') + +if __name__ == '__main__': + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/app4.py b/app4.py new file mode 100644 index 0000000..164e767 --- /dev/null +++ b/app4.py @@ -0,0 +1,93 @@ +import os +from flask import Flask, request, jsonify +import face_recognition +import pickle +from PIL import Image +import numpy as np + +app = Flask(__name__) + +UPLOAD_FOLDER = 'student_roll/uploads/' +FACE_DATA_FOLDER = 'student_roll/face_data/' + +os.makedirs(UPLOAD_FOLDER, exist_ok=True) +os.makedirs(FACE_DATA_FOLDER, exist_ok=True) + +def convert_image_to_8bit_rgb(image_path): + with Image.open(image_path) as img: + if img.mode != 'RGB': + img = img.convert('RGB') + img = img.convert('RGB') # Ensure conversion to 8-bit per channel + img_array = np.array(img) + return img_array + +@app.route('/upload', methods=['POST']) +def upload_image(): + if 'image' not in request.files: + return jsonify({"error": "No image part in the request"}), 400 + + file = request.files['image'] + if file.filename == '': + return jsonify({"error": "No selected file"}), 400 + + student_roll = request.form.get('student_roll') + if not student_roll: + return jsonify({"error": "Student roll number is required"}), 400 + + file_path = os.path.join(UPLOAD_FOLDER, f"{student_roll}.jpg") + file.save(file_path) + + try: + # Convert image to 8-bit RGB if necessary + image = convert_image_to_8bit_rgb(file_path) + face_encodings = face_recognition.face_encodings(image) + + if not face_encodings: + return jsonify({"error": "No face found in the image"}), 400 + + face_data_path = os.path.join(FACE_DATA_FOLDER, f"{student_roll}.pkl") + with open(face_data_path, 'wb') as f: + pickle.dump(face_encodings[0], f) + + return jsonify({"message": "Image and face data uploaded successfully"}), 200 + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route('/recognize_student', methods=['POST']) +def recognize_student(): + if 'image' not in request.files: + return jsonify({"error": "No image part in the request"}), 400 + + file = request.files['image'] + if file.filename == '': + return jsonify({"error": "No selected file"}), 400 + + file_path = os.path.join(UPLOAD_FOLDER, "temp.jpg") + file.save(file_path) + + try: + # Convert image to 8-bit RGB if necessary + image = convert_image_to_8bit_rgb(file_path) + face_encodings = face_recognition.face_encodings(image) + + if not face_encodings: + return jsonify({"error": "No face found in the image"}), 400 + + uploaded_face_encoding = face_encodings[0] + + # Load all stored face data + for face_data_file in os.listdir(FACE_DATA_FOLDER): + with open(os.path.join(FACE_DATA_FOLDER, face_data_file), 'rb') as f: + known_face_encoding = pickle.load(f) + matches = face_recognition.compare_faces([known_face_encoding], uploaded_face_encoding) + + if matches[0]: + student_roll = os.path.splitext(face_data_file)[0] + return jsonify({"student_roll": student_roll}), 200 + + return jsonify({"error": "No matching student found"}), 404 + except Exception as e: + return jsonify({"error": str(e)}), 500 + +if __name__ == '__main__': + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/app5.py b/app5.py new file mode 100644 index 0000000..1916ab2 --- /dev/null +++ b/app5.py @@ -0,0 +1,81 @@ +from flask import Flask, request, jsonify +import os +import face_recognition +import pickle +from werkzeug.utils import secure_filename + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = 'uploads/' +app.config['STUDENT_DATA_FILE'] = 'students_data.pkl' + +if not os.path.exists(app.config['UPLOAD_FOLDER']): + os.makedirs(app.config['UPLOAD_FOLDER']) + +# Load or initialize student data +if os.path.exists(app.config['STUDENT_DATA_FILE']): + with open(app.config['STUDENT_DATA_FILE'], 'rb') as f: + students_db = pickle.load(f) +else: + students_db = {} + +def save_student_data(): + with open(app.config['STUDENT_DATA_FILE'], 'wb') as f: + pickle.dump(students_db, f) + +@app.route('/upload', methods=['POST']) +def upload_image(): + if 'image' not in request.files or 'student_id' not in request.form: + return jsonify({'error': 'Image or student_id not provided'}), 400 + + image = request.files['image'] + student_id = request.form['student_id'] + filename = secure_filename(f"{student_id}_{image.filename}") + filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) + image.save(filepath) + + # Load the image file into a numpy array + image = face_recognition.load_image_file(filepath) + # Get the face encoding for the image + face_encodings = face_recognition.face_encodings(image) + + if len(face_encodings) > 0: + # Assuming the first face found in the image is the correct one + students_db[student_id] = face_encodings[0] + save_student_data() + return jsonify({'message': 'Image uploaded and student registered successfully', 'student_id': student_id}), 200 + else: + return jsonify({'error': 'No faces found in the image'}), 400 + +@app.route('/recognize_image', methods=['POST']) +def recognize_image(): + if 'image' not in request.files: + return jsonify({'error': 'Image not provided'}), 400 + + image = request.files['image'] + # Load the uploaded image file into a numpy array + unknown_image = face_recognition.load_image_file(image) + # Get the face encodings for the uploaded image + unknown_encodings = face_recognition.face_encodings(unknown_image) + + if len(unknown_encodings) > 0: + unknown_encoding = unknown_encodings[0] + best_match_id = None + best_match_score = None + + for student_id, known_encoding in students_db.items(): + # Calculate the distance between the known encoding and the uploaded image encoding + distance = face_recognition.face_distance([known_encoding], unknown_encoding)[0] + # Convert distance to accuracy score (the closer the distance, the higher the accuracy) + accuracy_score = (1 - distance) * 100 + + if best_match_score is None or accuracy_score > best_match_score: + best_match_id = student_id + best_match_score = accuracy_score + + if best_match_id: + return jsonify({'student_id': best_match_id, 'accuracy_score': best_match_score}), 200 + + return jsonify({'error': 'Student not recognized'}), 404 + +if __name__ == '__main__': + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/app6.py b/app6.py new file mode 100644 index 0000000..c844647 --- /dev/null +++ b/app6.py @@ -0,0 +1,86 @@ +from flask import Flask, request, jsonify +import os +import face_recognition +import pickle +from werkzeug.utils import secure_filename +from time import time + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = 'uploads/' +app.config['STUDENT_DATA_FILE'] = 'students_data.pkl' + +if not os.path.exists(app.config['UPLOAD_FOLDER']): + os.makedirs(app.config['UPLOAD_FOLDER']) + +# Load or initialize student data +if os.path.exists(app.config['STUDENT_DATA_FILE']): + with open(app.config['STUDENT_DATA_FILE'], 'rb') as f: + students_db = pickle.load(f) +else: + students_db = {} + +def save_student_data(): + with open(app.config['STUDENT_DATA_FILE'], 'wb') as f: + pickle.dump(students_db, f) + +@app.route('/upl', methods=['POST']) +def upload_image(): + if 'face' not in request.files or 'student_id' not in request.form: + return jsonify({'error': 'Image or student_id not provided'}), 400 + + image = request.files['face'] + student_id = request.form['student_id'] + timestamp = int(time()) + filename = secure_filename(f"{timestamp}.jpg") + student_folder = os.path.join(app.config['UPLOAD_FOLDER'], student_id) + if not os.path.exists(student_folder): + os.makedirs(student_folder) + filepath = os.path.join(student_folder, filename) + image.save(filepath) + + # Load the image file into a numpy array + image_array = face_recognition.load_image_file(filepath) + # Get the face encoding for the image + face_encodings = face_recognition.face_encodings(image_array) + + if len(face_encodings) > 0: + # Assuming the first face found in the image is the correct one + students_db[student_id] = face_encodings[0] + save_student_data() + return jsonify({'message': 'Image uploaded and student registered successfully', 'student_id': student_id}), 200 + else: + return jsonify({'error': 'No faces found in the image'}), 400 + +@app.route('/rec', methods=['POST']) +def recognize_image(): + if 'image' not in request.files: + return jsonify({'error': 'Image not provided'}), 400 + + image = request.files['image'] + # Load the uploaded image file into a numpy array + unknown_image = face_recognition.load_image_file(image) + # Get the face encodings for the uploaded image + unknown_encodings = face_recognition.face_encodings(unknown_image) + + if len(unknown_encodings) > 0: + unknown_encoding = unknown_encodings[0] + best_match_id = None + best_match_score = None + + for student_id, known_encoding in students_db.items(): + # Calculate the distance between the known encoding and the uploaded image encoding + distance = face_recognition.face_distance([known_encoding], unknown_encoding)[0] + # Convert distance to accuracy score (the closer the distance, the higher the accuracy) + accuracy_score = (1 - distance) * 100 + + if best_match_score is None or accuracy_score > best_match_score: + best_match_id = student_id + best_match_score = accuracy_score + + if best_match_id: + return jsonify({'student_id': best_match_id, 'accuracy_score': best_match_score}), 200 + + return jsonify({'error': 'Student not recognized'}), 404 + +if __name__ == '__main__': + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/bin/Activate.ps1 b/bin/Activate.ps1 new file mode 100644 index 0000000..b49d77b --- /dev/null +++ b/bin/Activate.ps1 @@ -0,0 +1,247 @@ +<# +.Synopsis +Activate a Python virtual environment for the current PowerShell session. + +.Description +Pushes the python executable for a virtual environment to the front of the +$Env:PATH environment variable and sets the prompt to signify that you are +in a Python virtual environment. Makes use of the command line switches as +well as the `pyvenv.cfg` file values present in the virtual environment. + +.Parameter VenvDir +Path to the directory that contains the virtual environment to activate. The +default value for this is the parent of the directory that the Activate.ps1 +script is located within. + +.Parameter Prompt +The prompt prefix to display when this virtual environment is activated. By +default, this prompt is the name of the virtual environment folder (VenvDir) +surrounded by parentheses and followed by a single space (ie. '(.venv) '). + +.Example +Activate.ps1 +Activates the Python virtual environment that contains the Activate.ps1 script. + +.Example +Activate.ps1 -Verbose +Activates the Python virtual environment that contains the Activate.ps1 script, +and shows extra information about the activation as it executes. + +.Example +Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv +Activates the Python virtual environment located in the specified location. + +.Example +Activate.ps1 -Prompt "MyPython" +Activates the Python virtual environment that contains the Activate.ps1 script, +and prefixes the current prompt with the specified string (surrounded in +parentheses) while the virtual environment is active. + +.Notes +On Windows, it may be required to enable this Activate.ps1 script by setting the +execution policy for the user. You can do this by issuing the following PowerShell +command: + +PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser + +For more information on Execution Policies: +https://go.microsoft.com/fwlink/?LinkID=135170 + +#> +Param( + [Parameter(Mandatory = $false)] + [String] + $VenvDir, + [Parameter(Mandatory = $false)] + [String] + $Prompt +) + +<# Function declarations --------------------------------------------------- #> + +<# +.Synopsis +Remove all shell session elements added by the Activate script, including the +addition of the virtual environment's Python executable from the beginning of +the PATH variable. + +.Parameter NonDestructive +If present, do not remove this function from the global namespace for the +session. + +#> +function global:deactivate ([switch]$NonDestructive) { + # Revert to original values + + # The prior prompt: + if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { + Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt + Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT + } + + # The prior PYTHONHOME: + if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { + Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME + Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME + } + + # The prior PATH: + if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { + Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH + Remove-Item -Path Env:_OLD_VIRTUAL_PATH + } + + # Just remove the VIRTUAL_ENV altogether: + if (Test-Path -Path Env:VIRTUAL_ENV) { + Remove-Item -Path env:VIRTUAL_ENV + } + + # Just remove VIRTUAL_ENV_PROMPT altogether. + if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) { + Remove-Item -Path env:VIRTUAL_ENV_PROMPT + } + + # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: + if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { + Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force + } + + # Leave deactivate function in the global namespace if requested: + if (-not $NonDestructive) { + Remove-Item -Path function:deactivate + } +} + +<# +.Description +Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the +given folder, and returns them in a map. + +For each line in the pyvenv.cfg file, if that line can be parsed into exactly +two strings separated by `=` (with any amount of whitespace surrounding the =) +then it is considered a `key = value` line. The left hand string is the key, +the right hand is the value. + +If the value starts with a `'` or a `"` then the first and last character is +stripped from the value before being captured. + +.Parameter ConfigDir +Path to the directory that contains the `pyvenv.cfg` file. +#> +function Get-PyVenvConfig( + [String] + $ConfigDir +) { + Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" + + # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). + $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue + + # An empty map will be returned if no config file is found. + $pyvenvConfig = @{ } + + if ($pyvenvConfigPath) { + + Write-Verbose "File exists, parse `key = value` lines" + $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath + + $pyvenvConfigContent | ForEach-Object { + $keyval = $PSItem -split "\s*=\s*", 2 + if ($keyval[0] -and $keyval[1]) { + $val = $keyval[1] + + # Remove extraneous quotations around a string value. + if ("'""".Contains($val.Substring(0, 1))) { + $val = $val.Substring(1, $val.Length - 2) + } + + $pyvenvConfig[$keyval[0]] = $val + Write-Verbose "Adding Key: '$($keyval[0])'='$val'" + } + } + } + return $pyvenvConfig +} + + +<# Begin Activate script --------------------------------------------------- #> + +# Determine the containing directory of this script +$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition +$VenvExecDir = Get-Item -Path $VenvExecPath + +Write-Verbose "Activation script is located in path: '$VenvExecPath'" +Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" +Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" + +# Set values required in priority: CmdLine, ConfigFile, Default +# First, get the location of the virtual environment, it might not be +# VenvExecDir if specified on the command line. +if ($VenvDir) { + Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" +} +else { + Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." + $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") + Write-Verbose "VenvDir=$VenvDir" +} + +# Next, read the `pyvenv.cfg` file to determine any required value such +# as `prompt`. +$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir + +# Next, set the prompt from the command line, or the config file, or +# just use the name of the virtual environment folder. +if ($Prompt) { + Write-Verbose "Prompt specified as argument, using '$Prompt'" +} +else { + Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" + if ($pyvenvCfg -and $pyvenvCfg['prompt']) { + Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" + $Prompt = $pyvenvCfg['prompt']; + } + else { + Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)" + Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" + $Prompt = Split-Path -Path $venvDir -Leaf + } +} + +Write-Verbose "Prompt = '$Prompt'" +Write-Verbose "VenvDir='$VenvDir'" + +# Deactivate any currently active virtual environment, but leave the +# deactivate function in place. +deactivate -nondestructive + +# Now set the environment variable VIRTUAL_ENV, used by many tools to determine +# that there is an activated venv. +$env:VIRTUAL_ENV = $VenvDir + +if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { + + Write-Verbose "Setting prompt to '$Prompt'" + + # Set the prompt to include the env name + # Make sure _OLD_VIRTUAL_PROMPT is global + function global:_OLD_VIRTUAL_PROMPT { "" } + Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT + New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt + + function global:prompt { + Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " + _OLD_VIRTUAL_PROMPT + } + $env:VIRTUAL_ENV_PROMPT = $Prompt +} + +# Clear PYTHONHOME +if (Test-Path -Path Env:PYTHONHOME) { + Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME + Remove-Item -Path Env:PYTHONHOME +} + +# Add the venv to the PATH +Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH +$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" diff --git a/bin/activate b/bin/activate new file mode 100755 index 0000000..f26bdfb --- /dev/null +++ b/bin/activate @@ -0,0 +1,69 @@ +# This file must be used with "source bin/activate" *from bash* +# you cannot run it directly + +deactivate () { + # reset old environment variables + if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then + PATH="${_OLD_VIRTUAL_PATH:-}" + export PATH + unset _OLD_VIRTUAL_PATH + fi + if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then + PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" + export PYTHONHOME + unset _OLD_VIRTUAL_PYTHONHOME + fi + + # This should detect bash and zsh, which have a hash command that must + # be called to get it to forget past commands. Without forgetting + # past commands the $PATH changes we made may not be respected + if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then + hash -r 2> /dev/null + fi + + if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then + PS1="${_OLD_VIRTUAL_PS1:-}" + export PS1 + unset _OLD_VIRTUAL_PS1 + fi + + unset VIRTUAL_ENV + unset VIRTUAL_ENV_PROMPT + if [ ! "${1:-}" = "nondestructive" ] ; then + # Self destruct! + unset -f deactivate + fi +} + +# unset irrelevant variables +deactivate nondestructive + +VIRTUAL_ENV="/data/p/p/kar/python_attendance_image" +export VIRTUAL_ENV + +_OLD_VIRTUAL_PATH="$PATH" +PATH="$VIRTUAL_ENV/bin:$PATH" +export PATH + +# unset PYTHONHOME if set +# this will fail if PYTHONHOME is set to the empty string (which is bad anyway) +# could use `if (set -u; : $PYTHONHOME) ;` in bash +if [ -n "${PYTHONHOME:-}" ] ; then + _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" + unset PYTHONHOME +fi + +if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then + _OLD_VIRTUAL_PS1="${PS1:-}" + PS1="(python_attendance_image) ${PS1:-}" + export PS1 + VIRTUAL_ENV_PROMPT="(python_attendance_image) " + export VIRTUAL_ENV_PROMPT +fi + +# This should detect bash and zsh, which have a hash command that must +# be called to get it to forget past commands. Without forgetting +# past commands the $PATH changes we made may not be respected +if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then + hash -r 2> /dev/null +fi diff --git a/bin/activate.csh b/bin/activate.csh new file mode 100755 index 0000000..d6c792c --- /dev/null +++ b/bin/activate.csh @@ -0,0 +1,26 @@ +# This file must be used with "source bin/activate.csh" *from csh*. +# You cannot run it directly. +# Created by Davide Di Blasi . +# Ported to Python 3.3 venv by Andrew Svetlov + +alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate' + +# Unset irrelevant variables. +deactivate nondestructive + +setenv VIRTUAL_ENV "/data/p/p/kar/python_attendance_image" + +set _OLD_VIRTUAL_PATH="$PATH" +setenv PATH "$VIRTUAL_ENV/bin:$PATH" + + +set _OLD_VIRTUAL_PROMPT="$prompt" + +if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then + set prompt = "(python_attendance_image) $prompt" + setenv VIRTUAL_ENV_PROMPT "(python_attendance_image) " +endif + +alias pydoc python -m pydoc + +rehash diff --git a/bin/activate.fish b/bin/activate.fish new file mode 100644 index 0000000..4b0c99d --- /dev/null +++ b/bin/activate.fish @@ -0,0 +1,69 @@ +# This file must be used with "source /bin/activate.fish" *from fish* +# (https://fishshell.com/); you cannot run it directly. + +function deactivate -d "Exit virtual environment and return to normal shell environment" + # reset old environment variables + if test -n "$_OLD_VIRTUAL_PATH" + set -gx PATH $_OLD_VIRTUAL_PATH + set -e _OLD_VIRTUAL_PATH + end + if test -n "$_OLD_VIRTUAL_PYTHONHOME" + set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME + set -e _OLD_VIRTUAL_PYTHONHOME + end + + if test -n "$_OLD_FISH_PROMPT_OVERRIDE" + set -e _OLD_FISH_PROMPT_OVERRIDE + # prevents error when using nested fish instances (Issue #93858) + if functions -q _old_fish_prompt + functions -e fish_prompt + functions -c _old_fish_prompt fish_prompt + functions -e _old_fish_prompt + end + end + + set -e VIRTUAL_ENV + set -e VIRTUAL_ENV_PROMPT + if test "$argv[1]" != "nondestructive" + # Self-destruct! + functions -e deactivate + end +end + +# Unset irrelevant variables. +deactivate nondestructive + +set -gx VIRTUAL_ENV "/data/p/p/kar/python_attendance_image" + +set -gx _OLD_VIRTUAL_PATH $PATH +set -gx PATH "$VIRTUAL_ENV/bin" $PATH + +# Unset PYTHONHOME if set. +if set -q PYTHONHOME + set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME + set -e PYTHONHOME +end + +if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" + # fish uses a function instead of an env var to generate the prompt. + + # Save the current fish_prompt function as the function _old_fish_prompt. + functions -c fish_prompt _old_fish_prompt + + # With the original prompt function renamed, we can override with our own. + function fish_prompt + # Save the return status of the last command. + set -l old_status $status + + # Output the venv prompt; color taken from the blue of the Python logo. + printf "%s%s%s" (set_color 4B8BBE) "(python_attendance_image) " (set_color normal) + + # Restore the return status of the previous command. + echo "exit $old_status" | . + # Output the original/"old" prompt. + _old_fish_prompt + end + + set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" + set -gx VIRTUAL_ENV_PROMPT "(python_attendance_image) " +end diff --git a/bin/f2py b/bin/f2py new file mode 100755 index 0000000..4bdddc3 --- /dev/null +++ b/bin/f2py @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from numpy.f2py.f2py2e import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/face_detection b/bin/face_detection new file mode 100755 index 0000000..961f3c0 --- /dev/null +++ b/bin/face_detection @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from face_recognition.face_detection_cli import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/face_recognition b/bin/face_recognition new file mode 100755 index 0000000..bb7c28e --- /dev/null +++ b/bin/face_recognition @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from face_recognition.face_recognition_cli import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/flask b/bin/flask new file mode 100755 index 0000000..573c687 --- /dev/null +++ b/bin/flask @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from flask.cli import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/pip b/bin/pip new file mode 100755 index 0000000..200f5d6 --- /dev/null +++ b/bin/pip @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/pip3 b/bin/pip3 new file mode 100755 index 0000000..200f5d6 --- /dev/null +++ b/bin/pip3 @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/pip3.10 b/bin/pip3.10 new file mode 100755 index 0000000..200f5d6 --- /dev/null +++ b/bin/pip3.10 @@ -0,0 +1,8 @@ +#!/data/p/p/kar/python_attendance_image/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/bin/python b/bin/python new file mode 120000 index 0000000..acd4152 --- /dev/null +++ b/bin/python @@ -0,0 +1 @@ +/usr/bin/python \ No newline at end of file diff --git a/bin/python3 b/bin/python3 new file mode 120000 index 0000000..d8654aa --- /dev/null +++ b/bin/python3 @@ -0,0 +1 @@ +python \ No newline at end of file diff --git a/bin/python3.10 b/bin/python3.10 new file mode 120000 index 0000000..d8654aa --- /dev/null +++ b/bin/python3.10 @@ -0,0 +1 @@ +python \ No newline at end of file diff --git a/pyvenv.cfg b/pyvenv.cfg new file mode 100644 index 0000000..0537ffc --- /dev/null +++ b/pyvenv.cfg @@ -0,0 +1,3 @@ +home = /usr/bin +include-system-site-packages = false +version = 3.10.12 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..56014ac --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +flask-3.0.3 +Flask_Cors-4.0.1 +face_recognition-1.3.0 +numpy-1.26.4 +pickle5 diff --git a/student_encodings.pkl b/student_encodings.pkl new file mode 100644 index 0000000..cbc3e9b Binary files /dev/null and b/student_encodings.pkl differ diff --git a/students_data.pkl b/students_data.pkl new file mode 100644 index 0000000..a79aaf9 Binary files /dev/null and b/students_data.pkl differ diff --git a/templates/upload.html b/templates/upload.html new file mode 100644 index 0000000..f4b207c --- /dev/null +++ b/templates/upload.html @@ -0,0 +1,18 @@ + + + + Upload Student Image + + +

Upload Student Image

+
+ + +

+ + +

+ +
+ + diff --git a/upload.py b/upload.py new file mode 100644 index 0000000..f0893b8 --- /dev/null +++ b/upload.py @@ -0,0 +1,29 @@ +from flask import Flask, render_template, request, jsonify, make_response +import os + +app = Flask(__name__) +UPLOAD_FOLDER = 'uploads' +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +@app.route('/') +def upload_form(): + return render_template('upload.html') + +@app.route('/upload', methods=['POST']) +def upload_file(): + folder_number = request.form['roll_number'] + images = request.files.getlist('images[]') + + folder_path = os.path.join(app.config['UPLOAD_FOLDER'], folder_number) + os.makedirs(folder_path, exist_ok=True) + + for image in images: + if image.filename == '': + continue + filename = image.filename + image.save(os.path.join(folder_path, filename)) + + return make_response(jsonify('success'), 200) + +if __name__ == '__main__': + app.run(debug=True, host="0.0.0.0", port=5005) diff --git a/uploads/1111111111/1719166994.jpg b/uploads/1111111111/1719166994.jpg new file mode 100644 index 0000000..62b06df Binary files /dev/null and b/uploads/1111111111/1719166994.jpg differ diff --git a/uploads/3333/1719166349.jpg b/uploads/3333/1719166349.jpg new file mode 100644 index 0000000..9b8db7c Binary files /dev/null and b/uploads/3333/1719166349.jpg differ