👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/language_detection_from_document
AI Language Detection from Documents for C# .NET Applications (Images and PDFs)
🎯 Purpose of the Sample
The Language Detection from Document demo shows how to use LM-Kit.NET with vision-language models (VLMs) to automatically detect the language of text contained in documents, including images and PDF files.
It leverages vision-capable models so you can detect language from scanned documents, photographs, and visual content with minimal code.
👥 Industry Target Audience
This demo is particularly useful for developers and organizations working on:
- Global enterprises: automatically route or localize content based on detected language.
- Mobile and web app development: detect the language of uploaded files (images or PDFs) to provide localized experiences.
- Media and publishing: tag and index documents by language to improve search and content organization.
- Intelligent agent solutions: allow autonomous systems to interpret multilingual document inputs and react without human intervention.
🚀 Problem Solved
Manually determining the language inside documents is inefficient and error-prone, especially when the input arrives as images or PDF files. This sample automates language detection from document content using vision-language models, which is a key capability for agentic workflows (triage, routing, translation, extraction).
The demo provides a selection of VLMs, so you can choose a balance between hardware constraints, latency, and accuracy.
💻 Sample Application Description
The Language Detection from Document demo is a console application that:
- Lets you select a vision-language model (or paste a custom model URI or model ID)
- Downloads and loads the model with progress feedback
- Prompts for a document path (image, PDF, or other supported format)
- Detects the language and prints the result with processing time
✨ Key Features
- Vision-Language Models: Detect language directly from scanned documents and images using VLMs
- Model selection: choose from predefined VLMs, or provide a custom model URI or model ID
- Progress feedback: shows model download and loading progress
- Document-based language detection: detect language from images, PDFs, and documents using a vision model
- Performance metric: prints processing time for each run
🤖 Benefits for Agentic Solutions
Adding document-based language detection to autonomous agents provides:
- Real-time routing: decide what pipeline to run (translation, extraction, summarization) based on language
- Better user experience: respond in the right language without explicit user configuration
- Scalable deployment: run locally when privacy matters or when cloud access is not desired
- Improved context awareness: agents can interpret multilingual document inputs more reliably
🛠️ Getting Started
📋 Prerequisites
- .NET 8.0 or later
- Sufficient VRAM for the selected model (2.5-18 GB depending on model choice)
📥 Download the Project
▶️ Running the Application
Clone the repository:
git clone https://github.com/LM-Kit/lm-kit-net-samplesNavigate to the project directory:
cd lm-kit-net-samples/console_net/language_detection_from_documentBuild and run the application:
dotnet build dotnet runFollow the on-screen prompts to select a vision-language model and provide the path to an image, PDF, or document for language detection.
💡 Example Usage
- Select a model: choose a vision-language model from the menu, or enter a custom model URI or model ID.
- Provide a document path: input the file path to an image, PDF, or document containing text.
- Language detection: the app processes the document using the VLM and detects the language.
- Review results: the detected language and processing time are displayed.
- Repeat or exit: continue with additional documents, or exit the application by submitting an empty input.
By incorporating this demo into your projects, you can enable agents and workflows to automatically detect the language of document inputs (images, PDFs, and scanned documents) and route them to the right next step, such as translation, extraction, or indexing.
📚 Related Content
- Import and Query Documents with Vision: Learn how to process PDFs and images using vision models for content understanding beyond language detection.
- Analyze Images with Vision: Step-by-step guide for using vision language models to extract information from visual content.
- Glossary: Vision Language Models: Core concepts behind models that understand both text and images.
- Text Translator Demo: Natural next step after detecting language, translating the detected content into a target language.