Spaces:
Sleeping
Sleeping
Quincy Hsieh commited on
Commit ·
f66fdd0
1
Parent(s): 4cf3b63
Add how to update binary files into /data bucket
Browse files23 unmodified lines2425262728293031301 unmodified lines33333433533633733823 unmodified lines3. [Step-by-Step Explanation](#step-by-step-explanation)4. [API Endpoints](#api-endpoints)5. [Setup & Deployment](#setup--deployment)6. [Configuration](#configuration)7. [How It Works (Detailed)](#how-it-works-detailed)---301 unmodified lines---## Configuration| Variable | Default | Description |23 unmodified lines242526272829303132301 unmodified lines33433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642723 unmodified lines3. [Step-by-Step Explanation](#step-by-step-explanation)4. [API Endpoints](#api-endpoints)5. [Setup & Deployment](#setup--deployment)6. [Adding Binary Files to the HF Space](#adding-binary-files-to-the-hf-space)7. [Configuration](#configuration)8. [How It Works (Detailed)](#how-it-works-detailed)---301 unmodified lines---## Adding Binary Files to the HF SpaceLarge or binary files (e.g., pre-built ChromaDB databases, PDFs, images, model weights) cannot be pushed with regular `git push` because Hugging Face repositories enforce a **10 MB file-size limit** for standard Git. Use one of the methods below to make them available to your Space at runtime.### Method 1: Git LFS (recommended for files < 5 GB)Hugging Face repos support [Git Large File Storage (LFS)](https://git-lfs.com/). Files tracked by LFS are stored in a dedicated bucket and downloaded transparently when the Space starts.```bash# 1. Install Git LFS (once per machine)git lfs install# 2. Track the binary patterns you needgit lfs track "*.pdf"git lfs track "*.sqlite3"git lfs track "chroma_db/**"git lfs track "DataSet/**"# This updates .gitattributes — commit itgit add .gitattributesgit commit -m "chore: track binary files with Git LFS"# 3. Add and push the binary filesgit add chroma_db/ DataSet/git commit -m "feat: add pre-built vector store and datasets"git push```> **Verify:** After pushing, open your Space repo on huggingface.co and click on an LFS file — it should show `Stored with Git LFS` instead of raw content.### Method 2: Upload via the `huggingface_hub` Python SDKUse this when you want to upload files programmatically (e.g., from a CI pipeline or a notebook) without cloning the full repo.```pythonfrom huggingface_hub import HfApiapi = HfApi()# Upload a single fileapi.upload_file(path_or_fileobj="./chroma_db/chroma.sqlite3",path_in_repo="chroma_db/chroma.sqlite3",repo_id="YOUR_USERNAME/Example-App-Hackathon-Gustave-Eiffel-2026",repo_type="space",)# Upload an entire folderapi.upload_folder(folder_path="./DataSet",path_in_repo="DataSet",repo_id="YOUR_USERNAME/Example-App-Hackathon-Gustave-Eiffel-2026",repo_type="space",)```> **Authentication:** Set `HF_TOKEN` in your environment or call `huggingface_hub.login()` first. The token needs **write** access to the Space.### Method 3: Hugging Face Hub UI (quick one-off uploads)1. Open your Space repository on huggingface.co2. Navigate to **Files and versions**3. Click **Add file → Upload files**4. Drag-and-drop your binary files (up to 50 GB per file via the UI)5. Commit directly to `main`### Accessing Uploaded Files in Your ApplicationOnce binary files are in the repo (via any method above), they are available at their relative path inside the Space container:```pythonimport chromadb# Files land at the repo root, same relative path you committed them atclient = chromadb.PersistentClient(path="./chroma_db")```No extra download logic is needed — Hugging Face clones the full repo (including LFS objects) into the Space container on startup.### Tips- **`.gitattributes`** is the source of truth for LFS tracking. Verify your patterns are listed there before pushing.- For files **> 5 GB**, prefer uploading via the Hub UI or the SDK (Git LFS CLI may time out on slow connections).- If you update a binary file, push the new version the same way — LFS handles versioning automatically.- To exclude files from the Space build (e.g., test data not needed at runtime), add them to `.gitignore` instead.---## Configuration| Variable | Default | Description |
README.md+91-2