왕현성
코딩발자취
왕현성
전체 방문자
오늘
어제
  • 코딩 (277)
    • Python (71)
    • Java (16)
    • MySQL (34)
    • 인공지능 (48)
      • 머신러닝 (16)
      • 딥러닝 (32)
    • 영상처리 (4)
    • Rest API (21)
    • Android Studio (25)
    • streamlit (13)
    • DevOps (22)
      • AWS (9)
      • PuTTY (5)
      • Git (4)
      • Serverless (2)
      • Docker (2)
    • IT 기술 용어 (6)
    • 디버깅 ( 오류 해결 과정 ) (17)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • matplotlib
  • get_long_description
  • pip install labelme
  • labelme
  • unsupervised
  • tune()
  • 딥러닝
  • imageprocessing
  • ckpt_file
  • alibidetect
  • UnboundLocalError
  • 의료이미징
  • 영상처리역사
  • yolov8
  • alibi-detection
  • PIL
  • pytorch
  • 기상탐사
  • numpy
  • OpenCV
  • maskimage
  • 비지도학습
  • labelme UnocodeDecodeError
  • 영상처리
  • TensorFlow
  • 영상기술
  • 컴퓨터비전
  • ComputerVision
  • encoding='utf-8'
  • PYTHON

최근 댓글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
왕현성

코딩발자취

CLOVA Summary를 활용해 리뷰 요약 API 만들기
Rest API

CLOVA Summary를 활용해 리뷰 요약 API 만들기

2023. 4. 3. 10:53
728x90

CLOVA Summary 서비스란?

CLOVA Summary는 NLP(Natural Language Processing, 자연어 처리) 기술과 그래프 기반 랭킹 알고리즘 기반으로 문서에서 중요한 문장을 가려내고, 이를 기준으로 요약 결과를 추출하는 서비스입니다.

 

리뷰 요약 서비스 만들기

 

1. 네이버 클라우드 플랫폼 ncloud.com 접속 후 로그인합니다.

 

NAVER CLOUD PLATFORM

cloud computing services for corporations, IaaS, PaaS, SaaS, with Global region and Security Technology Certification

www.ncloud.com

 

2. 우측 상단 콘솔 (Console) 접속 후 [ Product & Service > AI·NAVER API ] 순서로 이동합니다.

 

3. CLOVA Summary 서비스를 활성화합니다.

 

[ Application 등록 ] 버튼을 클릭하고 CLOVA Summary 서비스를 활성화 합니다.

 

Apllication 등록 관련 자세한 안내는 아래 공식 매뉴얼 페이지를 참조 바랍니다.​

- 매뉴얼 링크 : https://guide.ncloud-docs.com/docs/naveropenapiv3-application

 

Application 사용 가이드

 

guide.ncloud-docs.com

 

4. 생성한 Summary 앱을 클릭하여 인증정보를 확인합니다.​

Client ID (X-NCP-APIGW-API-KEY-ID) 와 Client Secret (X-NCP-APIGW-API-KEY) 정보를 메모장에 복사합니다.

 

 

 

 

5. 문서를 RESTful API로 전달하여 요약 결과를 리턴해주는 API를 사용합니다.

 

아래 코드는 제가 이용한 리뷰 요약 기능 API 코드입니다.

 

# 요약된 리뷰 가져오기.
class ReviewSummaryResource(Resource):
    @jwt_required()
    
    def get(self,hotelId):

        try :
            connection = get_connection()

            query = '''SELECT content FROM reviews
                    where hotelId=%s;'''
            
            record = (hotelId,)

            ## 중요!!!! select 문은 
            ## 커서를 가져올 때 dictionary = True로 해준다
            cursor = connection.cursor(dictionary=True)

            cursor.execute(query,record)

            resultList=cursor.fetchall()

            contents = [r['content'] for r in resultList]

            all_content = ' '.join(contents)

            print(all_content)
            
            cursor.close()
            connection.close()
        except Error as e :
            print(e)
            cursor.close()
            connection.close()
            return{"result":"fail","error":str(e)}, 500
        
        # 문서 요약 API ( 리뷰 요약 )


        headers = {

            "X-NCP-APIGW-API-KEY-ID": Config.client_id,
            "X-NCP-APIGW-API-KEY": Config.client_secret,
            "Content-Type": "application/json"
        }
        language = "ko"

        

        url= "https://naveropenapi.apigw.ntruss.com/text-summary/v1/summarize" 

        summaryData = {"document":{
            "content":all_content},
            "option":{
            "language":language
            }
        }

        print(json.dumps(summaryData, indent=4, sort_keys=True))

        response = requests.post(url, data=json.dumps(summaryData), headers=headers)

        # rescode = response.status_code
        # print(response)
        # print(rescode)

        json_data = json.loads(response.text)
        
        

        if 'summary' in json_data:
            summary = json_data['summary']
            print(summary)
        else:
            print("Failed to get summary data")
            summary = ""  # 초기화 코드 추가
        
        return {"result" : 'success','summary':summary}, 200

앱에서 적용한 부분의 사진입니다. 특정 호텔에 대한 모든 리뷰를 가져와서 요약하는 기능입니다.

'Rest API' 카테고리의 다른 글

chatGPT API(gpt-3.5-turbo)를 활용한 상담기능 서비스 개발  (0) 2023.04.03
AWS Rekognition 얼굴비교, 이미지 내 텍스트 추출하기  (0) 2023.02.21
Naver Open API - 뉴스 검색 API , 파파고 번역 API 사용하기  (0) 2023.01.13
AmazonRekognition을 사용하여 객체탐지(Object detection) / 사진과 문장을 업로드하는 SNS의 Posting API 개발  (0) 2023.01.13
AmazonRekognition을 사용하여 객체탐지(Object detection) / 자동 태그 API 개발  (0) 2023.01.13
    'Rest API' 카테고리의 다른 글
    • chatGPT API(gpt-3.5-turbo)를 활용한 상담기능 서비스 개발
    • AWS Rekognition 얼굴비교, 이미지 내 텍스트 추출하기
    • Naver Open API - 뉴스 검색 API , 파파고 번역 API 사용하기
    • AmazonRekognition을 사용하여 객체탐지(Object detection) / 사진과 문장을 업로드하는 SNS의 Posting API 개발
    왕현성
    왕현성
    AI 머신비전 학습일지

    티스토리툴바