Spaces:
Running
Running
People Search
Browse files- src/api/people.py +23 -16
src/api/people.py
CHANGED
|
@@ -14,7 +14,7 @@ the same Supabase table.
|
|
| 14 |
|
| 15 |
import hashlib
|
| 16 |
|
| 17 |
-
from fastapi import APIRouter, Body, Depends, HTTPException, Request
|
| 18 |
|
| 19 |
from src.core.config import USE_CLUSTER_AWARE_SEARCH
|
| 20 |
from src.core.security import get_verified_keys
|
|
@@ -42,7 +42,7 @@ def _user_id_from_key(pinecone_key: str) -> str:
|
|
| 42 |
return hashlib.sha256(pinecone_key.encode()).hexdigest()[:16]
|
| 43 |
|
| 44 |
|
| 45 |
-
@router.
|
| 46 |
async def list_people(
|
| 47 |
request: Request,
|
| 48 |
keys: dict = Depends(get_verified_keys),
|
|
@@ -51,16 +51,21 @@ async def list_people(
|
|
| 51 |
Returns all identity clusters for the authenticated user, ordered by
|
| 52 |
face_count descending (most-seen people first).
|
| 53 |
|
|
|
|
|
|
|
| 54 |
Response shape:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
"""
|
| 65 |
ip = get_ip(request)
|
| 66 |
user_id = _user_id_from_key(keys["pinecone_key"])
|
|
@@ -74,7 +79,7 @@ async def list_people(
|
|
| 74 |
raise HTTPException(500, f"Failed to fetch people: {e}")
|
| 75 |
|
| 76 |
|
| 77 |
-
@router.
|
| 78 |
async def get_cluster_images(
|
| 79 |
cluster_id: str,
|
| 80 |
request: Request,
|
|
@@ -83,6 +88,8 @@ async def get_cluster_images(
|
|
| 83 |
"""
|
| 84 |
Returns all images belonging to a specific identity cluster.
|
| 85 |
|
|
|
|
|
|
|
| 86 |
Response shape:
|
| 87 |
{
|
| 88 |
"cluster_id": "uuid",
|
|
@@ -111,18 +118,18 @@ async def get_cluster_images(
|
|
| 111 |
raise HTTPException(500, f"Failed to fetch cluster images: {e}")
|
| 112 |
|
| 113 |
|
| 114 |
-
@router.
|
| 115 |
async def update_cluster_name(
|
| 116 |
cluster_id: str,
|
| 117 |
request: Request,
|
| 118 |
-
name: str =
|
| 119 |
keys: dict = Depends(get_verified_keys),
|
| 120 |
):
|
| 121 |
"""
|
| 122 |
Assigns a human-readable name to a cluster.
|
| 123 |
|
| 124 |
-
Request
|
| 125 |
-
Response:
|
| 126 |
"""
|
| 127 |
ip = get_ip(request)
|
| 128 |
user_id = _user_id_from_key(keys["pinecone_key"])
|
|
|
|
| 14 |
|
| 15 |
import hashlib
|
| 16 |
|
| 17 |
+
from fastapi import APIRouter, Body, Depends, Form, HTTPException, Request
|
| 18 |
|
| 19 |
from src.core.config import USE_CLUSTER_AWARE_SEARCH
|
| 20 |
from src.core.security import get_verified_keys
|
|
|
|
| 42 |
return hashlib.sha256(pinecone_key.encode()).hexdigest()[:16]
|
| 43 |
|
| 44 |
|
| 45 |
+
@router.post("/api/people")
|
| 46 |
async def list_people(
|
| 47 |
request: Request,
|
| 48 |
keys: dict = Depends(get_verified_keys),
|
|
|
|
| 51 |
Returns all identity clusters for the authenticated user, ordered by
|
| 52 |
face_count descending (most-seen people first).
|
| 53 |
|
| 54 |
+
Request: FormData with user_pinecone_key + user_cloudinary_url
|
| 55 |
+
|
| 56 |
Response shape:
|
| 57 |
+
{
|
| 58 |
+
"people": [
|
| 59 |
+
{
|
| 60 |
+
"cluster_id": "uuid",
|
| 61 |
+
"name": "Mom" | null,
|
| 62 |
+
"face_count": 42,
|
| 63 |
+
"representative_face_crop": "<base64 jpg>"
|
| 64 |
+
},
|
| 65 |
+
...
|
| 66 |
+
],
|
| 67 |
+
"total": 3
|
| 68 |
+
}
|
| 69 |
"""
|
| 70 |
ip = get_ip(request)
|
| 71 |
user_id = _user_id_from_key(keys["pinecone_key"])
|
|
|
|
| 79 |
raise HTTPException(500, f"Failed to fetch people: {e}")
|
| 80 |
|
| 81 |
|
| 82 |
+
@router.post("/api/people/{cluster_id}")
|
| 83 |
async def get_cluster_images(
|
| 84 |
cluster_id: str,
|
| 85 |
request: Request,
|
|
|
|
| 88 |
"""
|
| 89 |
Returns all images belonging to a specific identity cluster.
|
| 90 |
|
| 91 |
+
Request: FormData with user_pinecone_key + user_cloudinary_url
|
| 92 |
+
|
| 93 |
Response shape:
|
| 94 |
{
|
| 95 |
"cluster_id": "uuid",
|
|
|
|
| 118 |
raise HTTPException(500, f"Failed to fetch cluster images: {e}")
|
| 119 |
|
| 120 |
|
| 121 |
+
@router.post("/api/people/{cluster_id}/rename")
|
| 122 |
async def update_cluster_name(
|
| 123 |
cluster_id: str,
|
| 124 |
request: Request,
|
| 125 |
+
name: str = Form(...),
|
| 126 |
keys: dict = Depends(get_verified_keys),
|
| 127 |
):
|
| 128 |
"""
|
| 129 |
Assigns a human-readable name to a cluster.
|
| 130 |
|
| 131 |
+
Request: FormData with user_pinecone_key + user_cloudinary_url + name
|
| 132 |
+
Response: {"cluster_id": "uuid", "name": "Mom", "ok": true}
|
| 133 |
"""
|
| 134 |
ip = get_ip(request)
|
| 135 |
user_id = _user_id_from_key(keys["pinecone_key"])
|