Skip to content

Commit

Permalink
v0.1.6 add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Mon-ius committed May 5, 2024
1 parent 3d270ef commit de50d89
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
16 changes: 16 additions & 0 deletions example/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use tokio;

#[tokio::main]
async fn main() {
let _build = libhfd::api::tokio::ApiBuilder::new();

let api = _build.with_endpoint("https://hf-mirror.com")
.with_token("xxxxxxxxxxx")
.build()
.unwrap();

let _filename = api
.dataset("OpenVideo/pexels-raw".to_string())
.get(format!("data/{:06}.parquet", 0).as_ref())
.await;
}
31 changes: 31 additions & 0 deletions example/dataset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use tokio;
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() {
let nums: Vec<Vec<u32>> = (0..204)
.collect::<Vec<_>>()
.chunks(10)
.map(|chunk| chunk.to_vec())
.collect();

for chunk in nums{
let mut tasks: Vec<_> = chunk.into_iter()
.map(|i| tokio::spawn(async move {
let _build = libhfd::api::tokio::ApiBuilder::new();
let api = _build.with_endpoint("https://hf-mirror.com")
.with_token("hf_xxxxxxxx")
.build()
.unwrap();
let _filename = api
.dataset("OpenVideo/pexels-raw".to_string())
.get(format!("data/{:06}.parquet", i).as_ref())
.await;
}))
.collect();

for task in tasks {
task.await.unwrap();
}
}
}
15 changes: 15 additions & 0 deletions example/mirror.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use tokio;

#[tokio::main]
async fn main() {
let _build = libhfd::api::tokio::ApiBuilder::new();
let api = _build.with_endpoint("https://hf-mirror.com")
.build()
.unwrap();

let _filename = api
.model("ByteDance/Hyper-SD".to_string())
.get("Hyper-SDXL-8steps-lora.safetensors")
.await
.unwrap();
}
2 changes: 1 addition & 1 deletion hfd-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hfd-cli"
version = "0.1.5"
version = "0.1.6"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions hfd-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use tokio;
use tokio_stream::StreamExt;
// use tokio_stream::StreamExt;

#[tokio::main]
async fn main() {
let api = libhfd::api::tokio::Api::new().unwrap();

let _filename = api
.dataset("ByteDance/Hyper-SD".to_string())
.model("ByteDance/Hyper-SD".to_string())
.get("Hyper-SDXL-8steps-lora.safetensors")
.await
.unwrap();
Expand Down
11 changes: 8 additions & 3 deletions hfd/src/api/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl ApiBuilder {
let progress = true;

Self {
endpoint: "https://hf-mirror.com".to_string(),
endpoint: "https://huggingface.co".to_string(),
url_template: "{endpoint}/{repo_id}/resolve/{revision}/{filename}".to_string(),
cache,
token,
Expand All @@ -98,6 +98,11 @@ impl ApiBuilder {
}
}

pub fn with_endpoint(mut self, endpoint: &str) -> Self {
self.endpoint = endpoint.to_string();
self
}

pub fn with_progress(mut self, progress: bool) -> Self {
self.progress = progress;
self
Expand All @@ -108,8 +113,8 @@ impl ApiBuilder {
self
}

pub fn with_token(mut self, token: Option<String>) -> Self {
self.token = token;
pub fn with_token(mut self, token: &str) -> Self {
self.token = Some(token.to_string());
self
}

Expand Down

0 comments on commit de50d89

Please sign in to comment.