<commit_before>package com.google.firebase.samples.apps.mlkit.kotlin.cloudimagelabeling

import android.util.Log
import com.google.android.gms.tasks.Task
import com.google.firebase.ml.vision.FirebaseVision
import com.google.firebase.ml.vision.cloud.FirebaseVisionCloudDetectorOptions
import com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabel
import com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabelDetector
import com.google.firebase.ml.vision.common.FirebaseVisionImage
import com.google.firebase.samples.apps.mlkit.common.FrameMetadata
import com.google.firebase.samples.apps.mlkit.common.GraphicOverlay
import com.google.firebase.samples.apps.mlkit.kotlin.VisionProcessorBase

/** Cloud Label Detector Demo.  */
class CloudImageLabelingProcessor : VisionProcessorBase<List<FirebaseVisionCloudLabel>>() {

    private val detector: FirebaseVisionCloudLabelDetector

    init {
        val options = FirebaseVisionCloudDetectorOptions.Builder()
                .setMaxResults(10)
                .setModelType(FirebaseVisionCloudDetectorOptions.STABLE_MODEL)
                .build()

        detector = FirebaseVision.getInstance().getVisionCloudLabelDetector(options)
    }

    override fun detectInImage(image: FirebaseVisionImage): Task<List<FirebaseVisionCloudLabel>> {
        return detector.detectInImage(image)
    }

    override fun onSuccess(
            labels: List<FirebaseVisionCloudLabel>,
            frameMetadata: FrameMetadata,
            graphicOverlay: GraphicOverlay) {

        graphicOverlay.clear()

        Log.d(TAG, "cloud label size: ${labels.size}")

        val labelsStr = ArrayList<String>()
        for (i in labels.indices) {
            val label = labels[i]

            Log.d(TAG, "cloud label: $label")

            label.label?.let {
                labelsStr.add(it)
            }
        }

        val cloudLabelGraphic = CloudLabelGraphic(graphicOverlay)
        graphicOverlay.add(cloudLabelGraphic)
        cloudLabelGraphic.updateLabel(labelsStr)
    }
<commit_msg>Fix lint warnings and optimize for CloudImageLabelingProcessor (#696)<commit_after>package com.google.firebase.samples.apps.mlkit.kotlin.cloudimagelabeling

import android.util.Log
import com.google.android.gms.tasks.Task
import com.google.firebase.ml.vision.FirebaseVision
import com.google.firebase.ml.vision.cloud.FirebaseVisionCloudDetectorOptions
import com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabel
import com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabelDetector
import com.google.firebase.ml.vision.common.FirebaseVisionImage
import com.google.firebase.samples.apps.mlkit.common.FrameMetadata
import com.google.firebase.samples.apps.mlkit.common.GraphicOverlay
import com.google.firebase.samples.apps.mlkit.kotlin.VisionProcessorBase

/** Cloud Label Detector Demo.  */
class CloudImageLabelingProcessor : VisionProcessorBase<List<FirebaseVisionCloudLabel>>() {

    private val detector: FirebaseVisionCloudLabelDetector by lazy {
        FirebaseVisionCloudDetectorOptions.Builder()
            .setMaxResults(10)
            .setModelType(FirebaseVisionCloudDetectorOptions.STABLE_MODEL)
            .build().let { options ->
                FirebaseVision.getInstance().getVisionCloudLabelDetector(options)
            }
    }


    override fun detectInImage(image: FirebaseVisionImage): Task<List<FirebaseVisionCloudLabel>> {
        return detector.detectInImage(image)
    }

    override fun onSuccess(
            results: List<FirebaseVisionCloudLabel>,
            frameMetadata: FrameMetadata,
            graphicOverlay: GraphicOverlay) {

        graphicOverlay.clear()

        Log.d(TAG, "cloud label size: ${results.size}")

        val labelsStr = ArrayList<String>()
        for (i in results.indices) {
            val result = results[i]

            Log.d(TAG, "cloud label: $result")

            result.label?.let {
                labelsStr.add(it)
            }
        }

        val cloudLabelGraphic = CloudLabelGraphic(graphicOverlay)
        graphicOverlay.add(cloudLabelGraphic)
        cloudLabelGraphic.updateLabel(labelsStr)
    }

{'fraction_non_alphanumeric': 0.08935863559932741, 'fraction_numerical': 0.0016814797021378813, 'mean_word_length': 3.3785488958990535, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2776395', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1181, 'n_words': 176}