|
| 1 | +--- |
| 2 | +title: How to use image-to-text models in the model catalog |
| 3 | +titleSuffix: Azure AI Foundry |
| 4 | +description: Learn how to use image-to-text models from the AI Foundry model catalog. |
| 5 | +manager: scottpolly |
| 6 | +author: msakande |
| 7 | +reviewer: frogglew |
| 8 | +ms.service: azure-ai-model-inference |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 05/02/2025 |
| 11 | +ms.author: mopeakande |
| 12 | +ms.reviewer: frogglew |
| 13 | +ms.custom: references_regions, tool_generated |
| 14 | +--- |
| 15 | + |
| 16 | +# How to use image-to-text models in the model catalog |
| 17 | + |
| 18 | +This article explains how to use _image-to-text_ models in the AI Foundry model catalog. |
| 19 | + |
| 20 | +Image-to-text models are designed to analyze images and generate descriptive text based on what they see. Think of them as a combination of a camera and a writer. You provide an image as an input to the model, and the model looks at the image and identifies different elements within it, like objects, people, scenes, and even text. Based on its analysis, the model then generates a written description of the image, summarizing what it sees. |
| 21 | + |
| 22 | +Image-to-text models excel at various use cases such as accessibility features, content organization (tagging), creating product and educational visual descriptions, and digitizing content via Optical Character Recognition (OCR). One might say image-to-text models bridge the gap between visual content and written language, making information more accessible and easier to process in various contexts. |
| 23 | + |
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +To use image models in your application, you need: |
| 27 | + |
| 28 | +- An Azure subscription with a valid payment method. Free or trial Azure subscriptions won't work. If you don't have an Azure subscription, create a [paid Azure account](https://azure.microsoft.com/pricing/purchase-options/pay-as-you-go) to begin. |
| 29 | + |
| 30 | +- An [Azure AI Foundry project](create-projects.md). |
| 31 | + |
| 32 | +- An image model deployment on Azure AI Foundry. |
| 33 | + |
| 34 | + - This article uses a __Mistral OCR__ model deployment. |
| 35 | + |
| 36 | +- The endpoint URL and key. |
| 37 | + |
| 38 | +## Use image-to-text model |
| 39 | + |
| 40 | +1. Authenticate using an API key. First, deploy the model to generate the endpoint URL and an API key to authenticate against the service. In this example, the endpoint and key are strings holding the endpoint URL and the API key. The API endpoint URL and API key can be found on the **Deployments + Endpoint** page once the model is deployed. |
| 41 | + |
| 42 | + If you're using Bash: |
| 43 | + |
| 44 | + ```bash |
| 45 | + export AZURE_API_KEY = "<your-api-key>" |
| 46 | + ``` |
| 47 | + |
| 48 | + If you're in PowerShell: |
| 49 | + |
| 50 | + ```powershell |
| 51 | + $Env:AZURE_API_KEY = "<your-api-key>" |
| 52 | + ``` |
| 53 | + |
| 54 | + If you're using Windows command prompt: |
| 55 | + |
| 56 | + ``` |
| 57 | + export AZURE_API_KEY = "<your-api-key>" |
| 58 | + ``` |
| 59 | + |
| 60 | +1. Run a basic code sample. Different image models accept different data formats. In this example, _Mistral OCR 25.03_ supports only base64 encoded data; document url or image url isn't supported. Paste the following code into a shell. |
| 61 | + |
| 62 | + ```http |
| 63 | + curl --request POST \ |
| 64 | + --url https://<your_serverless_endpoint>/v1/ocr \ |
| 65 | + --header 'Authorization: <api_key>' \ |
| 66 | + --header 'Content-Type: Application/json' \ |
| 67 | + --data '{ |
| 68 | + "model": "mistral-ocr-2503", |
| 69 | + "document": { |
| 70 | + "type": "document_url", |
| 71 | + "document_name": "test", |
| 72 | + "document_url": "data:application/pdf;base64,JVBER... <replace with your base64 encoded image data>" |
| 73 | + } |
| 74 | + }' |
| 75 | + ``` |
| 76 | +
|
| 77 | +## More code samples for Mistral OCR 25.03 |
| 78 | +
|
| 79 | +To process PDF files: |
| 80 | +
|
| 81 | +```bash |
| 82 | +# Read the pdf file |
| 83 | +input_file_path="assets/2201.04234v3.pdf" |
| 84 | +base64_value=$(base64 "$input_file_path") |
| 85 | +input_base64_value="data:application/pdf;base64,${base64_value}" |
| 86 | +# echo $input_base64_value |
| 87 | + |
| 88 | +# Prepare JSON data |
| 89 | +payload_body=$(cat <<EOF |
| 90 | +{ |
| 91 | + "model": "mistral-ocr-2503", |
| 92 | + "document": { |
| 93 | + "type": "document_url", |
| 94 | + "document_url": "$input_base64_value" |
| 95 | + }, |
| 96 | + "include_image_base64": true |
| 97 | +} |
| 98 | +EOF |
| 99 | +) |
| 100 | +
|
| 101 | +echo "$payload_body" | curl ${AZURE_AI_CHAT_ENDPOINT}/v1/ocr \ |
| 102 | + -H "Content-Type: application/json" \ |
| 103 | + -H "Authorization: Bearer ${AZURE_AI_CHAT_KEY}" \ |
| 104 | + -d @- -o ocr_pdf_output.json |
| 105 | +``` |
| 106 | +
|
| 107 | +To process an image file: |
| 108 | +
|
| 109 | +```bash |
| 110 | +# Read the image file |
| 111 | +input_file_path="assets/receipt.png" |
| 112 | +base64_value=$(base64 "$input_file_path") |
| 113 | +input_base64_value="data:application/png;base64,${base64_value}" |
| 114 | +# echo $input_base64_value |
| 115 | + |
| 116 | +# Prepare JSON data |
| 117 | +payload_body=$(cat <<EOF |
| 118 | +{ |
| 119 | + "model": "mistral-ocr-2503", |
| 120 | + "document": { |
| 121 | + "type": "image_url", |
| 122 | + "image_url": "$input_base64_value" |
| 123 | + }, |
| 124 | + "include_image_base64": true |
| 125 | +} |
| 126 | +EOF |
| 127 | +) |
| 128 | + |
| 129 | +# Process the base64 data with ocr endpoint |
| 130 | +echo "$payload_body" | curl ${AZURE_AI_CHAT_ENDPOINT}/v1/ocr \ |
| 131 | + -H "Content-Type: application/json" \ |
| 132 | + -H "Authorization: Bearer ${AZURE_AI_CHAT_KEY}" \ |
| 133 | + -d @- -o ocr_png_output.json |
| 134 | +``` |
| 135 | +
|
| 136 | +## Model-specific parameters |
| 137 | +
|
| 138 | +Some image-to-text models only support specific data formats. Mistral OCR 25.03, for example, requires `base64 encoded image data` for their `document_url` parameter. The following table lists the supported and unsupported data formats for image models in the model catalog. |
| 139 | +
|
| 140 | +| Model | Supported | Not supported | |
| 141 | +| :---- | ----- | ----- | |
| 142 | +| Mistral OCR 25.03 | base64 encoded image data | document url, image url | |
| 143 | +
|
| 144 | +
|
| 145 | +
|
| 146 | +## Related content |
| 147 | +
|
| 148 | +- [How to use image generation models on Azure OpenAI](../../ai-services/openai/how-to/dall-e.md) |
| 149 | +
|
0 commit comments