Post

Replies

Boosts

Views

Activity

Reply to DATA
In addition to @SpaceMan 's answer you can import some sort of database: You can export a CSV file and have something sort of like this. Aloe Vera, skin healer, Cut from middle, once every three days, cut the leave and use the gel inside for your rash Almond, skin healer, cut the young leaves, daily, soak in water overnight rinse and blend ...... and then that's easy. struct Plant: Identifiable { var id: UUID { get { return .init() } } var plantName: String var mdedicalProperties: String var harvestInstructions: String var waterRequirements: String var recipe: String } // load your file with your way, I'll use file as a variable for the string contents of the database var plantModel = [Plant] let plantLines = file.split(separator: "\n") let plantArray2D: Array<Array<String>> = [] for i in plantLines { let modified = i.replacingOccurrences(of: " ", with: "") plantArray2D.append(i.split(separator: ",")) } for i in plantArray2D { plantModel.append(Plant(plantName: i[0], medicicalProperties: i[1], harvestInstructions: i[2], waterRequirements: i[3], recipe: i[4])) }
Aug ’22
Reply to ML
JSON: [ { "text": "sun", "label": "RED" }, { "text": "", "label": "RED" }, { "text": "citrus", "label": "ORG" }, { "text": "warm", "label": "ORG" }, { "text": "sunlight", "label": "YLW" }, { "text": "cheese", "label": "YLW" }, { "text": "foliage", "label": "GRN" }, { "text": "organic", "label": "GRN" }, { "text": "mint", "label": "MNT" }, { "text": "freshness", "label": "MNT" }, { "text": "sky", "label": "BLU" }, { "text": "sea", "label": "BLU" }, { "text": "magic", "label": "VLT" }, { "text": "jealousy", "label": "VLT" } ] And I updated my code to @ebhanson 's suggestion:     var body: some View { // view         TextField("Text...", text: $text).padding().background(color).onReceive(timer) { _ in             color = predict(for: text)?.color             print(color)         }.task {             do {                 model = try ChromaClassifier(configuration: .init()).model             } catch {                 print("NIL MDL")                 model = nil             }             if let model = model {                 predictor = try? NLModel(mlModel: model)             } else {                 predictor = nil             }         } var model: MLModel? = nil var predictor: NLModel? = nil func predict(for string: String) -> SingleColor? { // function     if let predictor = predictor {         let colorKeys = predictor.predictedLabelHypotheses(for: string, maximumCount: 1) // 1..7         print(colorKeys)         var color: SingleColor = .init(red: 0, green: 0, blue: 0)         for i in colorKeys {             color.morphing((ColorKeys.init(rawValue: i.key) ?? .white).toColor().percentage(of: i.value))             print(color)         }         return color     } else {         return nil     } }
Aug ’22