diff --git a/examples/text_embedder/android/app/src/androidTest/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelperTest.kt b/examples/text_embedder/android/app/src/androidTest/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelperTest.kt
index c2edcfe790..629dd2839c 100644
--- a/examples/text_embedder/android/app/src/androidTest/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelperTest.kt
+++ b/examples/text_embedder/android/app/src/androidTest/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelperTest.kt
@@ -16,19 +16,14 @@
package com.google.mediapipe.examples.textembedder
-import android.content.res.AssetManager
-import android.graphics.Bitmap
-import android.graphics.BitmapFactory
import androidx.test.core.app.ApplicationProvider
-import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
-import org.junit.Assert.*
+import org.junit.Assert.assertEquals
import org.junit.Before
-import java.io.InputStream
/**
* Instrumented test, which will execute on an Android device.
@@ -55,7 +50,7 @@ class TextEmbedderHelperTest {
@Test
fun embeddingResultsWithinAcceptedRange() {
- val bundleResult = embedderHelper.embed(TEXT_TEST_ONE, TEXT_TEST_TWO)
+ val bundleResult = embedderHelper.compare(TEXT_TEST_ONE, TEXT_TEST_TWO)
assertEquals(EXPECTED_SIMILARITY, bundleResult?.similarity ?: 0.0, 0.09)
}
}
diff --git a/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/MainActivity.kt b/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/MainActivity.kt
index 1835bcd07c..3e337346ef 100644
--- a/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/MainActivity.kt
+++ b/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/MainActivity.kt
@@ -38,11 +38,11 @@ class MainActivity : AppCompatActivity(), TextEmbedderHelper.EmbedderListener {
binding.btnCompare.setOnClickListener {
// Compare two texts here
val firstText =
- if (binding.imgOne.text.isNullOrEmpty()) getString(R.string.default_compared_text) else binding.imgOne.text.toString()
+ if (binding.imgOne.text.isNullOrEmpty()) getString(R.string.default_hint_first_text) else binding.imgOne.text.toString()
val secondText =
- if (binding.imgTwo.text.isNullOrEmpty()) getString(R.string.default_compared_text) else binding.imgTwo.text.toString()
+ if (binding.imgTwo.text.isNullOrEmpty()) getString(R.string.default_hint_second_text) else binding.imgTwo.text.toString()
- textEmbedderHelper.embed(firstText, secondText)
+ textEmbedderHelper.compare(firstText, secondText)
?.let { resultBundle ->
updateResult(resultBundle)
}
diff --git a/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelper.kt b/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelper.kt
index ee8ffe3890..da1d6658b3 100644
--- a/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelper.kt
+++ b/examples/text_embedder/android/app/src/main/java/com/google/mediapipe/examples/textembedder/TextEmbedderHelper.kt
@@ -85,16 +85,16 @@ class TextEmbedderHelper(
// If both the vectors are aligned, the angle between them
// will be 0. cos 0 = 1. So, mathematically, this distance metric will
// be used to find the most similar text.
- fun embed(firstBitmap: String, secondBitmap: String): ResultBundle? {
+ fun compare(firstText: String, secondText: String): ResultBundle? {
// Inference time is the difference between the system time at the start and finish of the
// process
val startTime = SystemClock.uptimeMillis()
textEmbedder?.let {
val firstEmbed =
- it.embed(firstBitmap).embeddingResult().embeddings().first()
+ it.embed(firstText).embeddingResult().embeddings().first()
val secondEmbed =
- it.embed(secondBitmap).embeddingResult().embeddings().first()
+ it.embed(secondText).embeddingResult().embeddings().first()
val inferenceTimeMs = SystemClock.uptimeMillis() - startTime
return ResultBundle(
TextEmbedder.cosineSimilarity(firstEmbed, secondEmbed),
diff --git a/examples/text_embedder/android/app/src/main/res/layout/activity_main.xml b/examples/text_embedder/android/app/src/main/res/layout/activity_main.xml
index e53da682fd..62ac1f6b0c 100644
--- a/examples/text_embedder/android/app/src/main/res/layout/activity_main.xml
+++ b/examples/text_embedder/android/app/src/main/res/layout/activity_main.xml
@@ -74,7 +74,7 @@
android:layout_height="0dp"
android:background="@color/bottom_sheet_background"
android:gravity="top"
- android:hint="@string/default_compared_text"
+ android:hint="@string/default_hint_first_text"
android:inputType="textMultiLine"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
@@ -88,7 +88,7 @@
android:layout_height="0dp"
android:background="@color/bottom_sheet_background"
android:gravity="top"
- android:hint="@string/default_compared_text"
+ android:hint="@string/default_hint_second_text"
android:inputType="textMultiLine"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
diff --git a/examples/text_embedder/android/app/src/main/res/values/strings.xml b/examples/text_embedder/android/app/src/main/res/values/strings.xml
index d459430d4c..5f5ce2ced8 100644
--- a/examples/text_embedder/android/app/src/main/res/values/strings.xml
+++ b/examples/text_embedder/android/app/src/main/res/values/strings.xml
@@ -26,7 +26,8 @@
Input two texts to compare
Similarity:
Compare
- MediaPipe offers cross-platform, customizable ML solutions for live and streaming media.
+ MediaPipe offers cross-platform, customizable ML solutions for live and streaming media.
+ I use MediaPipe to create amazing things with text, audio, and visual content.
- CPU