Update storage/embeddings_routers.py
Browse files
storage/embeddings_routers.py
CHANGED
|
@@ -19,6 +19,46 @@ file_manager = FileManager(EMBEDDINGS_ROOT)
|
|
| 19 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@router.post("/upload_embeddings", tags=["Embeddings Manager"])
|
| 23 |
async def upload_embeddings(
|
| 24 |
file: UploadFile = File(...),
|
|
|
|
| 19 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 20 |
|
| 21 |
|
| 22 |
+
@router.get("/list_embeddings", tags=["Embeddings Manager"])
|
| 23 |
+
def list_all_embeddings(
|
| 24 |
+
token: str = Query(..., description="Token required for authorization")
|
| 25 |
+
):
|
| 26 |
+
"""
|
| 27 |
+
List all embeddings stored under /data/embeddings.
|
| 28 |
+
|
| 29 |
+
For each video hash folder, returns:
|
| 30 |
+
- video: folder name (hash)
|
| 31 |
+
- faces: true/false depending on whether faces/embeddings.json exists
|
| 32 |
+
- voices: true/false depending on whether voices/embeddings.json exists
|
| 33 |
+
|
| 34 |
+
Notes:
|
| 35 |
+
- A video folder may contain only faces, only voices, or neither.
|
| 36 |
+
- Missing folders are treated as false.
|
| 37 |
+
"""
|
| 38 |
+
validate_token(token)
|
| 39 |
+
|
| 40 |
+
results = []
|
| 41 |
+
|
| 42 |
+
# If embeddings root does not exist, return empty list
|
| 43 |
+
if not EMBEDDINGS_ROOT.exists():
|
| 44 |
+
return []
|
| 45 |
+
|
| 46 |
+
for video_dir in EMBEDDINGS_ROOT.iterdir():
|
| 47 |
+
if not video_dir.is_dir():
|
| 48 |
+
continue # Skip anything that is not a folder
|
| 49 |
+
|
| 50 |
+
faces_path = video_dir / "faces" / "embeddings.json"
|
| 51 |
+
voices_path = video_dir / "voices" / "embeddings.json"
|
| 52 |
+
|
| 53 |
+
results.append({
|
| 54 |
+
"video": video_dir.name,
|
| 55 |
+
"faces": faces_path.exists(),
|
| 56 |
+
"voices": voices_path.exists()
|
| 57 |
+
})
|
| 58 |
+
|
| 59 |
+
return results
|
| 60 |
+
|
| 61 |
+
|
| 62 |
@router.post("/upload_embeddings", tags=["Embeddings Manager"])
|
| 63 |
async def upload_embeddings(
|
| 64 |
file: UploadFile = File(...),
|