import io import json import os import urllib.request from collections import Counter from google.cloud import vertexai # JSON 파일 경로 json_file_path = "leensoo1nt_service_key.json" # Vertex AI Prediction 서비스 엔드포인트 endpoint = "https://us-central1-aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/us-central1/models/gemini-pro" # Vertex AI Prediction 서비스에 사용할 크레덴셜 credentials, _ = vertexai.auth.google_auth() def extract_product_info(product_name, image_url): # 이미지 URL로부터 이미지 바이트 데이터 읽어오기 image_bytes = io.BytesIO(urllib.request.urlopen(image_url).read()) # 요청 객체 생성 request = { "inputs": [ { "image_bytes": image_bytes.getvalue(), }, {"text": product_name}, ] } # Vertex AI Prediction 서비스에 요청 response = vertexai.prediction.predict( endpoint=endpoint, instances=request, credentials=credentials, ) # 추출 결과 product_description = response["predictions"][0]["text"] product_weight = response["predictions"][0]["weight"] # 홍보 문구 생성 # promotional_phrases = generate_promotional_phrases(product_description) return product_description, promotional_phrases, product_weight # 상품명 및 이미지 URL 입력 product_name = "음식물 쓰레기통" image_url = "https://file.percenty.co.kr/public/652bed8e865b1f32ea62bf1f/products/66063feb4de44a71b14f2b6a/aac95c72-7155-41e9-b27d-f34b51f00a29.jpg" # 정보 추출 및 홍보 문구 생성 product_description, promotional_phrases, product_weight = extract_product_info(product_name, image_url) # 결과 출력 print(f"상품 설명: {product_description}") print(f"홍보 문구: {promotional_phrases}") print(f"상품 무게: {product_weight}")