36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
# Sample script to translate a document on azure
|
|
|
|
import requests
|
|
|
|
endpoint = "https://translateazuretesting.cognitiveservices.azure.com/translator/text/batch/v1.0"
|
|
key = '0cad779367054a3cb47d374de2ad110c'
|
|
path = '/batches'
|
|
constructed_url = endpoint + path
|
|
|
|
payload= {
|
|
"inputs": [
|
|
{
|
|
"source": {
|
|
"sourceUrl": "https://translatedatastore.blob.core.windows.net/translate-source?sp=rl&st=2023-01-10T20:06:57Z&se=2024-01-11T04:06:57Z&spr=https&sv=2021-06-08&sr=c&sig=payaBXqpPpVZGG4y4h8Bncjlfzf5T3JN2HFbtCCXMeI%3D",
|
|
"storageSource": "AzureBlob",
|
|
"language": "fr"
|
|
},
|
|
"targets": [
|
|
{
|
|
"targetUrl": "https://translatedatastore.blob.core.windows.net/translate-output?sp=rwl&st=2023-01-10T20:07:41Z&se=2024-01-11T04:07:41Z&spr=https&sv=2021-06-08&sr=c&sig=C8Ivgssa4W5AaeKtE4%2B3xZElNPa%2FJxiXo93897dpBxI%3D",
|
|
"storageSource": "AzureBlob",
|
|
"category": "general",
|
|
"language": "en"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
headers = {
|
|
'Ocp-Apim-Subscription-Key': key,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
response = requests.post(constructed_url, headers=headers, json=payload)
|
|
|
|
print(f'response status code: {response.status_code}\nresponse status: {response.reason}\nresponse headers: {response.headers}') |