About AIModelLand
Installing
How to use
Running Examples
Contributing
AIModelLand is a library that provides developers with a simple API for interacting with various AI providers. It allows developers to easily integrate popular AI providers into their projects. Using this library, developers don't have to waste time connecting a new provider to a project and can easily use all the functionality that the provider and AI model provide without any difficulty.
-
Add this code to the
index.html
for Web projects:<head> <!-- other head elements --> <script type="application/javascript" src="flutter.js" defer></script> <script type="application/javascript" src="/assets/packages/flutter_inappwebview_web/assets/web/web_support.js" defer ></script> <script type="module" src="/assets/packages/ai_model_land/assets/onnx/index.js" defer ></script> </head> <script> window.addEventListener("load", async function (ev) { { { flutter_js; } } { { flutter_build_config; } } _flutter.loader.load({ serviceWorker: { serviceWorkerVersion: "{{flutter_service_worker_version}}", }, onEntrypointLoaded: function (engineInitializer) { engineInitializer.initializeEngine().then(function (appRunner) { appRunner.runApp(); }); }, }); }); </script>
-
Set Android:
minSdkVersion >= 26
,compileSdk >= 34
,AGP version >= 7.3.0
in theandroid/app/build.gradle
file and add to theAndroidManifest.xml
theusesCleartextTraffic
parameter and Internet permission:<manifest> ... <application> ... android:usesCleartextTraffic="true" </application> <uses-permission android:name="android.permission.INTERNET"/> </manifest>
-
Set Flutter version
>= 3.24.3 stable
.
Example code for updating to the latest Flutter stable version:flutter channel stable flutter upgrade
-
Initialize the
AIModelLand
library afterWidgetsFlutterBinding.ensureInitialized()
in themain
function:void main() { WidgetsFlutterBinding.ensureInitialized(); initAIModelLandLib(); ... runApp(MyApp()); }
With the library, you can easily manage the most popular AI providers without any problems. To initialize AIModelLand
, we can use the default constructor and the named constructor defaultInstance()
.
Example:
final aiModelLand = AiModelLandLib.defaultInstance();
The next step is to create base information about the model by using the BaseModel
class.
In this class, we have the following parameters:
sourceType
with enumModelSourceType
– choose where your model is located. If you choosenetwork
, the file will be downloaded to your device.source
– in this parameter, input the file location. It can be a file explorer path or an assets path. If you choosenetwork
insourceType
, input the URL to the model. If in the future you will load the model to the provider usinguint8List
format, you can input an empty string.nameFile
– input the existing file name, or if you download the model, this will be the future file name.format
with enumModelFormat
– choose the provider that you want to use.
Then you can reuse this BaseModel
in all functions for each AI provider.
You can check how to use all functions for each AI provider by the following links:
Example of using the AIModelLand library:
//create base model
BaseModel baseModel = BaseModel(
source: "assets/onnx/image_classification/mobilenetv2-7.onnx",
nameFile: "photo-detection-classification",
format: ModelFormat.onnx,
sourceType: ModelSourceType.local);
//load model to provider
bool isLoadModel = await aiModelLand.loadModel(
request: OnnxRequestModel(
loadModelWay: LoadModelWay.fromAssets,
onnxBackend: ONNXBackend.cpu ),
baseModel: baseModel);
//run model (get prediction)
OnnxResponsModel predict = await aiModelLand.runTaskOnTheModel(
request: OnnxRequestModel(dataMulti: [
inputBytes
], shape: [
[1, 3, 224, 224]
], threshold: 3, topPredictEntries: 5),
baseModel: baseModel) as OnnxResponsModel;
//restart model
await aiModelLand.restartModel(
request: OnnxRequestModel(
loadModelWay: LoadModelWay.fromAssets,
onnxBackend: ONNXBackend.cpu),
baseModel: baseModel);
//stop model
await aiModelLand.stopModel(baseModel: baseModel);
//delete model from device
await aiModelLand.deleteModelFromDevice(baseModel: baseModel);
//you can check information about device
await aiModelLand.checkPlatformInfo();
Instructions for running the included examples:
- Navigate to the example directory:
cd example
- Run
flutter run
to launch the example app on your preferred device. - Explore the example app to see how to use the library in your own project.
Instructions for contributing to this library:
- Fork this repository.
- Create a new branch:
git checkout -b my-new-branch
- Make changes and commit them:
git commit -m "My message"
- Push to the remote branch:
git push origin my-new-branch
- Create a pull request.
List any dependencies or prerequisites needed before getting started with editing this library:
- Flutter
- Installed Android Studio and Android SDK (For Android dev)
- Installed Xcode (For iOS, macOS dev)
Instructions for building the library from source code:
- Clone this repository:
git clone https://github.com/vlmoon99/ai_model_land
- Navigate to the project root directory:
cd ai_model_land