forked from pynicolas/FairScan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload-tflite.gradle.kts
More file actions
38 lines (32 loc) · 1.22 KB
/
Copy pathdownload-tflite.gradle.kts
File metadata and controls
38 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import org.gradle.api.tasks.Copy
import java.net.URL
val modelVersion = "v1.2.0"
val modelFileName = "fairscan-segmentation-model.tflite"
val modelUrl = "https://github.com/pynicolas/fairscan-segmentation-model/releases/download/$modelVersion/$modelFileName"
val downloadedModelPath = layout.buildDirectory.file("downloads/$modelFileName")
val generatedAssetsDir = layout.buildDirectory.dir("generated/assets")
val downloadTFLiteModel = tasks.register("downloadTFLiteModel") {
val outputFile = downloadedModelPath.get().asFile
outputs.file(outputFile)
doLast {
if (!outputFile.exists()) {
println("Downloading $modelFileName from $modelUrl")
outputFile.parentFile.mkdirs()
URL(modelUrl).openStream().use { input ->
outputFile.outputStream().use { output ->
input.copyTo(output)
}
}
} else {
println("Model already downloaded: ${outputFile.absolutePath}")
}
}
}
val copyTFLiteToAssets = tasks.register<Copy>("copyTFLiteToAssets") {
dependsOn(downloadTFLiteModel)
from(downloadedModelPath)
into(generatedAssetsDir)
}
tasks.named("preBuild") {
dependsOn(copyTFLiteToAssets)
}