https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
f

felislynx

10/20/2023, 8:26 AM
Hello. I've question about wrapping up node dependency: I've 4 expect members in commonMain:
Copy code
expect class CapturedImage
expect class CapturedFace
expect fun CapturedFace.extractEyePosition(): Eyes
expect fun CapturedImage.toBase64String(): String
TF lite for js dependency:
Copy code
val jsMain by getting {
    dependencies {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
        api("io.ktor:ktor-client-js:2.2.1")
        implementation(npm("mediapipe/face_detection", "0.4.0"))
        implementation(npm("tensorflow/tfjs-backend-webgl", "4.4.0"))
        implementation(npm("tensorflow/tfjs-converter", "4.4.0"))
        implementation(npm("tensorflow/tfjs-core", "4.4.0"))
    }
}
Now, i would like to have actual in jsMain but i have no idea how to do it for js: For example for ios i have:
Copy code
actual typealias CapturedFace = MLKFace

actual fun CapturedFace.extractEyePosition(): Eyes {
    val le = this.landmarkOfType(MLKFaceLandmarkTypeLeftEye)?.position!!
    val re = this.landmarkOfType(MLKFaceContourTypeRightEye)?.position!!
    return Eyes(
        Eye(re.x.toFloat(), re.y.toFloat()),
        Eye(le.x.toFloat(), le.y.toFloat())
    )
}
But for js i don't see import for Face or anything that is related to those npm libraries
a

Alexander Zhirkevich

10/20/2023, 8:33 AM
You have to define externals for js libraries using
external
keyword. Here is an example
👀 1
f

felislynx

10/20/2023, 8:35 AM
So External would be a wrapper for a json returned from tfjs
a

Alexander Zhirkevich

10/20/2023, 8:37 AM
This also would be helpful
👀 1
f

felislynx

10/20/2023, 8:37 AM
I've found out that npm dependency was not resolved during gradle sync and manually runned task to pack js module returned: error Couldn't find package "tensorflow/tfjs@4.12.0" required by "myCommons@0.0.0-unspecified" on the "npm" registry.
Execution failed for task ':kotlinNpmInstall'.
Process 'Resolving NPM dependencies using yarn' returns 1
@Alexander Zhirkevich could you also help with this part? I think the external part i understand so the only part that i'm missing now would be actually get this dependency 😄
a

Alexander Zhirkevich

10/20/2023, 8:50 AM
Not really. Try upgrade tfjs to 4.12.0
f

felislynx

10/20/2023, 8:51 AM
Copy code
val jsMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
                api("io.ktor:ktor-client-js:2.2.1")
//                implementation(npm("mediapipe/face_detection", "0.4.0"))
//                implementation(npm("tensorflow/tfjs-backend-webgl", "4.4.0"))
//                implementation(npm("tensorflow/tfjs-converter", "4.4.0"))
//                implementation(npm("tensorflow/tfjs-core", "4.4.0"))
                implementation(npm("tensorflow/tfjs", "4.12.0"))
            }
        }
and still it says it is not in registry o_O
a

Alexander Zhirkevich

10/20/2023, 8:54 AM
Or try it like @tensorflow/tfjs with @ sign
❤️ 1
f

felislynx

10/20/2023, 9:00 AM
thank you
2 Views