Azure AI document translation — Batch

Published Nov 12 2021 01:29 PM 1,432 Views

Translate document in batch with Cognitive services

  • Batch translate pdf document from one language to another

Use Case

  • The below architecture shows how to do batch document translations
  • Here i have translationinput as input container for document
  • Then i created translationoutput as output container to store the output
  • For both create SAS key with Read and write.
  • At least read for translationinput
  • Write for translationoutput

Architecture

BalamuruganBalakreshnan_5-1635600901083.jpeg

 

Steps

  • Create a new logic app
  • Create a new workload
  • create a new connection for blob storage where you have the data
  • to trigger the flow start when a file is uploaded
  • i am reading the pdf file — this step is not necessary
BalamuruganBalakreshnan_6-1635600901057.jpeg

 

  • Now drag HTTP to send the translation request
  • Provide Ocp-Apim-Subscription-Key key which is from cognitive services
  • then provide the URL
https://cognitivesvcname.cognitiveservices.azure.com/translator/text/batch/v1.0/batches
 
  • Next configure the input and outputs
  • Here i am converting to 2 different languages
{
"inputs": [
{
"source": {
"sourceUrl": "https://storagename.blob.core.windows.net/translateinput?sp=racwl&st=2020-10-19T21:27:53Z&se=2020-10-21T05:27:53Z&spr=https&sv=2020-08-04&sr=c&sig=xxxxxxxxxxxxxxxxxxxxxxx"
},
"targets": [
{
"language": "fr",
"targetUrl": "https://storagename.blob.core.windows.net/translateoutput?sp=racwl&st=2020-10-19T21:29:02Z&se=2020-10-21T05:29:02Z&spr=https&sv=2020-08-04&sr=c&sig=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"language": "id",
"targetUrl": "https://storaegname.blob.core.windows.net/translateoutput?sp=racwl&st=2020-10-19T21:29:02Z&se=2020-10-21T05:29:02Z&spr=https&sv=2020-08-04&sr=c&sig=xxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
}
]
}
 
  • source and targets are full blob sas keys
  • the above SAS keys are fake and just for sample
BalamuruganBalakreshnan_7-1635600901109.jpeg

 

  • Next wait for 30 seconds
BalamuruganBalakreshnan_8-1635600901117.jpeg

 

  • Now lets get the status
  • From the above batch submission, response header will have the URL to query for status
@{outputs('HTTP')['headers']?['Operation-Location']}
 
  • Make sure send the Ocp-Apim-Subscription-Key
BalamuruganBalakreshnan_9-1635600901122.jpeg

 

  • Now save and run the logic app.
  • Once successful then go out storage explorer and see the translationoutput container for processed pdf file.
  • Done

Original article: Samples2021/Doctranslation.md at main · balakreshnan/Samples2021 (github.com)

%3CLINGO-SUB%20id%3D%22lingo-sub-2903708%22%20slang%3D%22en-US%22%3EAzure%20AI%20document%20translation%E2%80%8A%E2%80%94%E2%80%8ABatch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2903708%22%20slang%3D%22en-US%22%3E%3CH3%20class%3D%22graf%20graf--h3%22%20id%3D%22toc-hId--2096784746%22%20id%3D%22toc-hId--2091338511%22%3ETranslate%20document%20in%20batch%20with%20Cognitive%20services%3C%2FH3%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EBatch%20translate%20pdf%20document%20from%20one%20language%20to%20another%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20class%3D%22graf%20graf--h3%22%20id%3D%22toc-hId-390728087%22%20id%3D%22toc-hId-396174322%22%3EUse%20Case%3C%2FH3%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EThe%20below%20architecture%20shows%20how%20to%20do%20batch%20document%20translations%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EHere%20i%20have%20translationinput%20as%20input%20container%20for%20document%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EThen%20i%20created%20translationoutput%20as%20output%20container%20to%20store%20the%20output%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EFor%20both%20create%20SAS%20key%20with%20Read%20and%20write.%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EAt%20least%20read%20for%20translationinput%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EWrite%20for%20translationoutput%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20class%3D%22graf%20graf--h3%22%20id%3D%22toc-hId--1416726376%22%20id%3D%22toc-hId--1411280141%22%3EArchitecture%3C%2FH3%3E%0A%3CFIGURE%20class%3D%22graf%20graf--figure%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22BalamuruganBalakreshnan_5-1635600901083.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F321841i4A1DA0F4F0CC27C3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22BalamuruganBalakreshnan_5-1635600901083.jpeg%22%20alt%3D%22BalamuruganBalakreshnan_5-1635600901083.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FFIGURE%3E%0A%3CH3%20class%3D%22graf%20graf--h3%22%20id%3D%22toc-hId-1070786457%22%20id%3D%22toc-hId-1076232692%22%3ESteps%3C%2FH3%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ECreate%20a%20new%20logic%20app%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ECreate%20a%20new%20workload%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3Ecreate%20a%20new%20connection%20for%20blob%20storage%20where%20you%20have%20the%20data%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3Eto%20trigger%20the%20flow%20start%20when%20a%20file%20is%20uploaded%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3Ei%20am%20reading%20the%20pdf%20file%E2%80%8A%E2%80%94%E2%80%8Athis%20step%20is%20not%20necessary%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CFIGURE%20class%3D%22graf%20graf--figure%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22BalamuruganBalakreshnan_6-1635600901057.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F321843i03BB4F32EA441841%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22BalamuruganBalakreshnan_6-1635600901057.jpeg%22%20alt%3D%22BalamuruganBalakreshnan_6-1635600901057.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FFIGURE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ENow%20drag%20HTTP%20to%20send%20the%20translation%20request%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EProvide%20Ocp-Apim-Subscription-Key%20key%20which%20is%20from%20cognitive%20services%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3Ethen%20provide%20the%20URL%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CPRE%20class%3D%22graf%20graf--pre%22%3E%3CCODE%20class%3D%22markup--code%20markup--pre-code%22%3E%3CA%20class%3D%22markup--anchor%20markup--pre-anchor%22%20href%3D%22https%3A%2F%2Fcognitivesvcname.cognitiveservices.azure.com%2Ftranslator%2Ftext%2Fbatch%2Fv1.0%2Fbatches%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%20data-href%3D%22https%3A%2F%2Fcognitivesvcname.cognitiveservices.azure.com%2Ftranslator%2Ftext%2Fbatch%2Fv1.0%2Fbatches%22%3Ehttps%3A%2F%2Fcognitivesvcname.cognitiveservices.azure.com%2Ftranslator%2Ftext%2Fbatch%2Fv1.0%2Fbatches%3C%2FA%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CPRE%20class%3D%22graf%20graf--pre%20graf--empty%22%3E%26nbsp%3B%3C%2FPRE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ENext%20configure%20the%20input%20and%20outputs%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EHere%20i%20am%20converting%20to%202%20different%20languages%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CPRE%20class%3D%22graf%20graf--pre%22%3E%3CCODE%20class%3D%22markup--code%20markup--pre-code%22%3E%7B%3CBR%20%2F%3E%20%20%22inputs%22%3A%20%5B%3CBR%20%2F%3E%20%20%20%20%7B%3CBR%20%2F%3E%20%20%20%20%20%20%22source%22%3A%20%7B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%22sourceUrl%22%3A%20%22https%3A%2F%2Fstoragename.blob.core.windows.net%2Ftranslateinput%3Fsp%3Dracwl%26amp%3Bst%3D2020-10-19T21%3A27%3A53Z%26amp%3Bse%3D2020-10-21T05%3A27%3A53Z%26amp%3Bspr%3Dhttps%26amp%3Bsv%3D2020-08-04%26amp%3Bsr%3Dc%26amp%3Bsig%3Dxxxxxxxxxxxxxxxxxxxxxxx%22%3CBR%20%2F%3E%20%20%20%20%20%20%7D%2C%3CBR%20%2F%3E%20%20%20%20%20%20%22targets%22%3A%20%5B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%7B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%22language%22%3A%20%22fr%22%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%22targetUrl%22%3A%20%22https%3A%2F%2Fstoragename.blob.core.windows.net%2Ftranslateoutput%3Fsp%3Dracwl%26amp%3Bst%3D2020-10-19T21%3A29%3A02Z%26amp%3Bse%3D2020-10-21T05%3A29%3A02Z%26amp%3Bspr%3Dhttps%26amp%3Bsv%3D2020-08-04%26amp%3Bsr%3Dc%26amp%3Bsig%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%22%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%7D%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%7B%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%22language%22%3A%20%22id%22%2C%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%22targetUrl%22%3A%20%22https%3A%2F%2Fstoraegname.blob.core.windows.net%2Ftranslateoutput%3Fsp%3Dracwl%26amp%3Bst%3D2020-10-19T21%3A29%3A02Z%26amp%3Bse%3D2020-10-21T05%3A29%3A02Z%26amp%3Bspr%3Dhttps%26amp%3Bsv%3D2020-08-04%26amp%3Bsr%3Dc%26amp%3Bsig%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxx%22%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%7D%3CBR%20%2F%3E%20%20%20%20%20%20%5D%3CBR%20%2F%3E%20%20%20%20%7D%3CBR%20%2F%3E%20%20%5D%3CBR%20%2F%3E%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CPRE%20class%3D%22graf%20graf--pre%20graf--empty%22%3E%26nbsp%3B%3C%2FPRE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3Esource%20and%20targets%20are%20full%20blob%20sas%20keys%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3Ethe%20above%20SAS%20keys%20are%20fake%20and%20just%20for%20sample%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CFIGURE%20class%3D%22graf%20graf--figure%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22BalamuruganBalakreshnan_7-1635600901109.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F321842i8BE4AD184608587E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22BalamuruganBalakreshnan_7-1635600901109.jpeg%22%20alt%3D%22BalamuruganBalakreshnan_7-1635600901109.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FFIGURE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ENext%20wait%20for%2030%20seconds%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CFIGURE%20class%3D%22graf%20graf--figure%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22BalamuruganBalakreshnan_8-1635600901117.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F321845i8F99B4C6804AA3AF%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22BalamuruganBalakreshnan_8-1635600901117.jpeg%22%20alt%3D%22BalamuruganBalakreshnan_8-1635600901117.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FFIGURE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ENow%20lets%20get%20the%20status%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EFrom%20the%20above%20batch%20submission%2C%20response%20header%20will%20have%20the%20URL%20to%20query%20for%20status%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CPRE%20class%3D%22graf%20graf--pre%22%3E%3CCODE%20class%3D%22markup--code%20markup--pre-code%22%3E%40%7Boutputs('HTTP')%5B'headers'%5D%3F%5B'Operation-Location'%5D%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CPRE%20class%3D%22graf%20graf--pre%20graf--empty%22%3E%26nbsp%3B%3C%2FPRE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EMake%20sure%20send%20the%20Ocp-Apim-Subscription-Key%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CFIGURE%20class%3D%22graf%20graf--figure%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22BalamuruganBalakreshnan_9-1635600901122.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F321846iD7416BF0092EDCFB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22BalamuruganBalakreshnan_9-1635600901122.jpeg%22%20alt%3D%22BalamuruganBalakreshnan_9-1635600901122.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FFIGURE%3E%0A%3CUL%20class%3D%22postList%22%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3ENow%20save%20and%20run%20the%20logic%20app.%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EOnce%20successful%20then%20go%20out%20storage%20explorer%20and%20see%20the%20translationoutput%20container%20for%20processed%20pdf%20file.%3C%2FLI%3E%0A%3CLI%20class%3D%22graf%20graf--li%22%3EDone%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%20class%3D%22graf%20graf--p%22%3EOriginal%20article%3A%20%3CA%20class%3D%22markup--anchor%20markup--p-anchor%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fbalakreshnan%2FSamples2021%2Fblob%2Fmain%2FDocumentTranslation%2FDoctranslation.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%20data-href%3D%22https%3A%2F%2Fgithub.com%2Fbalakreshnan%2FSamples2021%2Fblob%2Fmain%2FDocumentTranslation%2FDoctranslation.md%22%3ESamples2021%2FDoctranslation.md%20at%20main%20%C2%B7%20balakreshnan%2FSamples2021%20(github.com)%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2903708%22%20slang%3D%22en-US%22%3E%3CH3%20class%3D%22graf%20graf--h3%22%20id%3D%22toc-hId--731221771%22%3EAzure%20AI%20document%20translation%E2%80%8A%E2%80%94%E2%80%8ABatch%3C%2FH3%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2903708%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Machine%20Learning%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECognitive%20Services%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Nov 12 2021 01:29 PM