File size: 1,433 Bytes
c4e128a | 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 36 37 38 39 40 41 42 43 44 | """kdc upload command — upload assets to HuggingFace Hub."""
from __future__ import annotations
from pathlib import Path
import typer
from rich.console import Console
from app.utils.container import Container
app = typer.Typer(help="Upload dataset assets to HuggingFace Hub.")
console = Console()
@app.command()
def run(
ctx: typer.Context,
repo_id: str = typer.Option("Darachhat/khmer-document-corpus", "--repo-id", help="HF Repo ID."),
pdf_dir: Path = typer.Option(Path("pdf"), "--pdf-dir"),
meta_dir: Path = typer.Option(Path("metadata"), "--meta-dir"),
preview_dir: Path = typer.Option(Path("preview"), "--preview-dir"),
datasets_dir: Path = typer.Option(Path("datasets"), "--datasets-dir"),
) -> None:
"""Upload PDF, metadata, previews, and datasets to HuggingFace Hub."""
container: Container = ctx.obj
hf_exporter = container.hf_exporter
if not hf_exporter:
console.print("[red]HuggingFace exporter service not configured.[/red]")
raise typer.Exit(1)
for path, target in [
(pdf_dir, "pdf"),
(meta_dir, "metadata"),
(preview_dir, "preview"),
(datasets_dir, "datasets"),
]:
if path.exists():
console.print(f"Uploading [cyan]{path}[/cyan] -> [bold]{repo_id}/{target}[/bold]...")
hf_exporter.upload_folder(path, path_in_repo=target)
console.print("[green]✓ Upload complete.[/green]")
|