hf-hub-simple-progress

Crates.iohf-hub-simple-progress
lib.rshf-hub-simple-progress
version0.1.2
created_at2025-01-09 16:54:32.710665+00
updated_at2025-02-24 12:06:50.627964+00
descriptionSimplified download callback for hf-hub
homepage
repositoryhttps://github.com/newfla/hf-hub-simple-progress
max_upload_size
id1510150
size67,937
Flavio Bizzarri (newfla)

documentation

README

hf-hub-simple-progress

A simpler approach to hf-hub Progress trait

Basically hf-hub#70 built on top hf-hub#80

Usage

Sync

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));

Async

See the test section in the async_closure module.

Requires async_fn_traits, unboxed_closures nightly features

Commit count: 8

cargo fmt