Team Ai
Apppublic

delsj/function-gemma

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
utils.py64 linesDownload Raw Back to media
1import shutil2from pathlib import Path3 4try:5    from trackio.utils import MEDIA_DIR6except ImportError:7    from utils import MEDIA_DIR8 9 10def check_path(file_path: str | Path) -> None:11    """Raise an error if the parent directory does not exist."""12    file_path = Path(file_path)13    if not file_path.parent.exists():14        try:15            file_path.parent.mkdir(parents=True, exist_ok=True)16        except OSError as e:17            raise ValueError(18                f"Failed to create parent directory {file_path.parent}: {e}"19            )20 21 22def check_ffmpeg_installed() -> None:23    """Raise an error if ffmpeg is not available on the system PATH."""24    if shutil.which("ffmpeg") is None:25        raise RuntimeError(26            "ffmpeg is required to write video but was not found on your system. "27            "Please install ffmpeg and ensure it is available on your PATH."28        )29 30 31def get_project_media_path(32    project: str,33    run: str | None = None,34    step: int | None = None,35    relative_path: str | Path | None = None,36) -> Path:37    """38    Get the full path where uploaded files are stored for a Trackio project (and create the directory if it doesn't exist).39    If a run is not provided, the files are stored in a project-level directory with the given relative path.40 41    Args:42        project: The project name43        run: The run name44        step: The step number45        relative_path: The relative path within the directory (only used if run is not provided)46 47    Returns:48        The full path to the media file49    """50    if step is not None and run is None:51        raise ValueError("Uploading files at a specific step requires a run")52 53    path = MEDIA_DIR / project54    if run:55        path /= run56        if step is not None:57            path /= str(step)58    else:59        path /= "files"60        if relative_path:61            path /= relative_path62    path.mkdir(parents=True, exist_ok=True)63    return path64