Skip to content

Instantly share code, notes, and snippets.

@mmaitlen
Last active September 23, 2025 16:35
Show Gist options
  • Select an option

  • Save mmaitlen/8be1d55a878fe9e14c3985bd1e6dd136 to your computer and use it in GitHub Desktop.

Select an option

Save mmaitlen/8be1d55a878fe9e14c3985bd1e6dd136 to your computer and use it in GitHub Desktop.
Image analysis with Moondream and Llama Vision
// following Dart code is used to analyze an image with Moondream and Llama3.2-vision
Future<String> encodeFile(String imagePath) async {
File imageFile = File(imagePath);
List<int> imageBytes = await imageFile.readAsBytes();
return base64Encode(imageBytes);
}
Future<void> analyzeWithLocalMoondream(String path) async {
final base64Image = await encodeFile(path);
final data = jsonEncode({
"image_url": "data:image/jpeg;base64,$base64Image",
"stream": false,
});
try {
final response = await http.post(
Uri.parse('http://localhost:2020/v1/caption'),
body: data,
);
print('response ${response.statusCode} ${response.body}');
} on Exception catch (e) {
print('exception $e');
}
}
Future<void> analyzeWithLocalLlama(String path) async {
final base64Image = await encodeFile(path);
final data = jsonEncode({
"model": "llama3.2-vision",
"messages": [
{
"role": "user",
"content": "what is in this image?",
"images": [base64Image],
},
],
});
try {
final response = await http.post(
Uri.parse('http://localhost:11434/api/chat'),
body: data,
);
print('response ${response.statusCode} ${response.body}');
} on Exception catch (e) {
print('exception $e');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment