{"id":2201,"date":"2025-07-02T20:20:58","date_gmt":"2025-07-02T20:20:58","guid":{"rendered":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/2025\/07\/02\/local-ai-net-alttext-magic-in-one-c-script\/"},"modified":"2025-07-02T20:20:58","modified_gmt":"2025-07-02T20:20:58","slug":"local-ai-net-alttext-magic-in-one-c-script","status":"publish","type":"post","link":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/2025\/07\/02\/local-ai-net-alttext-magic-in-one-c-script\/","title":{"rendered":"Local AI + .NET = AltText Magic in One C# Script"},"content":{"rendered":"<p>Need to generate image descriptions fast? In this post, we\u2019ll show how to combine .NET 10\u2019s new capabilities with local AI models to create smart AltText \u2014 all in one simple C# file. It\u2019s a fun way to explore what AI can do beyond chat.<\/p>\n<h2>AltText Generation with Local AI Models and dotnet run app.cs<\/h2>\n<h3> Intro: Let\u2019s Talk About AltText<\/h3>\n<p>Accessibility matters \u2014 and one simple but powerful way to improve it is by adding <strong>AltText<\/strong> to images. Alternative text helps screen readers describe images to visually impaired users, improves SEO, and enhances overall UX. But writing descriptive alt text for every image can be repetitive. That\u2019s where AI comes in!<\/p>\n<h3> Using Local Models with Ollama<\/h3>\n<p>Local models are a game changer. No rate limits, no cloud latency, and full control over the models you use.<\/p>\n<p>In this sample, we will use <strong><a href=\"https:\/\/ollama.com\/\">Ollama<\/a><\/strong> to run a vision model like gemma3, llama3.2-vision, or mistral-small3.2. These models are great at understanding image content and generating rich natural language descriptions.<\/p>\n<p>ollama run gemma3<br \/>\n# or ollama run llama3.2-vision<br \/>\n# or ollama run mistral-small3.2<\/p>\n<p>Once Ollama is running locally (usually on <a href=\"http:\/\/localhost:11434\/\">http:\/\/localhost:11434<\/a>), you can send requests to analyze an image and receive a natural language description.<\/p>\n\n<div class=\"alert alert-primary\">\n<p class=\"alert-divider\"><strong>Coming Soon<\/strong><\/p>\n<p>AI Foundry Local will provide similar capabilities with local models. Stay tuned!<\/p><\/div>\n<h2> Run C# as a Script with dotnet run app.cs<\/h2>\n<p>.NET 10 introduced a cool new feature: you can now run a C# file directly with dotnet run. No project scaffolding, no .csproj files \u2014 just clean, script-like execution.<\/p>\n<p>Ref: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-run-app\/\">https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-run-app\/<\/a><\/p>\n<p>dotnet run app.cs<\/p>\n<p>This is incredibly convenient for scripting tasks like image processing, quick automation, or dev tooling.<\/p>\n<p>Let\u2019s see it in action!<\/p>\n<h2> The Full Code Sample<\/h2>\n\n<p> Source: <a href=\"https:\/\/gist.github.com\/elbruno\/4396c9ee3e56d1c86d280faa33b8f9fe\">https:\/\/gist.github.com\/elbruno\/4396c9ee3e56d1c86d280faa33b8f9fe<\/a><\/p>\n<p>Save this code as alttext.cs and run it  using dotnet run alttext.cs &lt;your image path&gt;. Make sure Ollama is running and the image path is correct.<\/p>\n<p>\/\/ alttext.cs<br \/>\n#:package OllamaSharp@5.1.19<\/p>\n<p>using OllamaSharp;<\/p>\n<p>\/\/ set up the client<br \/>\nvar uri = new Uri(&#8220;http:\/\/localhost:11434&#8221;);<br \/>\nvar ollama = new OllamaApiClient(uri);<br \/>\nollama.SelectedModel = &#8220;gemma3&#8221;;<br \/>\nvar chat = new Chat(ollama);<\/p>\n<p>\/\/ read the image file from arguments<br \/>\nbyte[] imageBytes = File.ReadAllBytes(args[0]);<br \/>\nvar imageBytesEnumerable = new List&lt;IEnumerable&lt;byte&gt;&gt; { imageBytes };<\/p>\n<p>\/\/ generate the alt text<br \/>\nvar message = &#8220;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.&#8221;;<br \/>\nawait foreach (var answerToken in chat.SendAsync(message: message, imagesAsBytes: imageBytesEnumerable))<br \/>\n    Console.Write(answerToken);<\/p>\n<p>\/\/ done<br \/>\nConsole.WriteLine($&#8221;&gt;&gt; Ollama done&#8221;);;<\/p>\n<p> Tip: If your image is large, consider resizing it before encoding. This reduces request size and speeds up inference.<\/p>\n<h2> What\u2019s Next?<\/h2>\n<p>With .NET 10 and the power of local AI models like Azure AI Foundry Local Ollama, we\u2019re no longer limited to \u201cchat with AI\u201d scenarios. We can now:<\/p>\n<p>Analyze media<br \/>\nAutomate content generation<br \/>\nBuild offline-capable AI features<\/p>\n<p>This is also a great way to learn! Try switching to different local models, modifying the prompt, or adding a few lines to copy the result to your clipboard. These small tweaks help you experiment and understand how to integrate AI into real-world apps.<\/p>\n<p>To go further:<\/p>\n<p> <strong>Learn More<\/strong>: Explore the <a href=\"https:\/\/aka.ms\/genainet\">Generative AI for Beginners (.NET)<\/a> repo for hands-on lessons and sample projects.<br \/>\n <strong>Watch &amp; Code<\/strong>: Tune in to the <a href=\"https:\/\/dotnet.microsoft.com\/live\/community-standup\">AI &amp; .NET Community StandUp<\/a> to see live demos and join the conversation.<\/p>\n<p>.NET keeps getting more fun, and AI keeps getting more powerful \u2014 especially when you run it locally <\/p>\n<p>Have fun generating smart AltText and making your apps more accessible!<\/p>\n<h3> Resources<\/h3>\n<p>Blog: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-run-app\/\">https:\/\/devblogs.microsoft.com\/dotnet\/announcing-dotnet-run-app\/<\/a><br \/>\nGist Code: <a href=\"https:\/\/gist.github.com\/elbruno\/4396c9ee3e56d1c86d280faa33b8f9fe\">https:\/\/gist.github.com\/elbruno\/4396c9ee3e56d1c86d280faa33b8f9fe<\/a><br \/>\nOllama: <a href=\"https:\/\/ollama.com\/\">https:\/\/ollama.com<\/a><br \/>\nAI Foundry: <a href=\"https:\/\/aka.ms\/aifoundry\">https:\/\/aka.ms\/aifoundry<\/a><\/p>\n<p>The post <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/alttext-generator-csharp-local-models\/\">Local AI + .NET = AltText Magic in One C# Script<\/a> appeared first on <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\">.NET Blog<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Need to generate image descriptions fast? In this post, we\u2019ll show how to combine .NET 10\u2019s new capabilities with local [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[7],"tags":[],"class_list":["post-2201","post","type-post","status-publish","format-standard","hentry","category-dotnet"],"_links":{"self":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts\/2201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/comments?post=2201"}],"version-history":[{"count":0,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts\/2201\/revisions"}],"wp:attachment":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/media?parent=2201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/categories?post=2201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/tags?post=2201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}