Crates.io | hf-hub-simple-progress |
lib.rs | hf-hub-simple-progress |
version | 0.1.2 |
created_at | 2025-01-09 16:54:32.710665+00 |
updated_at | 2025-02-24 12:06:50.627964+00 |
description | Simplified download callback for hf-hub |
homepage | |
repository | https://github.com/newfla/hf-hub-simple-progress |
max_upload_size | |
id | 1510150 |
size | 67,937 |
A simpler approach to hf-hub Progress trait
Basically hf-hub#70 built on top hf-hub#80
use std::{thread::sleep, time::Duration, sync::atomic::AtomicBool, rc::Rc};
use hf_hub::api::sync::ApiBuilder;
use hf_hub_simple_progress::{ProgressEvent, sync::callback_builder};
let done = Rc::new(AtomicBool::new(false));
let done_copy = done.clone();
let api = ApiBuilder::new().build().unwrap();
let callback = callback_builder(move |progress: ProgressEvent| {
if progress.percentage == 1. {
done_copy.store(true, std::sync::atomic::Ordering::Relaxed);
}
});
api.model("julien-c/dummy-unknown".to_string())
.download_with_progress("config.json", callback)
.unwrap();
assert!(done.load(std::sync::atomic::Ordering::Relaxed));
See the test section in the async_closure
module.
Requires async_fn_traits, unboxed_closures
nightly features