Skip to content

Commit

Permalink
Add pre-commit hooks and update requirements.txt (Devasy23#32)
Browse files Browse the repository at this point in the history
* Add pre-commit hooks and update requirements.txt

* Exclude testing directory from flake8 hook

* Fix formatting issues and update dependencies

* Add wily hook to pre-commit configuration

* fix(.pre-commit-config.yaml): Add commitizen hook to pre-commit config

* Updated Requirements

* Added input sanitation

* Converted logging.info() to logging.debug()

* Removed tensorflow-intel==2.15.0

---------

Co-authored-by: Devansh Shah <[email protected]>
  • Loading branch information
Devasy23 and devansh-shah-11 authored Jun 4, 2024
1 parent 7acd5af commit e222588
Show file tree
Hide file tree
Showing 32 changed files with 568 additions and 425 deletions.
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [ ] Info
- [ ] Bug
- [ ] Documentation
- [ ] Other (please specify):
- [ ] Other (please specify):

## Description
<!-- Describe the issue in detail. What problem are you experiencing or what feature would you like to see added? -->
Expand All @@ -23,18 +23,18 @@

## Steps to Reproduce
<!-- If applicable, provide a step-by-step guide to reproducing the issue -->
1.
2.
3.
1.
2.
3.

## Screenshots / Code Snippets (if applicable)
<!-- Include any relevant screenshots or code snippets that can help understand the issue better -->

## Environment
<!-- Provide details about your environment -->
- Operating System:
- Browser (if applicable):
- Version/Commit ID (if applicable):
- Operating System:
- Browser (if applicable):
- Version/Commit ID (if applicable):

## Possible Solution (if you have any in mind)
<!-- If you have an idea about how to fix the issue, please share it here -->
Expand Down
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ labels: ''
assignees: ''

---


2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Please describe the tests that you ran to verify your changes. Provide instructi
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
- [ ] Any dependent changes have been merged and published in downstream modules
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ cython_debug/
venv/
*.pyc
.vscode/
__pyc
__pyc
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: double-quote-string-fixer
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [--py38-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/hhatto/autopep8
rev: v2.1.0
hooks:
- id: autopep8
# - repo: https://github.com/PyCQA/flake8
# rev: 7.0.0
# hooks:
# - id: flake8
# exclude: testing/
# - repo: local
# hooks:
# - id: wily
# name: wily
# entry: wily diff
# verbose: true
# language: python
# additional_dependencies: [wily]

- repo: https://github.com/commitizen-tools/commitizen
rev: master
hooks:
- id: commitizen
stages: [commit-msg]
17 changes: 17 additions & 0 deletions .pre-commit-security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0
hooks:
- id: bandit
files: \.py$ # Run Bandit only on Python files
additional_dependencies: [toml] # Additional dependencies required by Bandit
args: [--skip, B101] # Skip Bandit test B101 (assert statements)
- repo: https://github.com/safepass-dev/safepass-pre-commit
rev: v0.1.0
hooks:
- id: safepass
files: \.(py|yaml|yml|json)$ # Run Safepass on Python, YAML, and JSON files
- repo: https://github.com/pyupio/safety-hooks
rev: v2.0.3
hooks:
- id: safety
8 changes: 5 additions & 3 deletions API/_init_.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import uvicorn
from fastapi import FastAPI

Expand All @@ -8,11 +10,11 @@
Fastapp.include_router(route.router)


@Fastapp.get("/")
@Fastapp.get('/')
def read_root():
return {"Hello": "FASTAPI"}
return {'Hello': 'FASTAPI'}


# function to run server of FastAPI
def run_fastapi_app():
uvicorn.run(Fastapp, host="127.0.0.1", port=8000)
uvicorn.run(Fastapp, host='127.0.0.1', port=8000)
32 changes: 17 additions & 15 deletions API/database.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from datetime import datetime

from pymongo import MongoClient


class Database:
def __init__(self, uri="mongodb://localhost:27017/", db_name="ImageDB"):
def __init__(self, uri='mongodb://localhost:27017/', db_name='ImageDB'):
self.client = MongoClient(uri)
self.db = self.client[db_name]

Expand All @@ -29,23 +31,23 @@ def vector_search(self, collection, embedding):
result = self.db[collection].aggregate(
[
{
"$vectorSearch": {
"index": "vector_index",
"path": "face_embedding",
"queryVector": embedding,
"numCandidates": 20,
"limit": 20,
}
'$vectorSearch': {
'index': 'vector_index',
'path': 'face_embedding',
'queryVector': embedding,
'numCandidates': 20,
'limit': 20,
},
},
{
"$project": {
"_id": 0,
"Name": 1,
"Image": 1,
"score": {"$meta": "vectorSearchScore"},
}
'$project': {
'_id': 0,
'Name': 1,
'Image': 1,
'score': {'$meta': 'vectorSearchScore'},
},
},
]
],
)
result_arr = [i for i in result]
return result_arr
Loading

0 comments on commit e222588

Please sign in to comment.