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.modelImport
import com.zeticai.mlange.core.model.ZeticMLangeHFModelConstructor
ZeticMLangeHFModel(context: Context, repoId: String)| Parameter | Type | Description |
|---|---|---|
context | Context | The Android application or activity context. |
repoId | String | The 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>| Parameter | Type | Description |
|---|---|---|
inputs | Array<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
| Feature | ZeticMLangeHFModel | ZeticMLangeModel |
|---|---|---|
| Authentication | No keys needed | Requires Personal Key |
| Model source | Hugging Face repo ID | Melange Dashboard |
| Compilation | Auto-compiled on first use | Pre-compiled on upload |
| First-run speed | Slower (download + compile) | Faster (pre-compiled) |
| Best for | Prototyping, public models | Production, custom models |
See Also
- Pre-built Models: Dashboard and Hugging Face models
- ZeticMLangeModel (Android): Key-based model class
- Compatible models on Hugging Face