Moved code to subfolder
This commit is contained in:
1
backend/azure/__init__.py
Normal file
1
backend/azure/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .functions import translate
|
27
backend/azure/functions.py
Normal file
27
backend/azure/functions.py
Normal 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()
|
Reference in New Issue
Block a user