File size: 1,030 Bytes
1c75c98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# tracklight_server/api/sync.py

from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from ..hf import push, pull
from .auth import verify_token

router = APIRouter()

class SyncRequest(BaseModel):
    repo_id: str
    hf_token: str

@router.post("/sync/push")
async def sync_push(request: SyncRequest, token: str = Depends(verify_token)):
    """
    Pushes local data to a Hugging Face Dataset repo.
    """
    try:
        push.push_to_hub(request.repo_id, request.hf_token)
        return {"message": "Data push initiated."}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@router.post("/sync/pull")
async def sync_pull(request: SyncRequest, token: str = Depends(verify_token)):
    """
    Pulls data from a Hugging Face Dataset repo.
    """
    try:
        pull.pull_from_hub(request.repo_id, request.hf_token)
        return {"message": "Data pull initiated."}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))