Deploying Azure AI Agent Translator in Containers

Deploying Azure AI Agent Translator in Containers




What is Azure AI Translator?

Azure AI Translator is a cloud-based neural machine translation service that is part of the Azure AI services family and can be used with any operating system.



Azure AI Translator features

  • Text Translation
    Execute text translation between supported source and target languages in real time. Create a dynamic dictionary and learn how to prevent translations using the Translator API.

  • Document Translation
    Asynchronous batch translation: Translate batch and complex files while preserving the structure and format of the original documents. The batch translation process requires an Azure Blob storage account with containers for your source and translated documents.
    Synchronous single file translation: Translate a single document file alone or with a glossary file while preserving the structure and format of the original document. The file translation process doesn’t require an Azure Blob storage account. The final response contains the translated document and is returned directly to the calling client.

  • Custom Translator
    Build customized models to translate domain- and industry-specific language, terminology, and style. Create a dictionary (phrase or sentence) for custom translations.



Language Translation Support

Azure AI services support over 100+ world wide. Full language support available in this docs



Why deploying Azure AI Translator in containers?

  • Flexible Deployment: You can run the Translator service anywhere in your own data center, on local devices, or in private clouds where data must stay inside. Perfect for industries with strict rules (like healthcare or finance).

  • Low Latency: Avoid delays by doing translations directly on-site instead of sending them to the cloud.

  • Offline Support: Can be used in places with little or no internet access (like factories, ships, or smart devices).

  • Cost Optimization: Lower your costs for large workloads by running the service yourself instead of paying for cloud usage.

  • Easy to Scale: Grow or shrink the translation service easily using container orchestration tools like Kubernetes.



Prerequisites

Please ensure you have prepare the following requirement to continue

  1. Azure Subscription
  2. Sign up at Azure Portal
  3. Find Azure AI Services and select Translator
  4. Click Create, select Create Translator, configure pricing tier (select F0 for testing)

  5. API Key and Endpoint

  6. Once the resources completed, go to Keys and Endpoint in Azure Portal

  7. Copy the (e.g xt32qsRRVk9SEyoX327KUHFRBIFNd9HF0iMLLpZ5qz2zjmRKVOI7bJQQJ99BCACYeBjFXJ3w3AAAdGcA32C) Key and Endpoint URL (e.g https://.cognitiveservices.azure.com)

Image description

  1. Docker Environment
  2. Install Docker Desktop or Install using CLI Linux
curl -fsSL https://get.docker.com -o install-docker.sh
chmod +x install-docker.sh
sudo sh install-docker.sh
Enter fullscreen mode

Exit fullscreen mode

  1. Command-Line Tools
  2. Terminal (Linux/macOS or PowerShell/Command Prompt (Windows)
  3. curl or Postman for testing APIs

Step 1 – Prepare Azure AI Translator Container Image
Open vscode, create directory and open terminal. Paste the following command to pull container from microsft registry

docker pull mcr.microsoft.com/azure-cognitive-services/translator/text-translation:latestdocker pull mcr.microsoft.com/azure-cognitive-services/translator/text-translation:latest
Enter fullscreen mode

Exit fullscreen mode

Make sure the docker desktop is running.

Step 2 – Run the AI Translator Container
Create file .env and paste API Key and Endpoint

API_KEY=xt32qsRRVk9SEyoX327KUHFRBIFNd9HF0iMLLpZ5qz2zjmRKVOI7bJQQJ99BCACYeBjFXJ3w3AAAdGcA32C
ENDPOINT_URI=https://containertranslator.cognitiveservices.azure.com
LANGUAGES=en,es,fr
EULA=accept
Enter fullscreen mode

Exit fullscreen mode

Once done save and paste the following command to run the container

docker run -d \
--name ai-translator \
-p 5001:5000 \
-p 8000:8000 \
--env-file .env \
--platform linux/amd64 \
mcr.microsoft.com/azure-cognitive-services/translator/text-translation:latest
Enter fullscreen mode

Exit fullscreen mode

Step 3 – Verify Container Health

  1. Check container Status
docker ps -a
Enter fullscreen mode

Exit fullscreen mode

Ensure the container status is up. If something goes wrong, troubleshoot using the following command

docker logs ai-translator
Enter fullscreen mode

Exit fullscreen mode

  1. Test Health Endpoint:
    Run the following command to test endpoint
curl -v http://localhost:8000/health
Enter fullscreen mode

Exit fullscreen mode

Test Translation Endpoint:

curl -X POST "http://localhost:5000/translate?api-version=3.0&from=en&to=es" \
  -H "Ocp-Apim-Subscription-Key: xt32qsRRVk9SEyoX327KUHFRBIFNd9HF0iMLLpZ5qz2zjmRKVOI7bJQQJ99BCACYeBjFXJ3w3AAAdGcA32C" \
  -H "Content-Type: application/json" \
  -d '[{ "Text": "Hello, world!" }]'
Enter fullscreen mode

Exit fullscreen mode

Sample output:

[
  {
    "translations": [
      {
        "text": "¡Hola, mundo!",
        "to": "es"
      }
    ]
  }
]
Enter fullscreen mode

Exit fullscreen mode

Test Language Detection:

curl -X POST "http://localhost:5000/detect?api-version=3.0" \
  -H "Ocp-Apim-Subscription-Key: xt32qsRRVk9SEyoX327KUHFRBIFNd9HF0iMLLpZ5qz2zjmRKVOI7bJQQJ99BCACYeBjFXJ3w3AAAdGcA32C" \
  -H "Content-Type: application/json" \
  -d '[{ "Text": "こんにちは" }]'
Enter fullscreen mode

Exit fullscreen mode

Sample output:

[
  {
    "language": "ja",
    "score": 1,
    "isTranslationSupported": true,
    "isTransliterationSupported": true
  }
]
Enter fullscreen mode

Exit fullscreen mode

The response of the request show that the language is japanese. If we have difficulty to read the Hiragana script, we could use transliteration to render the text in Latin script

Test Transliteration:

curl -X POST "http://localhost:5000/transliterate?api-version=3.0&fromScript=Jpan&toScript=Latn" \
  -H "Ocp-Apim-Subscription-Key: xt32qsRRVk9SEyoX327KUHFRBIFNd9HF0iMLLpZ5qz2zjmRKVOI7bJQQJ99BCACYeBjFXJ3w3AAAdGcA32C" \
  -H "Content-Type: application/json" \
  -d '[{ "Text": "こんにちは" }]'
Enter fullscreen mode

Exit fullscreen mode

Sample output:

[
  {
    "script": "Latn",
    "text": "Kon'nichiwa"
  }
]
Enter fullscreen mode

Exit fullscreen mode

Conclusion

The Azure AI Translator container lets you use cloud AI technology while running it locally. This guide will help you easily add translation, language detection, transliteration features to your systems while keeping full control of your data and setup. For more complex use cases, check out the official docs.

References:



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *