1
- use hf_hub:: api:: tokio:: Api ;
1
+ use hf_hub:: api:: tokio:: { Api , ApiError } ;
2
2
use iced:: futures:: { SinkExt , Stream } ;
3
3
use iced:: stream:: try_channel;
4
4
use iced:: task;
5
5
use iced:: widget:: { button, center, column, progress_bar, text, Column } ;
6
6
7
- use std:: sync:: Arc ;
8
-
9
7
use iced:: { Center , Element , Right , Task } ;
10
8
11
9
#[ derive( Debug , Clone ) ]
@@ -16,13 +14,12 @@ pub enum Progress {
16
14
17
15
#[ derive( Debug , Clone ) ]
18
16
pub enum Error {
19
- RequestFailed ( Arc < reqwest:: Error > ) ,
20
- NoContentLength ,
17
+ Api ( String ) ,
21
18
}
22
19
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 ( ) )
26
23
}
27
24
}
28
25
@@ -69,17 +66,15 @@ impl hf_hub::api::tokio::Progress for Prog {
69
66
}
70
67
}
71
68
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 > > {
73
73
try_channel ( 1 , move |output| async move {
74
74
let prog = Prog { output, total : 0 } ;
75
75
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 ?;
83
78
84
79
Ok ( ( ) )
85
80
} )
@@ -175,9 +170,8 @@ impl Download {
175
170
match self . state {
176
171
State :: Idle { .. } | State :: Finished { .. } | State :: Errored { .. } => {
177
172
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" ,
181
175
) )
182
176
. abortable ( ) ;
183
177
0 commit comments