Papago Image Translation 예제
    • PDF

    Papago Image Translation 예제

    • PDF

    기사 요약

    Classic/VPC 환경에서 이용 가능합니다.

    Papago Image Translation API 예제를 소개합니다.

    Image Translation (Text)

    Image Translation (Text) API 예제를 설명합니다.

    Python

    Python 기반의 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": 유저_클라이언트_아이디,
      "X-NCP-APIGW-API-KEY": 유저_클라이언트_시크릿
    }
    
    url = "https://naveropenapi.apigw.ntruss.com/image-to-text/v1/translate"
    res = requests.post(url, headers=headers, data=m.to_string())
    print(res.text)
    

    Image Translation (Image)

    Image Translation (Image) API 예제를 설명합니다.

    Python

    Python 기반의 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": 유저_클라이언트_아이디,
      "X-NCP-APIGW-API-KEY": 유저_클라이언트_시크릿
    }
    
    url = " https://naveropenapi.apigw.ntruss.com/image-to-image/v1/translate"
    res = requests.post(url, headers=headers, data=m.to_string())
    print(res.text)
    
    # renderedImage -> 이미지 파일로 출력
    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)
    

    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.