darachhat
feat: build production-ready Khmer Document Corpus v0.2.0 with Typer CLI, PyMuPDF, Polars, and DI architecture
c4e128a | """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() | |
| 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]") | |