Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created June 25, 2025 14:52
Show Gist options
  • Save elbruno/4396c9ee3e56d1c86d280faa33b8f9fe to your computer and use it in GitHub Desktop.
Save elbruno/4396c9ee3e56d1c86d280faa33b8f9fe to your computer and use it in GitHub Desktop.
alttextgenerator.cs
#:package OllamaSharp@5.1.19
using OllamaSharp;
// set up the client
var uri = new Uri("http://localhost:11434");
var ollama = new OllamaApiClient(uri);
ollama.SelectedModel = "gemma3";
var chat = new Chat(ollama);
// read the image file from arguments
byte[] imageBytes = File.ReadAllBytes(args[0]);
var imageBytesEnumerable = new List<IEnumerable<byte>> { imageBytes };
// generate the alt text
var message = "Generate a complete alt text description for the attached image. The description should be detailed and suitable for visually impaired users. Do not include any information about the image file name or format. must be in Spanish.";
await foreach (var answerToken in chat.SendAsync(message: message, imagesAsBytes: imageBytesEnumerable))
Console.Write(answerToken);
// done
Console.WriteLine($">> Ollama done");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment