Download and return the primary file path for this component.
(&self, repo_id: &str, cache_dir: &str)
| 33 | |
| 34 | /// Download and return the primary file path for this component. |
| 35 | pub fn get(&self, repo_id: &str, cache_dir: &str) -> Result<PathBuf> { |
| 36 | let mut cache_path = PathBuf::from(cache_dir); |
| 37 | cache_path.push("hub"); |
| 38 | let cache = Cache::new(cache_path); |
| 39 | let api = ApiBuilder::from_cache(cache).build()?; |
| 40 | let repo = api.model(repo_id.to_string()); |
| 41 | |
| 42 | let files = self.files(); |
| 43 | let mut primary_path = None; |
| 44 | for file in &files { |
| 45 | log::info!("downloading {} ...", file); |
| 46 | let path = repo |
| 47 | .get(file) |
| 48 | .map_err(|e| anyhow::anyhow!("failed to download {}: {}", file, e))?; |
| 49 | if primary_path.is_none() { |
| 50 | primary_path = Some(path); |
| 51 | } |
| 52 | } |
| 53 | Ok(primary_path.unwrap()) |
| 54 | } |
| 55 | |
| 56 | /// Get all downloaded file paths for this component. |
| 57 | pub fn get_all(&self, repo_id: &str, cache_dir: &str) -> Result<Vec<PathBuf>> { |
no test coverage detected