pub struct ApiRepo { /* private fields */ }
Expand description
Shorthand for accessing things within a particular repo
You can inspect repos with ApiRepo::info
or download files with ApiRepo::download
Implementations§
Source§impl ApiRepo
impl ApiRepo
Sourcepub fn url(&self, filename: &str) -> String
pub fn url(&self, filename: &str) -> String
Get the fully qualified URL of the remote filename
let api = Api::new().unwrap();
let url = api.model("gpt2".to_string()).url("model.safetensors");
assert_eq!(url, "https://huggingface.co/gpt2/resolve/main/model.safetensors");
Sourcepub fn get(&self, filename: &str) -> Result<PathBuf, ApiError>
pub fn get(&self, filename: &str) -> Result<PathBuf, ApiError>
This will attempt the fetch the file locally first, then [Api.download
]
if the file is not present.
use hf_hub::{api::sync::Api};
let api = Api::new().unwrap();
let local_filename = api.model("gpt2".to_string()).get("model.safetensors").unwrap();
Sourcepub fn download_with_progress<P: Progress>(
&self,
filename: &str,
progress: P,
) -> Result<PathBuf, ApiError>
pub fn download_with_progress<P: Progress>( &self, filename: &str, progress: P, ) -> Result<PathBuf, ApiError>
This function is used to download a file with a custom progress function.
It uses the Progress
trait and can be used in more complex use
cases like downloading a showing progress in a UI.
struct MyProgress{
current: usize,
total: usize
}
impl Progress for MyProgress{
fn init(&mut self, size: usize, _filename: &str){
self.total = size;
self.current = 0;
}
fn update(&mut self, size: usize){
self.current += size;
println!("{}/{}", self.current, self.total)
}
fn finish(&mut self){
println!("Done !");
}
}
let api = Api::new().unwrap();
let progress = MyProgress{current: 0, total: 0};
let local_filename = api.model("gpt2".to_string()).download_with_progress("model.safetensors", progress).unwrap();
Sourcepub fn download(&self, filename: &str) -> Result<PathBuf, ApiError>
pub fn download(&self, filename: &str) -> Result<PathBuf, ApiError>
Downloads a remote file (if not already present) into the cache directory to be used locally. This functions require internet access to verify if new versions of the file exist, even if a file is already on disk at location.
let api = Api::new().unwrap();
let local_filename = api.model("gpt2".to_string()).download("model.safetensors").unwrap();
Sourcepub fn info(&self) -> Result<RepoInfo, ApiError>
pub fn info(&self) -> Result<RepoInfo, ApiError>
Get information about the Repo
use hf_hub::{api::sync::Api};
let api = Api::new().unwrap();
api.model("gpt2".to_string()).info();
Sourcepub fn info_request(&self) -> Request
pub fn info_request(&self) -> Request
Get the raw ureq::Request
with the url and method already set
let api = Api::new().unwrap();
api.model("gpt2".to_owned())
.info_request()
.query("blobs", "true")
.call();