-
Notifications
You must be signed in to change notification settings - Fork 582
[Feat] Implemented the search feature by uploading a image -2nd PR #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
972d5f0
Implemented face search feature on backend
tushar1977 cae7573
Fixed response model and implemented some api in frontend
tushar1977 dc14551
Added placeholder image for search bar
tushar1977 9e6168d
Added a constant for similarity
tushar1977 1b798ea
Added searchImage redux
tushar1977 9e329c1
Implemented search option to search for specific face
tushar1977 a1e1225
Refractored the code
tushar1977 5ae56bd
Changed the id generation and type
tushar1977 5b49d7e
Fixed
tushar1977 db33982
f
tushar1977 fda2f41
Fixed all changes suggested by AI after reviewing
tushar1977 d576323
Improved the search bar
tushar1977 24bb3af
Merge remote-tracking branch 'upstream/main'
tushar1977 51f5842
Fixed import statements
tushar1977 a6705ef
fix
tushar1977 4d5eb5d
Fixed the requirements acc to recent PR
tushar1977 a81cbac
removed files
tushar1977 596372e
Revert "removed files"
tushar1977 14dac00
Deleted env
tushar1977 664e267
Fixed linting in selectFile
tushar1977 359f487
Delete .github/workflows/update-project-structure.yml
rahulharpal1603 eb3ae12
Fixed navigation to home
tushar1977 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -36,8 +36,3 @@ body: | |
| required: true | ||
| - label: "Do Your changes passes all tests?" | ||
| required: false | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -36,4 +36,3 @@ body: | |
| required: true | ||
| - label: "Does it contain any style related issues?" | ||
| required: false | ||
|
|
||
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embeddings aggregation bug: only first face per image kept; duplicates possible due to tag joins; bbox/JSON None handling.
face_idyou’ll append duplicates if you start aggregating.json.loads(bbox)will raise on NULL (TypeError), not caught.bbox(singular) whereas frontend types expectbboxes?: [...].Apply this refactor to correctly aggregate and dedupe faces per image and handle NULLs:
def get_all_face_embeddings(): conn = sqlite3.connect(DATABASE_PATH) cursor = conn.cursor() try: - cursor.execute(""" - SELECT - f.embeddings, - f.bbox, - i.id, - i.path, - i.folder_id, - i.thumbnailPath, - i.metadata, - i.isTagged, - m.name as tag_name - FROM faces f - JOIN images i ON f.image_id=i.id - LEFT JOIN image_classes ic ON i.id = ic.image_id - LEFT JOIN mappings m ON ic.class_id = m.class_id - """) + cursor.execute(""" + SELECT + f.face_id, + f.embeddings, + f.bbox, + i.id, + i.path, + i.folder_id, + i.thumbnailPath, + i.metadata, + i.isTagged, + m.name as tag_name + FROM faces f + JOIN images i ON f.image_id = i.id + LEFT JOIN image_classes ic ON i.id = ic.image_id + LEFT JOIN mappings m ON ic.class_id = m.class_id + """) results = cursor.fetchall() - images_dict = {} - for ( - embeddings, - bbox, - image_id, - path, - folder_id, - thumbnail_path, - metadata, - is_tagged, - tag_name, - ) in results: - if image_id not in images_dict: - try: - embeddings_json = json.loads(embeddings) - bbox_json = json.loads(bbox) - except json.JSONDecodeError: - continue; - images_dict[image_id] = { - "embeddings": embeddings_json, - "bbox": bbox_json, - "id": image_id, - "path": path, - "folder_id": folder_id, - "thumbnailPath": thumbnail_path, - "metadata": metadata, - "isTagged": bool(is_tagged), - "tags": [], - } - - # Add tag if it exists - if tag_name: - images_dict[image_id]["tags"].append(tag_name) + images_dict = {} + seen_faces = {} # image_id -> set(face_id) + for ( + face_id, + embeddings_json_text, + bbox_json_text, + image_id, + path, + folder_id, + thumbnail_path, + metadata, + is_tagged, + tag_name, + ) in results: + if image_id not in images_dict: + images_dict[image_id] = { + "embeddings": [], # list[list[float]] + "bboxes": [], # list[dict] + "id": image_id, + "path": path, + "folder_id": folder_id, + "thumbnailPath": thumbnail_path, + "metadata": metadata, + "isTagged": bool(is_tagged), + "tags": set(), + } + seen_faces[image_id] = set() + + # Deduplicate the same face across tag join rows + if face_id in seen_faces[image_id]: + if tag_name: + images_dict[image_id]["tags"].add(tag_name) + continue + + # Parse embedding vector + try: + emb_vec = json.loads(embeddings_json_text) + except (json.JSONDecodeError, TypeError): + continue + images_dict[image_id]["embeddings"].append(emb_vec) + + # Parse bbox if present + if bbox_json_text: + try: + bbox_obj = json.loads(bbox_json_text) + except (json.JSONDecodeError, TypeError): + bbox_obj = None + else: + bbox_obj = None + images_dict[image_id]["bboxes"].append(bbox_obj) + + if tag_name: + images_dict[image_id]["tags"].add(tag_name) + seen_faces[image_id].add(face_id) - # Convert to list and set tags to None if empty + # Convert to list and set tags to None if empty images = [] for image_data in images_dict.values(): - if not image_data["tags"]: - image_data["tags"] = None + # finalize tags set -> list or None + tags_set = image_data.pop("tags", set()) + image_data["tags"] = list(tags_set) if tags_set else None images.append(image_data)Notes:
bboxes(plural) and a list of embeddings per image.📝 Committable suggestion
🤖 Prompt for AI Agents