|
8 | 8 | import Foundation |
9 | 9 |
|
10 | 10 | public struct HubApi { |
11 | | - var downloadBase: URL |
12 | | - var hfToken: String? |
13 | | - var endpoint: String |
| 11 | + public let downloadBase: URL |
| 12 | + public let hfToken: String? |
| 13 | + public let endpoint: String |
14 | 14 |
|
15 | 15 | public typealias RepoType = Hub.RepoType |
16 | 16 | public typealias Repo = Hub.Repo |
17 | 17 |
|
18 | | - public init(downloadBase: URL? = nil, hfToken: String? = nil, endpoint: String = "https://huggingface.co") { |
19 | | - if downloadBase == nil { |
| 18 | + public init( |
| 19 | + downloadBase: URL? = nil, |
| 20 | + hfToken: String? = nil, |
| 21 | + endpoint: String = "https://huggingface.co" |
| 22 | + ) { |
| 23 | + self.hfToken = hfToken |
| 24 | + if let downloadBase { |
| 25 | + self.downloadBase = downloadBase |
| 26 | + } else { |
20 | 27 | let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! |
21 | 28 | self.downloadBase = documents.appending(component: "huggingface") |
22 | | - } else { |
23 | | - self.downloadBase = downloadBase! |
24 | 29 | } |
25 | | - self.hfToken = hfToken |
26 | 30 | self.endpoint = endpoint |
27 | 31 | } |
28 | 32 |
|
29 | | - static let shared = HubApi() |
| 33 | + public static let shared = HubApi() |
30 | 34 | } |
31 | 35 |
|
32 | 36 | /// File retrieval |
@@ -179,7 +183,13 @@ public extension HubApi { |
179 | 183 | let repoDestination = localRepoLocation(repo) |
180 | 184 | for filename in filenames { |
181 | 185 | let fileProgress = Progress(totalUnitCount: 100, parent: progress, pendingUnitCount: 1) |
182 | | - let downloader = HubFileDownloader(repo: repo, repoDestination: repoDestination, relativeFilename: filename, hfToken: hfToken, endpoint: endpoint) |
| 186 | + let downloader = HubFileDownloader( |
| 187 | + repo: repo, |
| 188 | + repoDestination: repoDestination, |
| 189 | + relativeFilename: filename, |
| 190 | + hfToken: hfToken, |
| 191 | + endpoint: endpoint |
| 192 | + ) |
183 | 193 | try await downloader.download { fractionDownloaded in |
184 | 194 | fileProgress.completedUnitCount = Int64(100 * fractionDownloaded) |
185 | 195 | progressHandler(progress) |
|
0 commit comments