From 8aa43221d235fb60c6f324348d281b7bb4f8ccc5 Mon Sep 17 00:00:00 2001 From: thug0bin Date: Tue, 3 Mar 2026 00:02:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20AI=20=EC=B6=94=EC=B2=9C=EC=97=90=20=EC=A0=9C?= =?UTF-8?q?=ED=92=88=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /api/recommendation API에서 product_images DB 조회 - 제품명 매칭으로 썸네일 이미지 반환 - 이미지 있으면 실제 사진, 없으면 💊 이모지 표시 --- backend/app.py | 25 ++++++++++++++++++++++++- backend/templates/my_page.html | 16 +++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/backend/app.py b/backend/app.py index e7cf0a3..576cfcc 100644 --- a/backend/app.py +++ b/backend/app.py @@ -2409,13 +2409,36 @@ def api_get_recommendation(user_id): """, (now, rec['id'])) conn.commit() + # 제품 이미지 조회 (product_images DB에서 제품명으로 검색) + product_image = None + try: + img_db_path = os.path.join(os.path.dirname(__file__), 'db', 'product_images.db') + img_conn = sqlite3.connect(img_db_path) + img_conn.row_factory = sqlite3.Row + img_cursor = img_conn.cursor() + + product_name = rec['recommended_product'] + # 제품명으로 이미지 검색 (LIKE 검색으로 부분 매칭) + img_cursor.execute(""" + SELECT thumbnail_base64 FROM product_images + WHERE product_name LIKE ? AND thumbnail_base64 IS NOT NULL + LIMIT 1 + """, (f'%{product_name}%',)) + img_row = img_cursor.fetchone() + if img_row: + product_image = img_row['thumbnail_base64'] + img_conn.close() + except Exception as e: + logging.warning(f"[AI추천] 제품 이미지 조회 실패: {e}") + return jsonify({ 'success': True, 'has_recommendation': True, 'recommendation': { 'id': rec['id'], 'product': rec['recommended_product'], - 'message': rec['recommendation_message'] + 'message': rec['recommendation_message'], + 'image': product_image # base64 썸네일 이미지 (없으면 null) } }) diff --git a/backend/templates/my_page.html b/backend/templates/my_page.html index f17e35a..8e4c397 100644 --- a/backend/templates/my_page.html +++ b/backend/templates/my_page.html @@ -466,7 +466,10 @@
-
💊
+
+ +
💊
+
@@ -575,6 +578,17 @@ _recId = data.recommendation.id; document.getElementById('rec-message').textContent = data.recommendation.message; document.getElementById('rec-product').textContent = data.recommendation.product; + + // 제품 이미지 표시 + if (data.recommendation.image) { + document.getElementById('rec-image').src = 'data:image/jpeg;base64,' + data.recommendation.image; + document.getElementById('rec-image').style.display = 'block'; + document.getElementById('rec-emoji').style.display = 'none'; + } else { + document.getElementById('rec-image').style.display = 'none'; + document.getElementById('rec-emoji').style.display = 'block'; + } + document.getElementById('rec-sheet').style.display = 'block'; document.getElementById('rec-backdrop').onclick = dismissRec; }