asimov_huggingface/
lib.rs

1// This is free and unencumbered software released into the public domain.
2
3//! Hugging Face helpers for model downloads with unified progress bar.
4//!
5//! ```no_run
6//! use asimov_huggingface::{ensure_file, ensure_snapshot};
7//!
8//! let file = ensure_file("facebook/dinov2-base", "pytorch_model.bin").unwrap();
9//! let dir = ensure_snapshot("julien-c/dummy-unknown", None).unwrap();
10//! ```
11
12mod ensure;
13pub use ensure::*;
14
15mod progress;
16pub use progress::*;
17
18use hf_hub::api::sync::ApiError;
19use std::path::PathBuf;
20use thiserror::Error;
21
22#[derive(Debug, Error)]
23pub enum HuggingfaceError {
24    #[error("failed to access Hugging Face API: {0}")]
25    Api(#[from] ApiError),
26
27    #[error("snapshot is empty")]
28    EmptySnapshot,
29
30    #[error("failed to download file `{0}`")]
31    Download(PathBuf),
32}
33
34pub type Result<T> = std::result::Result<T, HuggingfaceError>;