CoolFace
Datasetpublic

echodict/llama.cpp

version https://git-lfs.github.com/spec/v1 oid sha256:cfc44b7ba25614df70e6b65e3341cae0310163bd32fd31a6b928a542df433faf size 30786

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes773downloads
LoadCustomButton.swift45 linesDownload Raw Back to UI
1import SwiftUI2import UniformTypeIdentifiers3 4struct LoadCustomButton: View {5    @ObservedObject private var llamaState: LlamaState6    @State private var showFileImporter = false7 8    init(llamaState: LlamaState) {9        self.llamaState = llamaState10    }11 12    var body: some View {13        VStack {14            Button(action: {15                showFileImporter = true16            }) {17                Text("Load Custom Model")18            }19        }20        .fileImporter(21            isPresented: $showFileImporter,22            allowedContentTypes: [UTType(filenameExtension: "gguf", conformingTo: .data)!],23            allowsMultipleSelection: false24        ) { result in25            switch result {26            case .success(let files):27                files.forEach { file in28                    let gotAccess = file.startAccessingSecurityScopedResource()29                    if !gotAccess { return }30 31                    do {32                        try llamaState.loadModel(modelUrl: file.absoluteURL)33                    } catch let err {34                        print("Error: \(err.localizedDescription)")35                    }36 37                    file.stopAccessingSecurityScopedResource()38                }39            case .failure(let error):40                print(error)41            }42        }43    }44}45