Available in Classic and VPC
This document introduces the Papago Image Translation API examples.
Image Translation (Text)
This section describes the Image Translation (Text) API examples.
Python
The following is a Python-based sample code for the API.
import requests
from requests_toolbelt import MultipartEncoder
import uuid
data = {
'source': 'ko',
'target': 'en',
'image': ('a.png', open('a.png', 'rb'), 'application/octet-stream', {'Content-Transfer-Encoding': 'binary'})
}
m = MultipartEncoder(data, boundary=uuid.uuid4())
headers = {
"Content-Type": m.content_type,
"X-NCP-APIGW-API-KEY-ID": user_client_ID,
"X-NCP-APIGW-API-KEY": user_client_secret
}
url = "https://papago.apigw.ntruss.com/image-to-text/v1/translate"
res = requests.post(url, headers=headers, data=m.to_string())
print(res.text)
Image Translation (Image)
This section describes the Image Translation (Image) API examples.
Python
The following is a Python-based sample code for the API.
import requests
from requests_toolbelt import MultipartEncoder
import uuid
import json
import base64
data = {
'source': 'ko',
'target': 'en',
'image': ('a.png', open('a.png', 'rb'), 'application/octet-stream', {'Content-Transfer-Encoding': 'binary'})
}
m = MultipartEncoder(data, boundary=uuid.uuid4())
headers = {
"Content-Type": m.content_type,
"X-NCP-APIGW-API-KEY-ID": user_client_ID,
"X-NCP-APIGW-API-KEY": user_client_secret
}
url = " https://papago.apigw.ntruss.com/image-to-image/v1/translate"
res = requests.post(url, headers=headers, data=m.to_string())
print(res.text)
# renderedImage -> Output as image file
resObj = json.loads(res.text)
imageStr = resObj.get("data").get("renderedImage")
imgdata = base64.b64decode(imageStr)
filename = 'a_translated.png'
with open(filename, 'wb') as f:
f.write(imgdata)