-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'merge-code-mark-1' of https://github.com/devansh-shah-1…
…1/FaceRec into merge-code-mark-1
- Loading branch information
Showing
10 changed files
with
219 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Pylint | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pylint | ||
pip install -r requirements.txt | ||
- name: Analysing the code with pylint | ||
run: | | ||
pylint $(git ls-files '*.py') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Python application | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest pytest-cov | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest --cov . | ||
continue-on-error: true | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: devansh-shah-11/FaceRec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@Devasy23 | ||
@Devansh-shah-11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from fastapi import FastAPI, File, UploadFile | ||
from fastapi.responses import FileResponse | ||
import os | ||
from datetime import datetime | ||
from pymongo import MongoClient | ||
from random import randint | ||
import uuid | ||
from deepface import DeepFace | ||
from matplotlib import pyplot as plt | ||
|
||
IMAGEDIR = "test-faces/" | ||
|
||
mongodb_uri ='mongodb://localhost:27017/' | ||
port = 8000 | ||
client = MongoClient(mongodb_uri,port) | ||
|
||
db = client["ImageDB"] | ||
faceEntries = db["faceEntries"] | ||
|
||
app = FastAPI() | ||
|
||
# deprecated | ||
@app.post("/upload/") | ||
async def register_face(file: UploadFile = File(...)): | ||
|
||
file.filename = f"{uuid.uuid4()}.jpg" | ||
contents = await file.read() | ||
|
||
#save the file | ||
with open(f"{IMAGEDIR}{file.filename}", "wb") as f: | ||
f.write(contents) | ||
# db.images.insert_one({"filename": file.filename, "contents": contents}) | ||
return {"filename": file.filename} | ||
|
||
|
||
@app.post("/create_new_faceEntry") | ||
async def create_new_faceEntry(id:int, age: int, gender: str, image: UploadFile = File(...)): | ||
# Generate a unique ID | ||
# id = uuid.uuid4() | ||
|
||
# Get the current time | ||
time = datetime.now() | ||
|
||
# Read the image file | ||
image_data = await image.read() | ||
print(image.filename) | ||
# Save the original image in a specified directory | ||
with open(f"../Images/dbImages/{image.filename}", "wb") as f: | ||
f.write(image_data) | ||
|
||
# Extract the face from the image | ||
face_image_data = DeepFace.extract_faces(f"../Images/dbImages/{image.filename}", detector_backend="mtcnn") | ||
|
||
# Save the face image in a specified directory | ||
plt.imsave(f"../Images/Faces/{image.filename}", face_image_data[0]['face']) | ||
|
||
# Calculate the embeddings of the face image | ||
embeddings = DeepFace.represent(f"../Images/dbImages/{image.filename}", model_name="Facenet", detector_backend="mtcnn") | ||
|
||
# Store the data in the database | ||
db.faceEntries.insert_one({ | ||
"id": id, | ||
"age": age, | ||
"gender": gender, | ||
"time": time, | ||
"embeddings": embeddings, | ||
# "face-img": face_image_data, | ||
}) | ||
|
||
return {"message": "Face entry created successfully"} | ||
|
||
@app.get("/show/") | ||
async def read_random_file(): | ||
|
||
# get random file from the image directory | ||
files = os.listdir(IMAGEDIR) | ||
random_index = randint(0, len(files) - 1) | ||
|
||
path = f"{IMAGEDIR}{files[random_index]}" | ||
|
||
return FileResponse(path) | ||
|
||
@app.delete("/delete/{filename}") | ||
async def delete_file(filename: str): | ||
os.remove(f"{IMAGEDIR}/{filename}") | ||
return {"message": "Face deleted successfully"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters