|
import os |
|
import tempfile |
|
from PIL import Image |
|
import gradio as gr |
|
import logging |
|
import re |
|
from io import BytesIO |
|
|
|
from google import genai |
|
from google.genai import types |
|
|
|
|
|
from dotenv import load_dotenv |
|
load_dotenv() |
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') |
|
logger = logging.getLogger(__name__) |
|
|
|
def save_binary_file(file_name, data): |
|
with open(file_name, "wb") as f: |
|
f.write(data) |
|
|
|
def translate_prompt_to_english(prompt): |
|
""" |
|
์
๋ ฅ๋ ํ๋กฌํํธ์ ํ๊ธ์ด ํฌํจ๋์ด ์์ผ๋ฉด Geminiโ2.0โflash ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์์ด๋ก ๋ฒ์ญํฉ๋๋ค. |
|
ํ๊ธ์ด ์์ผ๋ฉด ์๋ณธ ํ๋กฌํํธ๋ฅผ ๊ทธ๋๋ก ๋ฐํํฉ๋๋ค. |
|
""" |
|
if not re.search("[๊ฐ-ํฃ]", prompt): |
|
return prompt |
|
try: |
|
api_key = os.environ.get("GEMINI_API_KEY") |
|
if not api_key: |
|
logger.error("Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.") |
|
return prompt |
|
client = genai.Client(api_key=api_key) |
|
translation_prompt = f"Translate the following Korean text to English:\n\n{prompt}" |
|
logger.info(f"Translation prompt: {translation_prompt}") |
|
response = client.models.generate_content( |
|
model="gemini-2.0-flash", |
|
contents=[translation_prompt], |
|
config=types.GenerateContentConfig( |
|
response_modalities=['Text'], |
|
temperature=0.2, |
|
top_p=0.95, |
|
top_k=40, |
|
max_output_tokens=512 |
|
) |
|
) |
|
translated_text = "" |
|
for part in response.candidates[0].content.parts: |
|
if hasattr(part, 'text') and part.text: |
|
translated_text += part.text |
|
if translated_text.strip(): |
|
logger.info(f"Translated text: {translated_text.strip()}") |
|
return translated_text.strip() |
|
else: |
|
logger.warning("๋ฒ์ญ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค. ์๋ณธ ํ๋กฌํํธ ์ฌ์ฉ") |
|
return prompt |
|
except Exception as e: |
|
logger.exception("๋ฒ์ญ ์ค ์ค๋ฅ ๋ฐ์:") |
|
return prompt |
|
|
|
def preprocess_prompt(prompt, image1, image2, image3, bg_options=None): |
|
""" |
|
ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ๊ณ ๊ธฐ๋ฅ ๋ช
๋ น์ ํด์ |
|
""" |
|
has_img1 = image1 is not None |
|
has_img2 = image2 is not None |
|
has_img3 = image3 is not None |
|
|
|
if "#1" in prompt and not has_img1: |
|
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)") |
|
else: |
|
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง") |
|
|
|
if "#2" in prompt and not has_img2: |
|
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)") |
|
else: |
|
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง") |
|
|
|
if "#3" in prompt and not has_img3: |
|
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)") |
|
else: |
|
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง") |
|
|
|
if "1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ" in prompt: |
|
desc_match = re.search(r'#1์ "(.*?)"์ผ๋ก ๋ฐ๊ฟ๋ผ', prompt) |
|
if desc_match: |
|
description = desc_match.group(1) |
|
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ {description}์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์๋ณธ ์ด๋ฏธ์ง์ ์ฃผ์ ๋ด์ฉ์ ์ ์งํ๋ ์๋ก์ด ์คํ์ผ๊ณผ ๋ถ์๊ธฐ๋ก ์ฌํด์ํด์ฃผ์ธ์." |
|
else: |
|
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์." |
|
|
|
elif "2. ๊ธ์์ง์ฐ๊ธฐ" in prompt: |
|
text_match = re.search(r'#1์์ "(.*?)"๋ฅผ ์ง์๋ผ', prompt) |
|
if text_match: |
|
text_to_remove = text_match.group(1) |
|
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ '{text_to_remove}' ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ํ
์คํธ๊ฐ ์๋ ๋ถ๋ถ์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ์ฑ์์ฃผ์ธ์." |
|
else: |
|
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ ๋ชจ๋ ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ๊น๋ํ ์ด๋ฏธ์ง๋ก ๋ง๋ค์ด์ฃผ์ธ์." |
|
|
|
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt: |
|
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์." |
|
|
|
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt or "๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ" in prompt: |
|
|
|
if bg_options and all([bg_options.get("product_name"), bg_options.get("background_type"), bg_options.get("background_style")]): |
|
product_name = bg_options.get("product_name", "") |
|
product_category = bg_options.get("product_category", "์ผ๋ฐ ์ํ") |
|
background_type = bg_options.get("background_type", "์์ฐ ๋ฐฐ๊ฒฝ") |
|
background_style = bg_options.get("background_style", "์ฒ") |
|
lighting = bg_options.get("lighting", "์์ฐ๊ด") |
|
texture = bg_options.get("texture", "") |
|
color_tone = bg_options.get("color_tone", "") |
|
mood = bg_options.get("mood", "") |
|
|
|
|
|
prompt = f"์ด์ปค๋จธ์ค ์ธ๋ค์ผ์ฉ ๊ณ ํ์ง ์์
์ฌ์ง: #1 ์ด๋ฏธ์ง์ {product_name} ์ํ์ ์๋ฒฝํ๊ฒ ๋ณด์กดํ๋ฉด์ ๋ฐฐ๊ฒฝ๋ง {background_type} ์ค {background_style}์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
|
|
|
|
if lighting: |
|
prompt += f"{lighting}์ ์ฌ์ฉํ์ฌ ์ํ์ ๋๋ณด์ด๊ฒ ํ๊ณ , " |
|
if texture and texture != "์ ํ ์ํจ": |
|
prompt += f"{texture} ์ง๊ฐ์ ๋ฐฐ๊ฒฝ์ผ๋ก ์ํ์ ๊ณ ๊ธ์ค๋ฌ์์ ๊ฐ์กฐํ๋ฉฐ, " |
|
if color_tone and color_tone != "์ ํ ์ํจ": |
|
prompt += f"์ ์ฒด์ ์ผ๋ก {color_tone}์ผ๋ก ์กฐํ๋กญ๊ฒ ์ฒ๋ฆฌํ๊ณ , " |
|
if mood and mood != "์ ํ ์ํจ": |
|
prompt += f"{mood}ํ ๋ถ์๊ธฐ๋ก " |
|
|
|
prompt += f"์ฐ์ถํด์ฃผ์ธ์. {product_category} ์ํ์ ๋ํ
์ผ, ์์, ์ง๊ฐ, ํํ, ๊ทธ๋ฆผ์๋ ์๋ณธ #1 ์ด๋ฏธ์ง์ 100% ๋์ผํ๊ฒ ์ ์งํ๊ณ , ๋ฐฐ๊ฒฝ๋ง ๋ณ๊ฒฝํ์ฌ ์ ๋ฌธ์ ์ด๊ณ ์์
์ฑ ๋์ ์ด์ปค๋จธ์ค ์ ํ ์ฌ์ง์ผ๋ก ์ ์ํด์ฃผ์ธ์." |
|
else: |
|
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์." |
|
|
|
elif "์ํํฉ์ฑ" in prompt: |
|
prompt = "#1 ์ํ ์ด๋ฏธ์ง์ #2 ์ด๋ฏธ์ง ๋๋ #3 ์ด๋ฏธ์ง๋ฅผ [๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ๋๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํ์ฌ]์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํ๋ผ." |
|
|
|
prompt += " ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์." |
|
return prompt |
|
|
|
def generate_with_images(prompt, images): |
|
""" |
|
API ํธ์ถ์ ํตํด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค. |
|
""" |
|
try: |
|
api_key = os.environ.get("GEMINI_API_KEY") |
|
if not api_key: |
|
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ํ๊ฒฝ๋ณ์๋ฅผ ํ์ธํด์ฃผ์ธ์." |
|
|
|
client = genai.Client(api_key=api_key) |
|
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}") |
|
|
|
contents = [prompt] |
|
for idx, img in enumerate(images, 1): |
|
if img is not None: |
|
contents.append(img) |
|
logger.info(f"์ด๋ฏธ์ง #{idx} ์ถ๊ฐ๋จ") |
|
|
|
response = client.models.generate_content( |
|
model="gemini-2.0-flash-exp-image-generation", |
|
contents=contents, |
|
config=types.GenerateContentConfig( |
|
response_modalities=['Text', 'Image'], |
|
temperature=1, |
|
top_p=0.95, |
|
top_k=40, |
|
max_output_tokens=8192 |
|
) |
|
) |
|
|
|
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp: |
|
temp_path = tmp.name |
|
result_text = "" |
|
image_found = False |
|
for part in response.candidates[0].content.parts: |
|
if hasattr(part, 'text') and part.text: |
|
result_text += part.text |
|
logger.info(f"์๋ต ํ
์คํธ: {part.text}") |
|
elif hasattr(part, 'inline_data') and part.inline_data: |
|
save_binary_file(temp_path, part.inline_data.data) |
|
image_found = True |
|
logger.info("์๋ต์์ ์ด๋ฏธ์ง ์ถ์ถ ์ฑ๊ณต") |
|
if not image_found: |
|
return None, f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์๋ต ํ
์คํธ: {result_text}" |
|
result_img = Image.open(temp_path) |
|
if result_img.mode == "RGBA": |
|
result_img = result_img.convert("RGB") |
|
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}" |
|
except Exception as e: |
|
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:") |
|
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}" |
|
|
|
def process_images_with_prompt(image1, image2, image3, prompt, bg_options=None): |
|
""" |
|
3๊ฐ์ ์ด๋ฏธ์ง์ ํ๋กฌํํธ๋ฅผ ์ฒ๋ฆฌํ์ฌ ์ต์ข
์์ด ํ๋กฌํํธ(final_prompt)๋ฅผ ์์ฑํ ํ, |
|
API๋ฅผ ํธ์ถํ์ฌ ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค. |
|
""" |
|
try: |
|
images = [image1, image2, image3] |
|
valid_images = [img for img in images if img is not None] |
|
if not valid_images: |
|
return None, "์ ์ด๋ ํ๋์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.", "" |
|
|
|
if prompt and prompt.strip(): |
|
processed_prompt = preprocess_prompt(prompt, image1, image2, image3, bg_options) |
|
if re.search("[๊ฐ-ํฃ]", processed_prompt): |
|
final_prompt = translate_prompt_to_english(processed_prompt) |
|
else: |
|
final_prompt = processed_prompt |
|
else: |
|
if len(valid_images) == 1: |
|
final_prompt = "Please creatively transform this image into a more vivid and artistic version." |
|
logger.info("Default prompt generated for single image") |
|
elif len(valid_images) == 2: |
|
final_prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image." |
|
logger.info("Default prompt generated for two images") |
|
else: |
|
final_prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene." |
|
logger.info("Default prompt generated for three images") |
|
|
|
result_img, status = generate_with_images(final_prompt, valid_images) |
|
return result_img, status, final_prompt |
|
except Exception as e: |
|
logger.exception("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์:") |
|
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", prompt |
|
|
|
def ask_llm_for_final_prompt(kr_prompt): |
|
""" |
|
LLM์ 2์ฐจ ์ง๋ฌธํ์ฌ ๋ ์์ฐ์ค๋ฌ์ด ์ด๋ฏธ์ง ์์ฑ ํ๋กฌํํธ๋ฅผ ์ป๋ ํจ์ |
|
์ค์ ๊ตฌํ์์๋ LLM API๋ฅผ ํธ์ถํด์ผ ํจ |
|
""" |
|
try: |
|
api_key = os.environ.get("GEMINI_API_KEY") |
|
if not api_key: |
|
logger.error("Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.") |
|
return f"#1 {kr_prompt}" |
|
|
|
client = genai.Client(api_key=api_key) |
|
|
|
llm_prompt = f""" |
|
๋ค์์ ์ด์ปค๋จธ์ค ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ์ ์ํ ํ๋กฌํํธ์
๋๋ค. ์ด ํ๋กฌํํธ๋ฅผ ๋ ์์ฐ์ค๋ฝ๊ณ ๋งค๋ ฅ์ ์ธ ์ด๋ฏธ์ง ์์ฑ ํ๋กฌํํธ๋ก |
|
๋ค์ ์์ฑํด์ฃผ์ธ์. |
|
|
|
์ค์ ์๊ตฌ์ฌํญ: |
|
1. ๋ฐ๋์ "#1"์ผ๋ก ์์ํด์ผ ํฉ๋๋ค - ์ด๊ฒ์ ์ฐธ์กฐํ ์ด๋ฏธ์ง๋ฅผ ์ง์ ํ๋ ํ๊ทธ์
๋๋ค. |
|
2. ์๋ณธ ์ ํ์ ํ์ง๊ณผ ๋ํ
์ผ์ด 100% ์ ์ง๋์ด์ผ ํฉ๋๋ค. |
|
3. ๋ฐฐ๊ฒฝ์ด ์์ฐ์ค๋ฝ๊ฒ ์ด์ฐ๋ฌ์ ธ์ผ ํฉ๋๋ค - ํฉ์ฑ์ด ์๋ ์ค์ ์ดฌ์ํ ๊ฒ์ฒ๋ผ ๋ณด์ด๊ฒ ํด์ฃผ์ธ์. |
|
4. ๋ค์ ์์๋ค์ ํฌํจํด์ฃผ์ธ์: |
|
- ์ฃผ๋ณ ํ๊ฒฝ๊ณผ์ ์์ฐ์ค๋ฌ์ด ์ํธ์์ฉ (๊ทธ๋ฆผ์, ๋ฐ์ฌ, ํ๊ฒฝ๊ด ๋ฑ) |
|
- ์ ํ๊ณผ ๋ฐฐ๊ฒฝ ๊ฐ์ ์์ฐ์ค๋ฌ์ด ๋น ์ํธ์์ฉ |
|
- ์ค์ ์ฌ์ง ์ดฌ์ ์ฉ์ด (์คํ๋์ค ์ดฌ์, ์์ฐ๊ด, ๊น์ด๊ฐ ๋ฑ) |
|
- ์ค์ ๊ณ ๊ธ ์์
์ฌ์ง ํ์ง (8K, ์ ๋ช
๋, ๋ฆฌ์ผ๋ฆฌ์ฆ) |
|
5. ์ธ์์ ์ด๊ฑฐ๋ ํฉ์ฑ๋ ๋๋์ด ์๋, ์ ๋ฌธ ์ ํ ์ฌ์ง์๊ฐ๊ฐ ์ค์ ๋ก ์ดฌ์ํ ๊ฒ ๊ฐ์ ๋๋์ด ๋๋๋ก ํด์ฃผ์ธ์. |
|
|
|
์๋ณธ ํ๋กฌํํธ: |
|
{kr_prompt} |
|
|
|
๊ฒฐ๊ณผ๋ฌผ์ AI ์ด๋ฏธ์ง ์์ฑ์ ์ต์ ํ๋ ํ๋กฌํํธ์ฌ์ผ ํฉ๋๋ค. ๊ฒฐ๊ณผ๋ฌผ๋ง ์ ๊ณตํ๊ณ ์ค๋ช
์ด๋ ์ถ๊ฐ ํ
์คํธ ์์ด ํ๋กฌํํธ ์์ฒด๋ง ์ถ๋ ฅํด์ฃผ์ธ์. |
|
""" |
|
|
|
response = client.models.generate_content( |
|
model="gemini-2.0-flash", |
|
contents=[llm_prompt], |
|
config=types.GenerateContentConfig( |
|
response_modalities=['Text'], |
|
temperature=0.7, |
|
top_p=0.95, |
|
top_k=40, |
|
max_output_tokens=512 |
|
) |
|
) |
|
|
|
final_prompt = "" |
|
for part in response.candidates[0].content.parts: |
|
if hasattr(part, 'text') and part.text: |
|
final_prompt += part.text |
|
|
|
|
|
final_prompt = final_prompt.strip() |
|
if not final_prompt.startswith("#1"): |
|
final_prompt = f"#1 {final_prompt}" |
|
|
|
if final_prompt.strip(): |
|
logger.info(f"LLM 2์ฐจ ํ๋กฌํํธ ์์ฑ ๊ฒฐ๊ณผ: {final_prompt.strip()}") |
|
return final_prompt.strip() |
|
else: |
|
logger.warning("LLM 2์ฐจ ํ๋กฌํํธ ์์ฑ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค. ์๋ณธ ํ๋กฌํํธ ์ฌ์ฉ") |
|
return f"#1 {kr_prompt}" |
|
except Exception as e: |
|
logger.exception("LLM 2์ฐจ ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:") |
|
return f"#1 {kr_prompt}" |
|
|
|
|
|
def generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood): |
|
|
|
prompt = f"#1 ์๋ณธ ์ด๋ฏธ์ง์ {product_name} ์ ํ์ 100% ๋์ผํ๊ฒ ์ ์งํ๋ฉด์ ๋ฐฐ๊ฒฝ๋ง " |
|
|
|
|
|
if background_type == "์์ฐ ๋ฐฐ๊ฒฝ": |
|
if background_style == "์ฒ": |
|
prompt += "์ธ์ฐฝํ ์ฒ์์ ์์ฐ ํ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "ํด๋ณ": |
|
prompt += "์ฒญ๋ํ ํด๋ณ๊ฐ์ ๋ชจ๋ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "์ฐ": |
|
prompt += "์
์ฅํ ์ฐ์ ์ ์์์ ๋ง์ ํ๋์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋คํ": |
|
prompt += "๋๊ฒ ํผ์ณ์ง ์ด์ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๊ณ๊ณก": |
|
prompt += "์์ํ ๊ณ๊ณก๋ฌผ์ด ํ๋ฅด๋ ๋ฐ์ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "์ด๋ ์ ์": |
|
prompt += "์๋๊ฐ ๋์น๋ ์ด๋ ์๋ฌผ๋ก ๋๋ฌ์ธ์ธ ๊ณต๊ฐ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "์ฌ๋ง": |
|
prompt += "๋์์ด ํผ์ณ์ง ํฉ๊ธ๋น ์ฌ๋ง ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋ ํ๊ฒฝ": |
|
prompt += "ํ์ ๋์ผ๋ก ๋ฎ์ธ ์๋ฐฑ์ ํ๊ฒฝ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
else: |
|
prompt += f"{background_style} ์์ฐ ํ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_type == "์ค๋ด ๋ฐฐ๊ฒฝ": |
|
if background_style == "๊ฑฐ์ค": |
|
prompt += "๋ชจ๋ํ๊ณ ์ธ๋ จ๋ ๊ฑฐ์ค ๊ณต๊ฐ์ ํ
์ด๋ธ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "์ฃผ๋ฐฉ": |
|
prompt += "๊น๋ํ ์ฃผ๋ฐฉ ์นด์ดํฐ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "์์ฌ": |
|
prompt += "์ง์ ์ธ ๋ถ์๊ธฐ์ ์์ฌ ์ฑ
์ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "ํ์ฅ๋": |
|
prompt += "์ธ๋ จ๋ ํ์ฅ๋ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "ํธํ
๋ก๋น": |
|
prompt += "๊ณ ๊ธ์ค๋ฌ์ด ํธํ
๋ก๋น์ ๋๋ฆฌ์ ํ
์ด๋ธ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "์นดํ": |
|
prompt += "๊ฐ์ฑ์ ์ธ ์นดํ ํ
์ด๋ธ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋ฏธ๋๋ฉ ๊ณต๊ฐ": |
|
prompt += "๋ฏธ๋๋ฉํ ๋์์ธ์ ๊น๋ํ ๊ณต๊ฐ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
else: |
|
prompt += f"{background_style} ์ค๋ด ๊ณต๊ฐ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_type == "ํน์ ๋ฐฐ๊ฒฝ": |
|
if background_style == "๋์ ํ๊ฒฝ": |
|
prompt += "ํ๋์ ์ธ ๋์ ์ค์นด์ด๋ผ์ธ์ ๋ฐฐ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋ฃจํํ": |
|
prompt += "๋์ ์ ๊ฒฝ์ด ๋ณด์ด๋ ๋ฃจํํ ํ
์ด๋ธ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "ํด์๊ฐ": |
|
prompt += "์๋ฆ๋ค์ด ํด์๊ฐ์ ์ ๋ฒฝ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋ชจ๋ ์คํ๋์ค": |
|
prompt += "ํ๋กํ์
๋ํ ๋ชจ๋ ์คํ๋์ค ์ธํธ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋นํฐ์ง ๊ณต๊ฐ": |
|
prompt += "ํด๋์ํ ๋ถ์๊ธฐ์ ๋นํฐ์ง ๊ณต๊ฐ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
elif background_style == "๋ฏธ๋์ด์ฒ ๊ณต๊ฐ": |
|
prompt += "์ ๊ตํ๊ฒ ๊พธ๋ฉฐ์ง ๋ฏธ๋์ด์ฒ ์ธํธ ์๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
else: |
|
prompt += f"{background_style} ํน์ ํ๊ฒฝ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํด์ฃผ์ธ์. " |
|
|
|
|
|
if lighting: |
|
if lighting == "์์ฐ๊ด": |
|
prompt += "๋ถ๋๋ฌ์ด ์์ฐ๊ด์ด ๋น์น๋ ํ๊ฒฝ์์ " |
|
elif lighting == "๋ฐ๋ปํ ์กฐ๋ช
": |
|
prompt += "๋ฐ๋ปํ ํฉ๊ธ๋น ์กฐ๋ช
์ด ๊ฐ์ธ๋ ํ๊ฒฝ์์ " |
|
elif lighting == "๊ทธ๋ฆผ์ ์๋ ์กฐ๋ช
": |
|
prompt += "๋๋ผ๋งํฑํ ๊ทธ๋ฆผ์๋ฅผ ๋ง๋๋ ์กฐ๋ช
์๋์์ " |
|
elif lighting == "๋ฏธ๋๋ฉ ์กฐ๋ช
": |
|
prompt += "๊น๋ํ๊ณ ๋ฏธ๋๋ฉํ ์กฐ๋ช
์๋์์ " |
|
|
|
|
|
if texture and texture != "์ ํ ์ํจ": |
|
if texture == "ํฐ ๋ฒฝ": |
|
prompt += "๊น๋ํ ํฐ ๋ฒฝ์ ๋ฐฐ๊ฒฝ์ผ๋ก ํ์ฌ " |
|
elif texture == "๋๋ฆฌ์": |
|
prompt += "๊ณ ๊ธ์ค๋ฌ์ด ๋๋ฆฌ์ ์ง๊ฐ ์์ " |
|
elif texture == "๋๋ฌด": |
|
prompt += "๋ฐ๋ปํ ๋๋์ ์๋ชฉ ์ง๊ฐ ์์ " |
|
elif texture == "๋ฒฝ๋": |
|
prompt += "ํด๋์ํ ๋ฒฝ๋ ์ง๊ฐ์ ๋ฐฐ๊ฒฝ์ผ๋ก " |
|
elif texture == "ํฐ ์ฒ": |
|
prompt += "๋ถ๋๋ฌ์ด ํฐ ์ฒ ์์ " |
|
elif texture == "์๋ฉํธ": |
|
prompt += "๋ชจ๋ํ ์๋ฉํธ ์ง๊ฐ ์์ " |
|
|
|
|
|
if color_tone and color_tone != "์ ํ ์ํจ": |
|
if color_tone == "ํ์ดํธ ํค": |
|
prompt += "์๋ฐฑ์ ๊น๋ํ ์๊ฐ์ผ๋ก " |
|
elif color_tone == "๋ธ๋ฃจ ํค": |
|
prompt += "์์ํ ๋ธ๋ฃจ ํค์ ์๊ฐ์ผ๋ก " |
|
elif color_tone == "๋ฐ๋ปํ ์์": |
|
prompt += "๋ฐ๋ปํ ํ์คํ
์๊ฐ์ผ๋ก " |
|
elif color_tone == "๋ชจ๋
ธํค": |
|
prompt += "์ธ๋ จ๋ ๋ชจ๋
ธํค ์๊ฐ์ผ๋ก " |
|
elif color_tone == "ํ์คํ
": |
|
prompt += "๋ถ๋๋ฌ์ด ํ์คํ
์๊ฐ์ผ๋ก " |
|
|
|
|
|
if mood and mood != "์ ํ ์ํจ": |
|
if mood == "ํฌ๊ทผํ": |
|
prompt += "ํฌ๊ทผํ๊ณ ์๋ํ ๋ถ์๊ธฐ ์์์ " |
|
elif mood == "์ฌํํ": |
|
prompt += "์ฌํํ๊ณ ๊น๋ํ ๋ถ์๊ธฐ ์์์ " |
|
elif mood == "๋ชจ๋ํ": |
|
prompt += "๋ชจ๋ํ๊ณ ์ธ๋ จ๋ ๋ถ์๊ธฐ ์์์ " |
|
elif mood == "๋ด์ถ๋ด": |
|
prompt += "์์ฐ์ค๋ฝ๊ณ ํธ์ํ ๋ถ์๊ธฐ ์์์ " |
|
elif mood == "๋ฏธ๋๋ฉ": |
|
prompt += "๋ฏธ๋๋ฉ๋ฆฌ์ฆ์ ์ ์ ๋ ๋ถ์๊ธฐ ์์์ " |
|
|
|
|
|
if product_category == "ํ์ฅํ": |
|
prompt += "์๋ฒฝํ ๋ํ
์ผ์ด ์ด์์๋ ํ์ฅํ ์ ํ์ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "๊ฐ๋ฐฉ": |
|
prompt += "์ง๊ฐ๊ณผ ๋์์ธ์ด ๋๋ณด์ด๋ ๊ฐ๋ฐฉ ์ ํ์ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "์ก์ธ์๋ฆฌ": |
|
prompt += "์ฌ์ธํ ๋ํ
์ผ์ด ๋น๋๋ ์ก์ธ์๋ฆฌ๋ฅผ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "๋ณด์๋ฅ": |
|
prompt += "ํ๋ คํ ๊ด์ฑ๊ฐ ๋๋ณด์ด๋ ๋ณด์ ์ ํ์ ๊ณ ๊ธ์ค๋ฝ๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "ํ ๋ฐ์ฝ": |
|
prompt += "๊ณต๊ฐ์ ์ด์ธ๋ฆฌ๋ ํ ๋ฐ์ฝ ์ ํ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "์ ๋ฐ": |
|
prompt += "๋์์ธ๊ณผ ์ง๊ฐ์ด ๋๋ณด์ด๋ ์ ๋ฐ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "์๋ฅ": |
|
prompt += "์์ฌ์ ์ค๋ฃจ์ฃ์ด ๋๋ณด์ด๋ ์๋ฅ๋ฅผ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "์ฃผ๋ฐฉ์ฉํ": |
|
prompt += "์ค์ฉ์ฑ๊ณผ ๋์์ธ์ด ๋๋ณด์ด๋ ์ฃผ๋ฐฉ์ฉํ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
elif product_category == "์ ์๊ธฐ๊ธฐ": |
|
prompt += "์ฒจ๋จ ๊ธฐ์ ๊ณผ ๋์์ธ์ด ๋๋ณด์ด๋ ์ ์๊ธฐ๊ธฐ๋ฅผ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
else: |
|
prompt += f"๋ํ
์ผ๊ณผ ํ์ง์ด ๋๋ณด์ด๋ {product_category} ์ ํ์ ์ธ๋ จ๋๊ฒ ์ฐ์ถํ ์์
์ฉ ์ ํ ์ฌ์ง" |
|
|
|
return prompt |
|
|
|
|
|
def generate_prompt_and_ask_llm(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood): |
|
|
|
kr_prompt = generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood) |
|
|
|
|
|
final_prompt = ask_llm_for_final_prompt(kr_prompt) |
|
|
|
|
|
options_summary = f"์ํ๋ช
: {product_name if product_name else '์ง์ ๋์ง ์์'}\n" |
|
options_summary += f"์ ํ๊ตฐ: {product_category}\n" |
|
options_summary += f"๋ฐฐ๊ฒฝ ์ ํ: {background_type}\n" |
|
options_summary += f"์ธ๋ถ ์คํ์ผ: {background_style}\n" |
|
|
|
if lighting: |
|
options_summary += f"์กฐ๋ช
: {lighting}\n" |
|
if texture and texture != "์ ํ ์ํจ": |
|
options_summary += f"๋ฐฐ๊ฒฝ ์ง๊ฐ: {texture}\n" |
|
if color_tone and color_tone != "์ ํ ์ํจ": |
|
options_summary += f"์๊ฐ: {color_tone}\n" |
|
if mood and mood != "์ ํ ์ํจ": |
|
options_summary += f"๋ถ์๊ธฐ: {mood}\n" |
|
|
|
return kr_prompt, final_prompt, options_summary |
|
|
|
|
|
def update_background_style_options(background_type): |
|
if background_type == "์์ฐ ๋ฐฐ๊ฒฝ": |
|
return gr.update(choices=["์ฒ", "ํด๋ณ", "์ฐ", "๋คํ", "๊ณ๊ณก", "์ด๋ ์ ์", "์ฌ๋ง", "๋ ํ๊ฒฝ"], value="์ฒ") |
|
elif background_type == "์ค๋ด ๋ฐฐ๊ฒฝ": |
|
return gr.update(choices=["๊ฑฐ์ค", "์ฃผ๋ฐฉ", "์์ฌ", "ํ์ฅ๋", "ํธํ
๋ก๋น", "์นดํ", "๋ฏธ๋๋ฉ ๊ณต๊ฐ"], value="๊ฑฐ์ค") |
|
elif background_type == "ํน์ ๋ฐฐ๊ฒฝ": |
|
return gr.update(choices=["๋์ ํ๊ฒฝ", "๋ฃจํํ", "ํด์๊ฐ", "๋ชจ๋ ์คํ๋์ค", "๋นํฐ์ง ๊ณต๊ฐ", "๋ฏธ๋์ด์ฒ ๊ณต๊ฐ"], value="๋์ ํ๊ฒฝ") |
|
else: |
|
return gr.update(choices=["์ ํํ์ธ์"], value="์ ํํ์ธ์") |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.HTML( |
|
""" |
|
<div style="text-align: center; margin-bottom: 1rem;"> |
|
<h1>์ด์ปค๋จธ์ค ์ํ ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ์์ฑ๊ธฐ</h1> |
|
<p>์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ์ํ๋ ๋ฐฐ๊ฒฝ ์ต์
์ ์ ํํ์ฌ ์๋ก์ด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ธ์.</p> |
|
</div> |
|
""" |
|
) |
|
|
|
current_selection = gr.State("") |
|
|
|
with gr.Row(): |
|
with gr.Column(scale=1): |
|
with gr.Row(): |
|
image1_input = gr.Image(type="pil", label="#1 ์ํ ์ด๋ฏธ์ง", image_mode="RGB") |
|
image2_input = gr.Image(type="pil", label="#2 (์ ํ์ฌํญ)", image_mode="RGB") |
|
image3_input = gr.Image(type="pil", label="#3 (์ ํ์ฌํญ)", image_mode="RGB") |
|
|
|
prompt_input = gr.Textbox( |
|
lines=3, |
|
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค.", |
|
label="ํ๋กฌํํธ (์ ํ ์ฌํญ)" |
|
) |
|
|
|
with gr.Row(): |
|
image_change_btn = gr.Button("์ด๋ฏธ์ง ๋ณ๊ฒฝ", variant="secondary") |
|
text_remove_btn = gr.Button("๊ธ์์ง์ฐ๊ธฐ", variant="secondary") |
|
clothes_change_btn = gr.Button("์ท๋ฐ๊พธ๊ธฐ", variant="secondary") |
|
background_change_btn = gr.Button("๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ", variant="secondary") |
|
composite_product_btn = gr.Button("์ํํฉ์ฑ", variant="secondary") |
|
|
|
|
|
with gr.Row(visible=False) as background_header: |
|
gr.HTML("<h3 style='margin-top: 20px; margin-bottom: 10px; width: 100%; text-align: center;'>๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ์ต์
</h3>") |
|
|
|
|
|
product_name = gr.Textbox( |
|
label="์ํ๋ช
์
๋ ฅ", |
|
placeholder="์ํ๋ช
์ ์
๋ ฅํด์ฃผ์ธ์", |
|
visible=False |
|
) |
|
|
|
|
|
product_category = gr.Dropdown( |
|
choices=["ํ์ฅํ", "๊ฐ๋ฐฉ", "์ก์ธ์๋ฆฌ", "๋ณด์๋ฅ", "ํ ๋ฐ์ฝ", "์ ๋ฐ", "์๋ฅ", "์ฃผ๋ฐฉ์ฉํ", "์ ์๊ธฐ๊ธฐ", "๊ธฐํ"], |
|
label="์ ํ๊ตฐ ์ ํ", |
|
value="๊ธฐํ", |
|
visible=False |
|
) |
|
|
|
|
|
background_type = gr.Dropdown( |
|
choices=["์์ฐ ๋ฐฐ๊ฒฝ", "์ค๋ด ๋ฐฐ๊ฒฝ", "ํน์ ๋ฐฐ๊ฒฝ"], |
|
label="๋ฐฐ๊ฒฝ ์ ํ ์ ํ", |
|
value="์์ฐ ๋ฐฐ๊ฒฝ", |
|
visible=False |
|
) |
|
|
|
|
|
background_style = gr.Dropdown( |
|
choices=["์ฒ", "ํด๋ณ", "์ฐ", "๋คํ", "๊ณ๊ณก", "์ด๋ ์ ์", "์ฌ๋ง", "๋ ํ๊ฒฝ"], |
|
label="๋ฐฐ๊ฒฝ ์ธ๋ถ ์คํ์ผ ์ ํ", |
|
value="์ฒ", |
|
visible=False |
|
) |
|
|
|
|
|
with gr.Row(visible=False) as additional_header: |
|
gr.HTML("<h4 style='margin-top: 15px; margin-bottom: 10px; width: 100%; text-align: center;'>์ถ๊ฐ ์ ํ ์ต์
</h4>") |
|
|
|
|
|
lighting = gr.Dropdown( |
|
choices=["์์ฐ๊ด", "๋ฐ๋ปํ ์กฐ๋ช
", "๊ทธ๋ฆผ์ ์๋ ์กฐ๋ช
", "๋ฏธ๋๋ฉ ์กฐ๋ช
"], |
|
label="์กฐ๋ช
์ ํ", |
|
value="์์ฐ๊ด", |
|
visible=False |
|
) |
|
|
|
|
|
texture = gr.Dropdown( |
|
choices=["์ ํ ์ํจ", "ํฐ ๋ฒฝ", "๋๋ฆฌ์", "๋๋ฌด", "๋ฒฝ๋", "ํฐ ์ฒ", "์๋ฉํธ"], |
|
label="๋ฐฐ๊ฒฝ ์ง๊ฐ ์ ํ", |
|
value="์ ํ ์ํจ", |
|
visible=False |
|
) |
|
|
|
|
|
color_tone = gr.Dropdown( |
|
choices=["์ ํ ์ํจ", "ํ์ดํธ ํค", "๋ธ๋ฃจ ํค", "๋ฐ๋ปํ ์์", "๋ชจ๋
ธํค", "ํ์คํ
"], |
|
label="์๊ฐ ์ ํ", |
|
value="์ ํ ์ํจ", |
|
visible=False |
|
) |
|
|
|
|
|
mood = gr.Dropdown( |
|
choices=["์ ํ ์ํจ", "ํฌ๊ทผํ", "์ฌํํ", "๋ชจ๋ํ", "๋ด์ถ๋ด", "๋ฏธ๋๋ฉ"], |
|
label="๋ถ์๊ธฐ ์ ํ", |
|
value="์ ํ ์ํจ", |
|
visible=False |
|
) |
|
|
|
|
|
selection_preview = gr.Textbox( |
|
label="์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", |
|
lines=8, |
|
visible=False |
|
) |
|
|
|
|
|
prompt_generate_btn = gr.Button("ํ๋กฌํํธ ์์ฑ", variant="secondary", visible=False) |
|
|
|
|
|
submit_btn = gr.Button("์ด๋ฏธ์ง ์์ฑ", variant="primary") |
|
|
|
with gr.Column(scale=1): |
|
output_image = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง") |
|
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง") |
|
kr_prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (ํ๊ตญ์ด)", visible=True, lines=4) |
|
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True, lines=4) |
|
options_summary = gr.Textbox(label="์ ํ๋ ์ต์
์์ฝ", lines=8, visible=True) |
|
|
|
|
|
def show_background_options(): |
|
return ("๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ", "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ", |
|
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), |
|
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), |
|
gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), |
|
gr.update(visible=True), "", gr.update(visible=True)) |
|
|
|
background_change_btn.click( |
|
fn=show_background_options, |
|
inputs=[], |
|
outputs=[prompt_input, current_selection, background_header, product_name, product_category, |
|
background_type, background_style, additional_header, lighting, texture, |
|
color_tone, mood, selection_preview, prompt_generate_btn] |
|
) |
|
|
|
|
|
def hide_background_options(prompt_value): |
|
return (prompt_value, "๊ธฐํ", |
|
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), |
|
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), |
|
gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), |
|
gr.update(visible=False), "", gr.update(visible=False)) |
|
|
|
image_change_btn.click( |
|
fn=lambda: hide_background_options("#1 ์ด๋ฏธ์ง์ [๋ค๋ฅธ ๋ชจ์ต]์ผ๋ก ๋ณ๊ฒฝํ๋ผ."), |
|
inputs=[], |
|
outputs=[prompt_input, current_selection, background_header, product_name, product_category, |
|
background_type, background_style, additional_header, lighting, texture, |
|
color_tone, mood, selection_preview, prompt_generate_btn] |
|
) |
|
|
|
text_remove_btn.click( |
|
fn=lambda: hide_background_options("#1 ์ด๋ฏธ์ง์ [์ค๊ตญ์ด๋ฅผ ๋ชจ๋]๋ฅผ ์ ๊ฑฐํ๋ผ."), |
|
inputs=[], |
|
outputs=[prompt_input, current_selection, background_header, product_name, product_category, |
|
background_type, background_style, additional_header, lighting, texture, |
|
color_tone, mood, selection_preview, prompt_generate_btn] |
|
) |
|
|
|
clothes_change_btn.click( |
|
fn=lambda: hide_background_options("#1์ด๋ฏธ์ง์์ [์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด] ์์[์คํ์ผ๊ณผ ์์์]#2, #3์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์."), |
|
inputs=[], |
|
outputs=[prompt_input, current_selection, background_header, product_name, product_category, |
|
background_type, background_style, additional_header, lighting, texture, |
|
color_tone, mood, selection_preview, prompt_generate_btn] |
|
) |
|
|
|
composite_product_btn.click( |
|
fn=lambda: hide_background_options("์ด๋ฏธ์ง #1์ ๋ชจ๋ธ์ด ํ์์ ๋ฐ๋ผ ์์ธ๋ ํ์ ์ ์ ๋์ ์ผ๋ก ๋ณํํ ํ, ์ด๋ฏธ์ง #2(๋๋ #3)์ ์ํ์ ์ต๋ํ ์๋ ํํ์ ๋ํ
์ผ์ ์ ์งํ๋ฉด์ ์์ฐ์ค๋ฝ๊ฒ ์ฐฉ์ฉํ ๋ชจ์ต์ ํฉ์ฑํ๋ผ."), |
|
inputs=[], |
|
outputs=[prompt_input, current_selection, background_header, product_name, product_category, |
|
background_type, background_style, additional_header, lighting, texture, |
|
color_tone, mood, selection_preview, prompt_generate_btn] |
|
) |
|
|
|
|
|
def update_all_previews(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood): |
|
llm_prompt = generate_llm_prompt(product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood) |
|
|
|
preview = f"์ํ๋ช
: {product_name}\n" |
|
preview += f"์ ํ๊ตฐ: {product_category}\n" |
|
preview += f"๋ฐฐ๊ฒฝ ์ ํ: {background_type}\n" |
|
preview += f"์ธ๋ถ ์คํ์ผ: {background_style}\n" |
|
|
|
if lighting: |
|
preview += f"์กฐ๋ช
: {lighting}\n" |
|
if texture and texture != "์ ํ ์ํจ": |
|
preview += f"๋ฐฐ๊ฒฝ ์ง๊ฐ: {texture}\n" |
|
if color_tone and color_tone != "์ ํ ์ํจ": |
|
preview += f"์๊ฐ: {color_tone}\n" |
|
if mood and mood != "์ ํ ์ํจ": |
|
preview += f"๋ถ์๊ธฐ: {mood}\n" |
|
|
|
preview += f"\n์์ฑ๋ ํ๋กฌํํธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ:\n{llm_prompt}" |
|
|
|
return preview |
|
|
|
|
|
background_type.change( |
|
fn=update_background_style_options, |
|
inputs=[background_type], |
|
outputs=[background_style] |
|
).then( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
|
|
product_name.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
product_category.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
background_style.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
lighting.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
texture.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
color_tone.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
mood.change( |
|
fn=update_all_previews, |
|
inputs=[product_name, product_category, background_type, background_style, lighting, texture, color_tone, mood], |
|
outputs=[selection_preview] |
|
) |
|
|
|
|
|
prompt_generate_btn.click( |
|
fn=generate_prompt_and_ask_llm, |
|
inputs=[product_name, product_category, background_type, background_style, |
|
lighting, texture, color_tone, mood], |
|
outputs=[kr_prompt_display, prompt_input, options_summary] |
|
) |
|
|
|
|
|
submit_btn.click( |
|
fn=process_images_with_prompt, |
|
inputs=[image1_input, image2_input, image3_input, prompt_input], |
|
outputs=[output_image, output_text, prompt_display], |
|
) |
|
|
|
gr.Markdown( |
|
""" |
|
### ์ฌ์ฉ ๋ฐฉ๋ฒ: |
|
|
|
1. ์ํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์ (#1 ์ด๋ฏธ์ง). |
|
2. "๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๋ฐฐ๊ฒฝ ๋ณ๊ฒฝ ์ต์
์ด ๋ํ๋ฉ๋๋ค. |
|
3. ์ํ๋ช
์ ์
๋ ฅํ๊ณ ์ ํ๊ตฐ, ๋ฐฐ๊ฒฝ ์ ํ, ๋ฐฐ๊ฒฝ ์ธ๋ถ ์คํ์ผ์ ์ ํํ์ธ์. |
|
4. ์ถ๊ฐ ์ต์
(์กฐ๋ช
, ์ง๊ฐ, ์๊ฐ, ๋ถ์๊ธฐ)์ ์ ํํ๋ฉด ๋ ์ธ๋ฐํ ๋ฐฐ๊ฒฝ์ ์์ฑํ ์ ์์ต๋๋ค. |
|
5. "ํ๋กฌํํธ ์์ฑ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด LLM ์คํ์ผ ํ๋กฌํํธ๊ฐ ์์ฑ๋๊ณ , ์ด๋ฅผ ๋ฐํ์ผ๋ก ์ด๋ฏธ์ง ์์ฑ์ฉ ํ๋กฌํํธ๊ฐ ์๋์ผ๋ก ์์ฑ๋ฉ๋๋ค. |
|
6. "์ด๋ฏธ์ง ์์ฑ" ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์์ฑ๋ ํ๋กฌํํธ๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋ฉ๋๋ค. |
|
7. ํ๋กฌํํธ ์
๋ ฅ๋์ ์ง์ ํ๋กฌํํธ๋ฅผ ์์ฑํ ์๋ ์์ต๋๋ค. |
|
|
|
> **ํ**: ์ ํ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์์ ์์ฑ๋ ํ๋กฌํํธ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค. |
|
""" |
|
) |