Skip to content

Commit

Permalink
Bugfix: Primeira execução do app carrega modelos
Browse files Browse the repository at this point in the history
  • Loading branch information
ThalesBezerra21 committed Aug 1, 2024
1 parent b71133c commit 0d7695f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
10 changes: 8 additions & 2 deletions android/MLCChat/app/src/main/java/ai/mlc/mlcchat/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
var benchmarkingModels = emptyList<ModelState>()
val chatState = ChatState()
val modelSampleList = emptyList<ModelRecord>().toMutableStateList()
var isReady = mutableStateOf(false)

private var showAlert = mutableStateOf(false)
private var alertMessage = mutableStateOf("")
private var appConfig = AppConfig(
Expand Down Expand Up @@ -126,8 +128,6 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
)
}
}
benchmarkingModels = modelList
.filter { model -> benchmarkingModelsLabels.any {label -> model.modelConfig.modelId.lowercase(Locale.getDefault()).contains(label.lowercase(Locale.getDefault()))} }
}

private fun updateAppConfig(action: () -> Unit) {
Expand All @@ -147,6 +147,12 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
File(appDirFile, modelConfig.modelId)
)
)
benchmarkingModels = modelList
.filter { model -> benchmarkingModelsLabels.any {label -> model.modelConfig.modelId.lowercase(Locale.getDefault()).contains(label.lowercase(Locale.getDefault()))} }

if(modelList.size == appConfig.modelList.size)
isReady.value = true

if (!isBuiltin) {
updateAppConfig {
appConfig.modelList.add(
Expand Down
21 changes: 14 additions & 7 deletions android/MLCChat/app/src/main/java/ai/mlc/mlcchat/HomeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ fun HomeView(
}
}

val isReady = appViewModel.isReady.value
val canStart = isReady && !isDownloading && isIdleMeasured

Column (
modifier = Modifier
.fillMaxSize(),
Expand Down Expand Up @@ -111,7 +114,7 @@ fun HomeView(
LargeRoundedButton(
icon = Icons.Default.BarChart,
onClick = { initBenchmarkingFlux() },
enabled = !isDownloading && isIdleMeasured,
enabled = canStart,
text = "Start benchmarking"
)

Expand All @@ -120,10 +123,9 @@ fun HomeView(
LargeRoundedButton(
icon = Icons.Default.Chat,
onClick = { startConversation() },
enabled = !isDownloading && isIdleMeasured,
enabled = canStart,
text = "Chat with LLMs"
)

}
Column(
modifier = Modifier
Expand All @@ -139,8 +141,15 @@ fun HomeView(
.fillMaxWidth(),
text = "Measuring idle energy consumption"
)
}else if(!isReady){
LoadingTopBottomIndicator(
modifier = Modifier
.fillMaxHeight(0.5f)
.fillMaxWidth(),
text = "Getting models ready",
subtitleText = "Be sure you are connected to the internet"
)
}

if(isDownloading) {
DownloadView(
modifier = Modifier
Expand Down Expand Up @@ -169,9 +178,7 @@ fun useDownloadModels(

var isDownloading by remember { mutableStateOf(false) }

var pendingModels by remember {
mutableStateOf(viewModel.benchmarkingModels)
}
var pendingModels = viewModel.benchmarkingModels

val numModels = viewModel.benchmarkingModels.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ai.mlc.mlcchat.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
Expand All @@ -19,8 +20,9 @@ import androidx.compose.ui.unit.dp

@Composable
fun LoadingTopBottomIndicator(
modifier: Modifier = Modifier,
text: String,
modifier: Modifier = Modifier
subtitleText: String? = null,
) {
Row(
modifier = modifier
Expand All @@ -37,13 +39,25 @@ fun LoadingTopBottomIndicator(
strokeWidth = 2.dp
)
Spacer(modifier = Modifier.width(20.dp))
Text(
modifier = Modifier
.wrapContentHeight(align = Alignment.CenterVertically),
text = text,
color = MaterialTheme.colorScheme.onPrimary,
style = MaterialTheme.typography.titleSmall,
fontWeight = FontWeight.Light
)
Column {
Text(
modifier = Modifier
.wrapContentHeight(align = Alignment.CenterVertically),
text = text,
color = MaterialTheme.colorScheme.onPrimary,
style = MaterialTheme.typography.titleSmall,
fontWeight = FontWeight.Light
)
if(subtitleText !== null){
Text(
modifier = Modifier
.wrapContentHeight(align = Alignment.CenterVertically),
text = subtitleText,
color = MaterialTheme.colorScheme.onPrimary,
style = MaterialTheme.typography.bodySmall,
fontWeight = FontWeight.Light
)
}
}
}
}

0 comments on commit 0d7695f

Please sign in to comment.