Return the HuggingFace hub cache directory if it exists.
()
| 84 | |
| 85 | /// Return the HuggingFace hub cache directory if it exists. |
| 86 | pub fn hf_cache_dir() -> Option<PathBuf> { |
| 87 | if let Ok(dir) = std::env::var("HF_HUB_CACHE") { |
| 88 | let p = PathBuf::from(dir); |
| 89 | if p.exists() { |
| 90 | return Some(p); |
| 91 | } |
| 92 | } |
| 93 | if let Ok(dir) = std::env::var("HF_HOME") { |
| 94 | let p = PathBuf::from(dir).join("hub"); |
| 95 | if p.exists() { |
| 96 | return Some(p); |
| 97 | } |
| 98 | } |
| 99 | let home = dirs::home_dir()?; |
| 100 | let p = home.join(".cache/huggingface/hub"); |
| 101 | if p.exists() { |
| 102 | Some(p) |
| 103 | } else { |
| 104 | None |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /// Downloads all required model files from HuggingFace Hub. |
| 109 | /// Returns the local directory path containing the downloaded files. |
no outgoing calls