Skip to content

Commit f1a1b2c

Browse files
committed
Fix the example.
1 parent 0801a58 commit f1a1b2c

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

examples/iced/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ edition = "2021"
66
[dependencies]
77
iced = { version = "0.13.1", features = ["tokio"] }
88
hf-hub = { path = "../../", default-features = false, features = ["tokio", "rustls-tls"] }
9-
reqwest = "0.12.10"

examples/iced/src/main.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use hf_hub::api::tokio::Api;
1+
use hf_hub::api::tokio::{Api, ApiError};
22
use iced::futures::{SinkExt, Stream};
33
use iced::stream::try_channel;
44
use iced::task;
55
use iced::widget::{button, center, column, progress_bar, text, Column};
66

7-
use std::sync::Arc;
8-
97
use iced::{Center, Element, Right, Task};
108

119
#[derive(Debug, Clone)]
@@ -16,13 +14,12 @@ pub enum Progress {
1614

1715
#[derive(Debug, Clone)]
1816
pub enum Error {
19-
RequestFailed(Arc<reqwest::Error>),
20-
NoContentLength,
17+
Api(String),
2118
}
2219

23-
impl From<reqwest::Error> for Error {
24-
fn from(error: reqwest::Error) -> Self {
25-
Error::RequestFailed(Arc::new(error))
20+
impl From<ApiError> for Error {
21+
fn from(value: ApiError) -> Self {
22+
Self::Api(value.to_string())
2623
}
2724
}
2825

@@ -69,17 +66,15 @@ impl hf_hub::api::tokio::Progress for Prog {
6966
}
7067
}
7168

72-
pub fn download(_url: impl AsRef<str>) -> impl Stream<Item = Result<Progress, Error>> {
69+
pub fn download(
70+
repo: String,
71+
filename: impl AsRef<str>,
72+
) -> impl Stream<Item = Result<Progress, Error>> {
7373
try_channel(1, move |output| async move {
7474
let prog = Prog { output, total: 0 };
7575

76-
let api = Api::new()
77-
.unwrap()
78-
.model("mattshumer/Reflection-Llama-3.1-70B".to_string());
79-
let filename = "model-00001-of-00162.safetensors";
80-
println!("API OK");
81-
api.download_with_progress(filename, prog).await.unwrap();
82-
println!("API Download started");
76+
let api = Api::new().unwrap().model(repo);
77+
api.download_with_progress(filename.as_ref(), prog).await?;
8378

8479
Ok(())
8580
})
@@ -175,9 +170,8 @@ impl Download {
175170
match self.state {
176171
State::Idle { .. } | State::Finished { .. } | State::Errored { .. } => {
177172
let (task, handle) = Task::stream(download(
178-
"https://huggingface.co/\
179-
mattshumer/Reflection-Llama-3.1-70B/\
180-
resolve/main/model-00001-of-00162.safetensors",
173+
"mattshumer/Reflection-Llama-3.1-70B".to_string(),
174+
"model-00001-of-00162.safetensors",
181175
))
182176
.abortable();
183177

0 commit comments

Comments
 (0)