diff --git a/smarketing-ai/app.py b/smarketing-ai/app.py index 218c44d..09ed94e 100644 --- a/smarketing-ai/app.py +++ b/smarketing-ai/app.py @@ -22,11 +22,6 @@ def create_app(): # CORS 설정 CORS(app) - # 업로드 폴더 생성 - os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) - os.makedirs(os.path.join(app.config['UPLOAD_FOLDER'], 'temp'), exist_ok=True) - os.makedirs('templates/poster_templates', exist_ok=True) - # 서비스 인스턴스 생성 poster_service = PosterService() sns_content_service = SnsContentService() diff --git a/smarketing-ai/test.py b/smarketing-ai/test.py index 019f76a..5b38fd7 100644 --- a/smarketing-ai/test.py +++ b/smarketing-ai/test.py @@ -1,42 +1,53 @@ -""" -마케팅 팁 API 테스트 스크립트 -""" +# openai_simple_test.py import requests -import json +import os +from utils.ai_client import AIClient +import openai +import base64 - -def test_marketing_tip_api(): - """마케팅 팁 API 테스트""" - - # 테스트 데이터 - test_data = { - "store_name": "더블샷 카페", - "business_type": "카페", - "location": "서울시 강남구 역삼동", - "seat_count": 30, - } - - # API 호출 - url = "http://localhost:5001/api/v1/generate-marketing-tip" - headers = { - "Content-Type": "application/json", - "Authorization": "Bearer dummy-key" - } - +def openai_test(prompt: str,): try: - response = requests.post(url, json=test_data, headers=headers) - - print(f"Status Code: {response.status_code}") - print(f"Response: {json.dumps(response.json(), ensure_ascii=False, indent=2)}") - - if response.status_code == 200: - print("✅ 테스트 성공!") + openai_api_key = os.getenv('OPENAI_API_KEY') + if openai_api_key: + openai_client = openai.OpenAI(api_key=openai_api_key) else: - print("❌ 테스트 실패!") - - except Exception as e: - print(f"❌ 테스트 오류: {str(e)}") + openai_client = None + if not openai_client: + raise Exception("OpenAI API 키가 설정되지 않았습니다.") + + response = openai_client.images.generate( + model="dall-e-3", + prompt=prompt, + size="1024x1024", + n=1, + ) + + + # # Azure Blob Storage에 업로드 + # blob_url = self.blob_client.upload_image(image_data, 'png') + + print(f"✅ 이미지 생성 및 업로드 완료: {response}") + return response + + except Exception as e: + raise Exception(f"이미지 생성 실패: {str(e)}") if __name__ == "__main__": - test_marketing_tip_api() \ No newline at end of file + # API 키 확인 + if not os.getenv('OPENAI_API_KEY'): + print("⚠️ 환경변수 OPENAI_API_KEY가 설정되지 않았습니다.") + print("코드 상단의 'your-api-key-here' 부분에 실제 API 키를 입력하거나") + print("export OPENAI_API_KEY='실제키' 로 환경변수를 설정해주세요.\n") + + openai_test("""아래 정보를 활용하여 사람 그림을 그려주세요. +- 성별 : 여자 +- 나이 : 27살 +- 머리 : 머리 긴 편, 아래쪽에 웨이브, 앞머리 약간 있음 +- 동양인 +- 쌍커풀 없음 +- 밝은 이미지 +- 웃는 모습 +현실적인 모습으로 그려주세요. +사진에 글자가 절대 들어가지 않게 해주세요. +""") \ No newline at end of file diff --git a/smarketing-ai/uploads/temp/temp_1da3ee47-4c9f-4029-b9e7-3d588d77caaa.jpg b/smarketing-ai/uploads/temp/temp_1da3ee47-4c9f-4029-b9e7-3d588d77caaa.jpg new file mode 100644 index 0000000..628c52a Binary files /dev/null and b/smarketing-ai/uploads/temp/temp_1da3ee47-4c9f-4029-b9e7-3d588d77caaa.jpg differ