diff --git a/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/common/modelitem/ModelItem.kt b/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/common/modelitem/ModelItem.kt index 1d3afff2f..700871a34 100644 --- a/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/common/modelitem/ModelItem.kt +++ b/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/common/modelitem/ModelItem.kt @@ -72,7 +72,6 @@ import com.google.ai.edge.gallery.ui.common.tos.TosViewModel import com.google.ai.edge.gallery.ui.modelmanager.ModelManagerViewModel import com.google.ai.edge.gallery.ui.theme.bodyMediumMedium import com.google.ai.edge.gallery.ui.theme.customColors -import kotlin.text.toFloat /** * Composable function to display a model item in the model manager list. @@ -148,13 +147,16 @@ fun ModelItem( ) // Model action menu (benchmark, delete), and button to expand/collapse button at the right. Row(verticalAlignment = Alignment.Top, modifier = Modifier.align(Alignment.TopEnd)) { + val isWebImport = model.imported && model.url.isNotEmpty() if ( - modelVariants.isEmpty() && downloadStatus?.status == ModelDownloadStatusType.SUCCEEDED + modelVariants.isEmpty() && + (downloadStatus?.status == ModelDownloadStatusType.SUCCEEDED || isWebImport) ) { ModelItemActionMenu( model = model, modelManagerViewModel = modelManagerViewModel, - showBenchmarkButton = showBenchmarkButton, + showBenchmarkButton = + showBenchmarkButton && downloadStatus?.status == ModelDownloadStatusType.SUCCEEDED, showDeleteButton = showDeleteButton && model.localFileRelativeDirPathOverride.isEmpty() && !isAicore, onBenchmarkClicked = { onBenchmarkClicked(model) }, @@ -387,11 +389,13 @@ fun ModelVariantHeader( ) } // Model action menu (benchmark, delete) - if (downloadStatus?.status == ModelDownloadStatusType.SUCCEEDED) { + val isWebImport = variantModel.imported && variantModel.url.isNotEmpty() + if (downloadStatus?.status == ModelDownloadStatusType.SUCCEEDED || isWebImport) { ModelItemActionMenu( model = variantModel, modelManagerViewModel = modelManagerViewModel, - showBenchmarkButton = showBenchmarkButton, + showBenchmarkButton = + showBenchmarkButton && downloadStatus?.status == ModelDownloadStatusType.SUCCEEDED, showDeleteButton = showDeleteButton && variantModel.localFileRelativeDirPathOverride.isEmpty() && diff --git a/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/modelmanager/GlobalModelManager.kt b/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/modelmanager/GlobalModelManager.kt index 5804f7e04..756a64db8 100644 --- a/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/modelmanager/GlobalModelManager.kt +++ b/Android/src/app/src/main/java/com/google/ai/edge/gallery/ui/modelmanager/GlobalModelManager.kt @@ -88,6 +88,7 @@ import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.unit.dp import androidx.core.net.toUri import com.google.ai.edge.gallery.R @@ -96,6 +97,7 @@ import com.google.ai.edge.gallery.data.RuntimeType import com.google.ai.edge.gallery.data.Task import com.google.ai.edge.gallery.proto.ImportedModel import com.google.ai.edge.gallery.ui.common.TaskIcon +import com.google.ai.edge.gallery.ui.common.buildTrackableUrlAnnotatedString import com.google.ai.edge.gallery.ui.common.modelitem.ModelItem import com.google.ai.edge.gallery.ui.common.tos.TosViewModel import kotlin.text.endsWith @@ -412,6 +414,12 @@ fun GlobalModelManager( style = MaterialTheme.typography.titleLarge, modifier = Modifier.padding(vertical = 4.dp, horizontal = 16.dp), ) + Text( + stringResource(R.string.import_model_terms_subtitle), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 12.dp), + ) val cbImportFromLocalFile = stringResource(R.string.cd_import_model_from_local_file_button) Box( modifier = @@ -538,7 +546,17 @@ fun GlobalModelManager( title = { Text(stringResource(R.string.import_from_hugging_face_title)) }, text = { Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { - Text(stringResource(R.string.enter_hugging_face_url)) + Text( + buildAnnotatedString { + append(stringResource(R.string.enter_hugging_face_url)) + append( + buildTrackableUrlAnnotatedString( + url = stringResource(R.string.enter_hugging_face_url_example_link), + linkText = stringResource(R.string.enter_hugging_face_url_example_link), + ) + ) + } + ) OutlinedTextField( value = huggingFaceUrlInput, onValueChange = { huggingFaceUrlInput = it }, diff --git a/Android/src/app/src/main/res/values/strings.xml b/Android/src/app/src/main/res/values/strings.xml index 08b5ea1a2..8164d908c 100644 --- a/Android/src/app/src/main/res/values/strings.xml +++ b/Android/src/app/src/main/res/values/strings.xml @@ -385,10 +385,12 @@ Are you sure you want to clear the history? This action cannot be undone. + You are responsible for adhering to any separate terms applicable to models. Import model from Hugging Face From Hugging Face Import from Hugging Face - Enter the Hugging Face model URL: + "Enter the Hugging Face model file URL, for example: " + https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/resolve/main/gemma-4-E2B-it.litertlm https://huggingface.co/… Next Unsupported model type