Post

Replies

Boosts

Views

Activity

Reply to Swift Student Challenge Vision
Hi! Thanks for the reply I want it to process through a Create ML file and show the name of the picture. For example, the user would upload a photo of a dish (e.g. Pad Thai) and then the Core ML would tell me what that the food is, in text. The Core ML works fine on a normal Xcode Project but Swift Playgrounds does not recognise the food and just does not identify the food. Thanks :)
Jan ’24
Reply to Swift Student Challenge Vision
Hi thanks for replying: Here is my code: Content View File: import SwiftUI import Vision struct ContentView: View { @State private var showImagePicker: Bool = false @State private var inputImage: UIImage? @State private var classificationLabel: String = "Upload Your Photo and add it your Daily Food Logger" var body: some View { VStack { Text(classificationLabel) .padding() if let inputImage = inputImage { Image(uiImage: inputImage) .resizable() .scaledToFit() } Button("Upload Photos") { self.showImagePicker = true } } .sheet(isPresented: $showImagePicker) { ImagePicker(image: self.$inputImage) } } } #Preview { ContentView() } Image PIckes File: import SwiftUI import UIKit struct ImagePicker: UIViewControllerRepresentable { @Environment(.presentationMode) var presentationMode @Binding var image: UIImage? func makeUIViewController(context: Context) -> UIImagePickerController { let picker = UIImagePickerController() picker.delegate = context.coordinator return picker } func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {} func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { var parent: ImagePicker init(_ parent: ImagePicker) { self.parent = parent } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { if let uiImage = info[.originalImage] as? UIImage { parent.image = uiImage } parent.presentationMode.wrappedValue.dismiss() } } }
Jan ’24