Melange
API ReferenceAndroid

ZeticMLangeHFModel

API reference for loading Hugging Face models on Android with ZeticMLangeHFModel.

The ZeticMLangeHFModel class allows you to load and run models directly from Hugging Face repositories. No personal key or model key is needed: just the repository ID.

Package

com.zeticai.mlange.core.model

Import

import com.zeticai.mlange.core.model.ZeticMLangeHFModel

Constructor

ZeticMLangeHFModel(context: Context, repoId: String)
ParameterTypeDescription
contextContextThe Android application or activity context.
repoIdStringThe Hugging Face repository ID (e.g., "zetic-ai/yolov11n").
val model = ZeticMLangeHFModel(context, "zetic-ai/yolov11n")

The constructor downloads, compiles, and caches the model on first use. This may take some time depending on model size. Run initialization on a background thread to avoid blocking the UI. Subsequent initializations use the cached binary and are fast.


Methods

run(inputs)

Executes inference on the loaded model.

fun run(inputs: Array<Tensor>): Array<Tensor>
ParameterTypeDescription
inputsArray<Tensor>Input tensors matching the model's expected shapes.

Returns: Array<Tensor>: The model's output tensors.

val outputs = model.run(arrayOf(inputTensor))

Full Working Example

import com.zeticai.mlange.core.model.ZeticMLangeHFModel
import kotlinx.coroutines.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        CoroutineScope(Dispatchers.IO).launch {
            // Initialize from Hugging Face (downloads on first use)
            val model = ZeticMLangeHFModel(this@MainActivity, "zetic-ai/yolov11n")

            // Prepare inputs
            val inputs = arrayOf(imageTensor) // Your preprocessed input

            // Run inference
            val outputs = model.run(inputs)

            // Process outputs on main thread
            withContext(Dispatchers.Main) {
                // Update UI with results
            }
        }
    }
}

Comparison with ZeticMLangeModel

FeatureZeticMLangeHFModelZeticMLangeModel
AuthenticationNo keys neededRequires Personal Key
Model sourceHugging Face repo IDMelange Dashboard
CompilationAuto-compiled on first usePre-compiled on upload
First-run speedSlower (download + compile)Faster (pre-compiled)
Best forPrototyping, public modelsProduction, custom models

See Also