initial commit

This commit is contained in:
2023-03-08 00:17:34 +01:00
commit 69416eb896
12 changed files with 321 additions and 0 deletions

1
azure/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .functions import translate

27
azure/functions.py Normal file
View File

@@ -0,0 +1,27 @@
import requests
import uuid
from config import Settings
def translate(data):
constructed_url = Settings().AZURE_ENDPOINT + '/translate'
params = {
'api-version': '3.0',
'from': data.language_from,
'to': [data.language_to]
}
headers = {
'Ocp-Apim-Subscription-Key': Settings().AZURE_KEY,
'Ocp-Apim-Subscription-Region': Settings().AZURE_LOCATION,
'Content-type': 'application/json',
'X-ClientTraceId': str(uuid.uuid4())
}
body = [{
'text': data.requested_text
}]
request = requests.post(constructed_url, params=params, headers=headers, json=body)
return request.json()