Deploy a Flask AI web app to Azure App Service
In this blog post, you will deploy an AI Flask application app to Azure App Service using Visual Studio Code.
Welcome to part 2 of the “Digitize and translate your notes with Azure Cognitive Services and Python” series. In the previous blog post, you explored the pre-trained models of Azure Computer Vision for Optical Character Recognition and extracted handwritten text from an image using the READ API and the Computer Vision SDK for Python.
In this article, you will translate the extracted text from your handwritten notes using Translator. You will:
To complete the exercise, you will need to install:
Translator is a cloud-based service that is part of the Azure Cognitive Services and enables you to perform language translation and other language-related operations.
Study the following sketch note to learn more about the capabilities of the Translator service.
You can find more information and how-to-guides about Translator on Microsoft Learn and Microsoft Docs.
Create a configuration file and add the authentication key for your Cognitive Services resource, and the location in which the service is deployed. You can copy both values from the Keys and Endpoint page of your Cognitive Services resource.
Create a new Python script, for example translator-demo.py and open it in Visual Studio Code or in your preferred editor.
Want to view the whole code at once? You can find it on GitHub.
Import the following llibraries.
|
|
Add the following code to load the Cognitive Services key and region from the configuration file and specify the endpoint.
|
|
Define the detect_language
function which automatically detects the language of the source text and returns the language code.
|
|
Define the translate
function which translates the given text from the source_language
into the target_language
and returns the translated text.
|
|
from
parameter in your translation request, the Translator will attempt to detect the language of the given text.Add the following code and run the script:
|
|
translate
function so that it returns the translation of the given text into two or more language. If you need some help, you can check the challenge.py script in my GitHub repo.In this section, you will build a Python app that uses the READ API to extract handwritten text from notes and then translates the extracted text using the Translator service.
First download the images used in the following examples from my GitHub repository.
Next, create a new Python script, for example read-translate.py and use the get_text
function from the previous post and the detect_language
and translate
functions you wrote previously to extract and translate the text of the given images.
Add the following lines of code in the main
function to test your app:
|
|
In this article, you learned how to use Azure Translator to detect the language of a given text and translate text from the source language into one or more languages. Then you built a Python app that uses the Azure Computer Vision READ API to extract text from handwritten notes and the Translator service to translate the extracted text.
In the next article, you will learn how to build and deploy a Flask AI web app that uses the READ API and the Azure Translator.
Check out the other parts of the “Digitize and translate your notes with Azure Cognitive Services and Python” series:
If you have finished learning, you can delete the resource group from your Azure subscription:
In the Azure Portal, select Resource groups on the right menu and then select the resource group that you have created.
Click Delete resource group.
In this blog post, you will deploy an AI Flask application app to Azure App Service using Visual Studio Code.
In this blog post, you will build a website using Flask and Azure Cognitive Services to extract and translate text from notes.
In this article, you will explore the Azure Translator and use Python to translate text and identify the language of the source text.
This post will take you through the newest Read OCR API of Azure Computer Vision, which is used for extracting text from images.