Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ let package = Package(
.library(name: "Transformers", targets: ["Tokenizers", "Generation", "Models"]),
],
dependencies: [
.package(url: "https://github.com/huggingface/swift-jinja.git", from: "2.0.0")
.package(url: "https://github.com/huggingface/swift-jinja.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "4.1.0"),
],
targets: [
.target(name: "Generation", dependencies: ["Tokenizers"]),
.target(name: "Hub", dependencies: [.product(name: "Jinja", package: "swift-jinja")], resources: [.process("Resources")], swiftSettings: swiftSettings),
.target(
name: "Hub",
dependencies: [
.product(name: "Jinja", package: "swift-jinja"),
.product(name: "Crypto", package: "swift-crypto"),
],
resources: [.process("Resources")],
swiftSettings: swiftSettings
),
.target(name: "Models", dependencies: ["Tokenizers", "Generation"]),
.target(name: "Tokenizers", dependencies: ["Hub", .product(name: "Jinja", package: "swift-jinja")]),
.testTarget(name: "GenerationTests", dependencies: ["Generation"]),
Expand Down
3 changes: 1 addition & 2 deletions Sources/Hub/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// See LICENSE at https://github.com/huggingface/swift-coreml-diffusers/LICENSE
//

import Combine
import Foundation

/// A robust file downloader with support for resumable downloads and progress reporting.
///
/// The Downloader class handles file downloads from remote URLs with features including
/// automatic resume capability, progress tracking, speed monitoring, and retry mechanisms.
/// It supports both foreground and background download sessions for different use cases.
final class Downloader: NSObject, Sendable, ObservableObject {
final class Downloader: NSObject, Sendable {
private let destination: URL
private let incompleteDestination: URL
private let downloadResumeState: DownloadResumeState = .init()
Expand Down
7 changes: 3 additions & 4 deletions Sources/Hub/HubApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Pedro Cuenca on 20231230.
//

import CryptoKit
import Crypto
import Foundation
import Network
import os
Expand Down Expand Up @@ -491,9 +491,8 @@ public extension HubApi {
}
}

/// Note we go from Combine in Downloader to callback-based progress reporting
/// We'll probably need to support Combine as well to play well with Swift UI
/// (See for example PipelineLoader in swift-coreml-diffusers)
/// Downloader emits progress over AsyncStream which we bridge here to a simple callback.
/// A Combine wrapper can be layered on top when needed for SwiftUI-style progress reporting.
@discardableResult
func download(progressHandler: @escaping (Double, Double?) -> Void) async throws -> URL {
let localMetadata = try hub.readDownloadMetadata(metadataPath: metadataDestination)
Expand Down
1 change: 0 additions & 1 deletion Tests/HubTests/DownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Arda Atahan Ibis on 1/28/25.
//

import Combine
import XCTest

@testable import Hub
Expand Down