Spaces:
Sleeping
Sleeping
Download backfill_embeddings.py from WhoIsLuwah/Transcriber: direct link, hf CLI and curl.
- Browser
- Download file 912 Bytes
-
https://huggingface.co/spaces/WhoIsLuwah/Transcriber/resolve/main/backfill_embeddings.py
- Command line
-
hf download hf://spaces/WhoIsLuwah/Transcriber/backfill_embeddings.py
-
curl -L -o backfill_embeddings.py https://huggingface.co/spaces/WhoIsLuwah/Transcriber/resolve/main/backfill_embeddings.py
912 Bytes
| """Fingerprint reels that have no search embedding yet. Safe to re-run. | |
| Run from the repo root: python backend/backfill_embeddings.py | |
| """ | |
| import db | |
| import main # importing main loads .env and configures logging | |
| def backfill() -> tuple: | |
| """Embed every row missing an embedding. Returns (updated, skipped).""" | |
| main._get_embedding_model() # fail loudly here rather than skip every row | |
| updated = skipped = 0 | |
| for row in db.reels_missing_embedding(): | |
| embedding = main.embed_reel(db.row_to_record(row)["extracted_json"]) | |
| if embedding is None: | |
| skipped += 1 # queued/failed reel: nothing extracted to embed | |
| continue | |
| db.set_embedding(row["id"], embedding) | |
| updated += 1 | |
| return updated, skipped | |
| if __name__ == "__main__": | |
| updated, skipped = backfill() | |
| print(f"Embedded {updated} reel(s); skipped {skipped} with nothing to embed.") | |