PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

Fix 904 celebrity tagging

Open DeveloperAmrit opened this issue 10 months ago • 2 comments

Closes #904

Changes done

  • Added face encodings of 1000 celebrities
  • Implemented celebrity detection
  • Marks a cluster with name of celebrity if a celebrity is detected in that cluster

Why second commit "fix merge issue"

  • Faced some local merge issues, solved them here

Video was larger than 10MB so i have attached the link https://res.cloudinary.com/db6cpegxg/video/upload/v1767805877/Screen_Recording_2026-01-07_at_10.32.52_PM_co6scx.mov

Summary by CodeRabbit

  • New Features

    • Added celebrity identification with background scanning and a "Scan Celebrities" button on the Home page.
    • Automatic creation/association of face clusters based on identified celebrities; identified faces are queued for batched updates.
    • New lightweight matcher that loads known celebrity encodings to match faces by embedding.
  • Chores

    • Minor formatting and logging improvements.

DeveloperAmrit avatar Jan 07 '26 17:01 DeveloperAmrit

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7d2402c8-ca7b-4bc3-927d-ecd9976007b8

📥 Commits

Reviewing files that changed from the base of the PR and between ef8461e298f733f3ac39c0840587d506f6e774bb and 5b40d422d7750b5cba6ab9b9cb0f92779ef78da4.

📒 Files selected for processing (2)
  • backend/main.py
  • frontend/src/api/api-functions/index.ts
💤 Files with no reviewable changes (1)
  • backend/main.py
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/api/api-functions/index.ts

Walkthrough

Adds celebrity identification: loads celebrity embeddings, matches detected faces, creates/associates cluster IDs, exposes a background scan endpoint, integrates into face detection pipeline, and adds a frontend control to trigger scans.

Changes

Cohort / File(s) Summary
Database Layer
backend/app/database/face_clusters.py
Added db_get_or_create_cluster_by_name(name, cursor=None) and ensures a unique index; performs atomic get-or-create using UUID, supports owned or external cursors with proper commit/rollback behavior.
Celebrity Detection Model
backend/app/models/celebrity_detection/CelebrityMatcher.py
New CelebrityMatcher class: loads pickle of celebrity encodings, optimizes into numpy arrays, and exposes identify_face(unknown_embedding, threshold=0.7) using Euclidean distance.
Face Detection Integration
backend/app/models/FaceDetector.py
Instantiates CelebrityMatcher, identifies celebrity per embedding during detection, tracks cluster_ids, and passes cluster_id into DB insertion flow (db_insert_face_embeddings_by_image_id).
Backend Routes
backend/app/routes/celebrity.py
New router and scan_celebrities(background_tasks) endpoint that schedules a background job to re-scan faces, identify celebrities, create/get cluster IDs, and batch-update face cluster associations with logging and error handling.
Frontend API Layer
frontend/src/api/api-functions/celebrity.ts, frontend/src/api/api-functions/index.ts
Added scanCelebrities() async helper and re-exported it via API index to call POST /celebrity/scan.
Frontend UI
frontend/src/pages/Home/Home.tsx
Added React Query mutation to call scanCelebrities, wired feedback states, and a "Scan Celebrities" button with loading state above the gallery.
Minor Formatting
backend/main.py
Whitespace-only removal of a blank line before the __main__ entry point (no functional change).

Sequence Diagram

sequenceDiagram
    participant User as User
    participant UI as Home Page
    participant API as Frontend API
    participant Route as Backend Route
    participant Task as Background Task
    participant Detector as FaceDetector
    participant Matcher as CelebrityMatcher
    participant DB as Database

    User->>UI: Click "Scan Celebrities"
    UI->>API: scanCelebrities()
    API->>Route: POST /celebrity/scan
    Route->>Task: Schedule background process
    Route-->>UI: Return 200
    Task->>DB: Fetch all faces with cluster names
    loop For each face
        Task->>Detector: Provide face embedding
        Detector->>Matcher: identify_face(embedding)
        Matcher-->>Detector: Celebrity name or None
        alt Celebrity identified and differs from cluster
            Task->>DB: db_get_or_create_cluster_by_name(celebrity_name)
            DB-->>Task: cluster_id
            Task->>DB: Queue update mapping face -> cluster_id
        end
    end
    Task->>DB: Batch update face cluster_ids
    Task->>Task: Log completion/errors

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • AOSSIE-Org/PictoPy#466: Overlaps with face cluster DB helper and celebrity-matching integration (db_get_or_create_cluster_by_name and celebrity cluster assignment).

Suggested labels

Python, TypeScript/JavaScript

Poem

🐰 I nibble through encodings, tiny and bright,
I hop on embeddings by moonlit byte,
I match a famous smile and give it a name,
Clusters bloom softly, never the same,
Hooray — celebs and clusters, a rabbit's delight!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Fix 904 celebrity tagging' directly references issue #904 and accurately summarizes the main feature—implementing celebrity detection and tagging in clusters.
Linked Issues check ✅ Passed The PR implements all core requirements from #904: hardcoded celebrity face encodings (via CelebrityMatcher), comparison of face embeddings against celebrity encodings (identify_face method), and cluster tagging with celebrity names via db_get_or_create_cluster_by_name.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to issue #904 requirements: celebrity detection infrastructure (CelebrityMatcher), database cluster operations (face_clusters.py), backend integration (FaceDetector, celebrity route), and frontend UI for triggering scans (Home page). One trivial whitespace removal in main.py is incidental.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jan 07 '26 17:01 coderabbitai[bot]

⚠️ This PR has merge conflicts.

Please resolve the merge conflicts before review.

Your PR will only be reviewed by a maintainer after all conflicts have been resolved.

📺 Watch this video to understand why conflicts occur and how to resolve them: https://www.youtube.com/watch?v=Sqsz1-o7nXk

github-actions[bot] avatar Jun 07 '26 14:06 github-actions[bot]

⚠️ This PR still has unresolved merge conflicts and has been inactive for the past 30 days.

The PR has merge conflicts label is still applied, and there has been no recent activity on this PR.

Please resolve the merge conflicts or leave a comment if you are still actively working on it.

If there is no further activity within the next 5 days, this PR may be automatically closed to help keep the PR backlog manageable.

github-actions[bot] avatar Jul 08 '26 03:07 github-actions[bot]

🔒 Closing this PR due to unresolved merge conflicts and prolonged inactivity.

This PR still had unresolved merge conflicts, and there was no activity within 5 days of the stale warning being posted.

You may reopen this PR or submit a new one after resolving the merge conflicts.

github-actions[bot] avatar Jul 13 '26 03:07 github-actions[bot]