Skip to content

Instantly share code, notes, and snippets.

@davidldennison
Forked from elbruno/alttextgenerator.cs
Created July 3, 2025 02:43
Show Gist options
  • Save davidldennison/e73df8a42b5e03b40576575620739151 to your computer and use it in GitHub Desktop.
Save davidldennison/e73df8a42b5e03b40576575620739151 to your computer and use it in GitHub Desktop.
alttextgenerator.cs
#:package [email protected]
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