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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
from PIL import Image, ImageEnhance, ImageFilter
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import logging
|
| 6 |
+
import re
|
| 7 |
+
import time
|
| 8 |
+
import cv2
|
| 9 |
+
import numpy as np
|
| 10 |
+
from io import BytesIO
|
| 11 |
+
from datetime import datetime, timedelta
|
| 12 |
+
import random
|
| 13 |
+
import requests
|
| 14 |
+
import base64
|
| 15 |
+
from dotenv import load_dotenv
|
| 16 |
+
|
| 17 |
+
load_dotenv()
|
| 18 |
+
|
| 19 |
+
# ๋ก๊น
์ค์
|
| 20 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
# ------------------- API ์๋ํฌ์ธํธ ์ค์ -------------------
|
| 24 |
+
def get_api_endpoint():
|
| 25 |
+
"""ํ๊ฒฝ๋ณ์์์ API ์๋ํฌ์ธํธ๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์"""
|
| 26 |
+
endpoint = os.getenv('API_ENDPOINT')
|
| 27 |
+
if not endpoint:
|
| 28 |
+
logger.error("API_ENDPOINT ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 29 |
+
return None
|
| 30 |
+
return endpoint
|
| 31 |
+
|
| 32 |
+
def encode_image_to_base64(image):
|
| 33 |
+
"""PIL ์ด๋ฏธ์ง๋ฅผ base64๋ก ์ธ์ฝ๋ฉ"""
|
| 34 |
+
if image is None:
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
buffered = BytesIO()
|
| 38 |
+
image.save(buffered, format="PNG")
|
| 39 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
| 40 |
+
return img_str
|
| 41 |
+
|
| 42 |
+
def decode_base64_to_image(base64_str):
|
| 43 |
+
"""base64 ๋ฌธ์์ด์ PIL ์ด๋ฏธ์ง๋ก ๋์ฝ๋ฉ"""
|
| 44 |
+
if not base64_str:
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
image_data = base64.b64decode(base64_str)
|
| 48 |
+
image = Image.open(BytesIO(image_data))
|
| 49 |
+
return image
|
| 50 |
+
|
| 51 |
+
def call_api_endpoint(endpoint_url, data):
|
| 52 |
+
"""API ์๋ํฌ์ธํธ ํธ์ถ ํจ์"""
|
| 53 |
+
try:
|
| 54 |
+
response = requests.post(endpoint_url, json=data, timeout=300)
|
| 55 |
+
response.raise_for_status()
|
| 56 |
+
return response.json()
|
| 57 |
+
except requests.exceptions.RequestException as e:
|
| 58 |
+
logger.error(f"API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 59 |
+
return {"error": f"API ํธ์ถ ์คํจ: {str(e)}"}
|
| 60 |
+
|
| 61 |
+
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ๊ด๋ จ ํจ์ ==========
|
| 62 |
+
def translate_prompt_to_english(prompt):
|
| 63 |
+
"""ํ๋กฌํํธ ๋ฒ์ญ - API ์๋ํฌ์ธํธ๋ก ์ ๋ฌ"""
|
| 64 |
+
endpoint_url = get_api_endpoint()
|
| 65 |
+
if not endpoint_url:
|
| 66 |
+
return prompt
|
| 67 |
+
|
| 68 |
+
data = {
|
| 69 |
+
"function": "translate_prompt",
|
| 70 |
+
"prompt": prompt
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
try:
|
| 74 |
+
result = call_api_endpoint(f"{endpoint_url}/translate", data)
|
| 75 |
+
if "error" in result:
|
| 76 |
+
logger.warning(f"๋ฒ์ญ API ์ค๋ฅ: {result['error']}")
|
| 77 |
+
return prompt
|
| 78 |
+
return result.get("translated_prompt", prompt)
|
| 79 |
+
except Exception as e:
|
| 80 |
+
logger.warning(f"๋ฒ์ญ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 81 |
+
return prompt
|
| 82 |
+
|
| 83 |
+
def preprocess_prompt(prompt, image1, image2, image3):
|
| 84 |
+
"""ํ๋กฌํํธ ์ ์ฒ๋ฆฌ - ๊ธฐ์กด ๋ก์ง ์ ์ง"""
|
| 85 |
+
has_img1 = image1 is not None
|
| 86 |
+
has_img2 = image2 is not None
|
| 87 |
+
has_img3 = image3 is not None
|
| 88 |
+
|
| 89 |
+
if "#1" in prompt and not has_img1:
|
| 90 |
+
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
| 91 |
+
else:
|
| 92 |
+
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
| 93 |
+
|
| 94 |
+
if "#2" in prompt and not has_img2:
|
| 95 |
+
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
| 96 |
+
else:
|
| 97 |
+
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
| 98 |
+
|
| 99 |
+
if "#3" in prompt and not has_img3:
|
| 100 |
+
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
| 101 |
+
else:
|
| 102 |
+
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
| 103 |
+
|
| 104 |
+
if "1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ" in prompt:
|
| 105 |
+
desc_match = re.search(r'#1์ "(.*?)"์ผ๋ก ๋ฐ๊ฟ๋ผ', prompt)
|
| 106 |
+
if desc_match:
|
| 107 |
+
description = desc_match.group(1)
|
| 108 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ {description}์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์๋ณธ ์ด๋ฏธ์ง์ ์ฃผ์ ๋ด์ฉ์ ์ ์งํ๋ ์๋ก์ด ์คํ์ผ๊ณผ ๋ถ์๊ธฐ๋ก ์ฌํด์ํด์ฃผ์ธ์."
|
| 109 |
+
else:
|
| 110 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
| 111 |
+
|
| 112 |
+
elif "2. ๊ธ์์ง์ฐ๊ธฐ" in prompt:
|
| 113 |
+
text_match = re.search(r'#1์์ "(.*?)"๋ฅผ ์ง์๋ผ', prompt)
|
| 114 |
+
if text_match:
|
| 115 |
+
text_to_remove = text_match.group(1)
|
| 116 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ '{text_to_remove}' ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ํ
์คํธ๊ฐ ์๋ ๋ถ๋ถ์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ์ฑ์์ฃผ์ธ์."
|
| 117 |
+
else:
|
| 118 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ ๋ชจ๋ ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ๊น๋ํ ์ด๋ฏธ์ง๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
| 119 |
+
|
| 120 |
+
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt:
|
| 121 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
| 122 |
+
|
| 123 |
+
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt:
|
| 124 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
| 125 |
+
|
| 126 |
+
elif "6. ์ด๋ฏธ์ง ํฉ์ฑ(์ํํฌํจ)" in prompt:
|
| 127 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง(๋๋ ์ธ ๋ฒ์งธ ์ด๋ฏธ์ง)๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํด์ฃผ์ธ์. ๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ๋๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํด์ฃผ์ธ์."
|
| 128 |
+
|
| 129 |
+
prompt += " ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์. ์ด๋ฏธ์ง์ ํ
์คํธ๋ ๊ธ์๋ฅผ ํฌํจํ์ง ๋ง์ธ์."
|
| 130 |
+
return prompt
|
| 131 |
+
|
| 132 |
+
def generate_with_images(prompt, images, variation_index=0):
|
| 133 |
+
"""API ์๋ํฌ์ธํธ๋ก ์ด๋ฏธ์ง ์์ฑ ์์ฒญ"""
|
| 134 |
+
endpoint_url = get_api_endpoint()
|
| 135 |
+
if not endpoint_url:
|
| 136 |
+
return None, "API ์๋ํฌ์ธํธ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค."
|
| 137 |
+
|
| 138 |
+
# ์ด๋ฏธ์ง๋ค์ base64๋ก ์ธ์ฝ๋ฉ
|
| 139 |
+
encoded_images = []
|
| 140 |
+
for img in images:
|
| 141 |
+
if img is not None:
|
| 142 |
+
encoded_img = encode_image_to_base64(img)
|
| 143 |
+
encoded_images.append(encoded_img)
|
| 144 |
+
else:
|
| 145 |
+
encoded_images.append(None)
|
| 146 |
+
|
| 147 |
+
data = {
|
| 148 |
+
"function": "generate_with_images",
|
| 149 |
+
"prompt": prompt,
|
| 150 |
+
"images": encoded_images,
|
| 151 |
+
"variation_index": variation_index
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
try:
|
| 155 |
+
result = call_api_endpoint(f"{endpoint_url}/generate", data)
|
| 156 |
+
if "error" in result:
|
| 157 |
+
return None, result["error"]
|
| 158 |
+
|
| 159 |
+
# base64 ์ด๋ฏธ์ง๋ฅผ PIL ์ด๋ฏธ์ง๋ก ๋ณํ
|
| 160 |
+
if "image" in result:
|
| 161 |
+
generated_image = decode_base64_to_image(result["image"])
|
| 162 |
+
return generated_image, result.get("status", "์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค.")
|
| 163 |
+
else:
|
| 164 |
+
return None, "API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค."
|
| 165 |
+
except Exception as e:
|
| 166 |
+
logger.error(f"์ด๋ฏธ์ง ์์ฑ API ํธ์ถ ์ค ์ค๋ฅ: {str(e)}")
|
| 167 |
+
return None, f"์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 168 |
+
|
| 169 |
+
def process_images_with_prompt(image1, image2, image3, prompt, variation_index=0, max_retries=3):
|
| 170 |
+
"""์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ฉ์ธ ํจ์"""
|
| 171 |
+
retry_count = 0
|
| 172 |
+
last_error = None
|
| 173 |
+
|
| 174 |
+
while retry_count < max_retries:
|
| 175 |
+
try:
|
| 176 |
+
images = [image1, image2, image3]
|
| 177 |
+
valid_images = [img for img in images if img is not None]
|
| 178 |
+
|
| 179 |
+
if not valid_images:
|
| 180 |
+
if prompt and prompt.strip():
|
| 181 |
+
logger.info("ํ
์คํธ ํ๋กฌํํธ๋ง์ผ๋ก ์ด๋ฏธ์ง ์์ฑ ์๋")
|
| 182 |
+
try:
|
| 183 |
+
result_img, status = generate_with_images(prompt, [], variation_index)
|
| 184 |
+
if result_img is not None:
|
| 185 |
+
return result_img, status, prompt
|
| 186 |
+
except:
|
| 187 |
+
pass
|
| 188 |
+
return None, "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ฑฐ๋ ํ
์คํธ ํ๋กฌํํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.", ""
|
| 189 |
+
|
| 190 |
+
if prompt and prompt.strip():
|
| 191 |
+
processed_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
| 192 |
+
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
| 193 |
+
final_prompt = translate_prompt_to_english(processed_prompt)
|
| 194 |
+
else:
|
| 195 |
+
final_prompt = processed_prompt
|
| 196 |
+
else:
|
| 197 |
+
if len(valid_images) == 1:
|
| 198 |
+
final_prompt = "Please creatively transform this image into a more vivid and artistic version. Do not include any text or watermarks in the generated image."
|
| 199 |
+
logger.info("Default prompt generated for single image")
|
| 200 |
+
elif len(valid_images) == 2:
|
| 201 |
+
final_prompt = "Please seamlessly composite these two images, integrating their key elements harmoniously into a single image. Do not include any text or watermarks in the generated image."
|
| 202 |
+
logger.info("Default prompt generated for two images")
|
| 203 |
+
else:
|
| 204 |
+
final_prompt = "Please creatively composite these three images, combining their main elements into a cohesive and natural scene. Do not include any text or watermarks in the generated image."
|
| 205 |
+
logger.info("Default prompt generated for three images")
|
| 206 |
+
|
| 207 |
+
result_img, status = generate_with_images(final_prompt, valid_images, variation_index)
|
| 208 |
+
if result_img is not None:
|
| 209 |
+
return result_img, status, final_prompt
|
| 210 |
+
else:
|
| 211 |
+
last_error = status
|
| 212 |
+
retry_count += 1
|
| 213 |
+
logger.warning(f"์ด๋ฏธ์ง ์์ฑ ์คํจ, ์ฌ์๋ {retry_count}/{max_retries}: {status}")
|
| 214 |
+
time.sleep(1)
|
| 215 |
+
except Exception as e:
|
| 216 |
+
last_error = str(e)
|
| 217 |
+
retry_count += 1
|
| 218 |
+
logger.exception(f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์, ์ฌ์๋ {retry_count}/{max_retries}:")
|
| 219 |
+
time.sleep(1)
|
| 220 |
+
|
| 221 |
+
return None, f"์ต๋ ์ฌ์๋ ํ์({max_retries}ํ) ์ด๊ณผ ํ ์คํจ: {last_error}", prompt
|
| 222 |
+
|
| 223 |
+
def generate_multiple_images(image1, image2, image3, prompt, progress=gr.Progress()):
|
| 224 |
+
"""๋ค์ค ์ด๋ฏธ์ง ์์ฑ ํจ์"""
|
| 225 |
+
results = []
|
| 226 |
+
statuses = []
|
| 227 |
+
prompts = []
|
| 228 |
+
|
| 229 |
+
num_images = 2
|
| 230 |
+
max_retries = 3
|
| 231 |
+
|
| 232 |
+
progress(0, desc="์ด๋ฏธ์ง ์์ฑ ์ค๋น ์ค...")
|
| 233 |
+
|
| 234 |
+
for i in range(num_images):
|
| 235 |
+
progress((i / num_images), desc=f"{i+1}/{num_images} ์ด๋ฏธ์ง ์์ฑ ์ค...")
|
| 236 |
+
result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, i, max_retries)
|
| 237 |
+
|
| 238 |
+
if result_img is not None:
|
| 239 |
+
results.append(result_img)
|
| 240 |
+
statuses.append(f"์ด๋ฏธ์ง #{i+1}: {status}")
|
| 241 |
+
prompts.append(f"์ด๋ฏธ์ง #{i+1}: {final_prompt}")
|
| 242 |
+
else:
|
| 243 |
+
results.append(None)
|
| 244 |
+
statuses.append(f"์ด๋ฏธ์ง #{i+1} ์์ฑ ์คํจ: {status}")
|
| 245 |
+
prompts.append(f"์ด๋ฏธ์ง #{i+1}: {final_prompt}")
|
| 246 |
+
|
| 247 |
+
time.sleep(1)
|
| 248 |
+
|
| 249 |
+
progress(1.0, desc="์ด๋ฏธ์ง ์์ฑ ์๋ฃ!")
|
| 250 |
+
|
| 251 |
+
while len(results) < 2:
|
| 252 |
+
results.append(None)
|
| 253 |
+
|
| 254 |
+
combined_status = "\n".join(statuses)
|
| 255 |
+
combined_prompts = "\n".join(prompts)
|
| 256 |
+
|
| 257 |
+
return results[0], results[1], combined_status, combined_prompts
|
| 258 |
+
|
| 259 |
+
# ๋คํฌ๋ชจ๋ ์๋ ์ ์ฉ ์ปค์คํ
CSS ์คํ์ผ
|
| 260 |
+
custom_css = """
|
| 261 |
+
/* ============================================
|
| 262 |
+
๋คํฌ๋ชจ๋ ์๋ ๋ณ๊ฒฝ ํ
ํ๋ฆฟ CSS
|
| 263 |
+
============================================ */
|
| 264 |
+
|
| 265 |
+
/* 1. CSS ๋ณ์ ์ ์ (๋ผ์ดํธ๋ชจ๋ - ๊ธฐ๋ณธ๊ฐ) */
|
| 266 |
+
:root {
|
| 267 |
+
/* ๋ฉ์ธ ์ปฌ๋ฌ */
|
| 268 |
+
--primary-color: #FB7F0D;
|
| 269 |
+
--secondary-color: #ff9a8b;
|
| 270 |
+
--accent-color: #FF6B6B;
|
| 271 |
+
|
| 272 |
+
/* ๋ฐฐ๊ฒฝ ์ปฌ๋ฌ */
|
| 273 |
+
--background-color: #FFFFFF;
|
| 274 |
+
--card-bg: #ffffff;
|
| 275 |
+
--input-bg: #ffffff;
|
| 276 |
+
|
| 277 |
+
/* ํ
์คํธ ์ปฌ๋ฌ */
|
| 278 |
+
--text-color: #334155;
|
| 279 |
+
--text-secondary: #64748b;
|
| 280 |
+
|
| 281 |
+
/* ๋ณด๋ ๋ฐ ๊ตฌ๋ถ์ */
|
| 282 |
+
--border-color: #dddddd;
|
| 283 |
+
--border-light: #e5e5e5;
|
| 284 |
+
|
| 285 |
+
/* ํ
์ด๋ธ ์ปฌ๋ฌ */
|
| 286 |
+
--table-even-bg: #f3f3f3;
|
| 287 |
+
--table-hover-bg: #f0f0f0;
|
| 288 |
+
|
| 289 |
+
/* ๊ทธ๋ฆผ์ */
|
| 290 |
+
--shadow: 0 8px 30px rgba(251, 127, 13, 0.08);
|
| 291 |
+
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 292 |
+
|
| 293 |
+
/* ๊ธฐํ */
|
| 294 |
+
--border-radius: 18px;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
/* 2. ๋คํฌ๋ชจ๋ ์์ ๋ณ์ (์๋ ๊ฐ์ง) */
|
| 298 |
+
@media (prefers-color-scheme: dark) {
|
| 299 |
+
:root {
|
| 300 |
+
/* ๋ฐฐ๊ฒฝ ์ปฌ๋ฌ */
|
| 301 |
+
--background-color: #1a1a1a;
|
| 302 |
+
--card-bg: #2d2d2d;
|
| 303 |
+
--input-bg: #2d2d2d;
|
| 304 |
+
|
| 305 |
+
/* ํ
์คํธ ์ปฌ๋ฌ */
|
| 306 |
+
--text-color: #e5e5e5;
|
| 307 |
+
--text-secondary: #a1a1aa;
|
| 308 |
+
|
| 309 |
+
/* ๋ณด๋ ๋ฐ ๊ตฌ๋ถ์ */
|
| 310 |
+
--border-color: #404040;
|
| 311 |
+
--border-light: #525252;
|
| 312 |
+
|
| 313 |
+
/* ํ
์ด๋ธ ์ปฌ๋ฌ */
|
| 314 |
+
--table-even-bg: #333333;
|
| 315 |
+
--table-hover-bg: #404040;
|
| 316 |
+
|
| 317 |
+
/* ๊ทธ๋ฆผ์ */
|
| 318 |
+
--shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
| 319 |
+
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
/* 3. ์๋ ๋คํฌ๋ชจ๋ ํด๋์ค (Gradio ํ ๊ธ์ฉ) */
|
| 324 |
+
[data-theme="dark"],
|
| 325 |
+
.dark,
|
| 326 |
+
.gr-theme-dark {
|
| 327 |
+
/* ๋ฐฐ๊ฒฝ ์ปฌ๋ฌ */
|
| 328 |
+
--background-color: #1a1a1a;
|
| 329 |
+
--card-bg: #2d2d2d;
|
| 330 |
+
--input-bg: #2d2d2d;
|
| 331 |
+
|
| 332 |
+
/* ํ
์คํธ ์ปฌ๋ฌ */
|
| 333 |
+
--text-color: #e5e5e5;
|
| 334 |
+
--text-secondary: #a1a1aa;
|
| 335 |
+
|
| 336 |
+
/* ๋ณด๋ ๋ฐ ๊ตฌ๋ถ์ */
|
| 337 |
+
--border-color: #404040;
|
| 338 |
+
--border-light: #525252;
|
| 339 |
+
|
| 340 |
+
/* ํ
์ด๋ธ ์ปฌ๋ฌ */
|
| 341 |
+
--table-even-bg: #333333;
|
| 342 |
+
--table-hover-bg: #404040;
|
| 343 |
+
|
| 344 |
+
/* ๊ทธ๋ฆผ์ */
|
| 345 |
+
--shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
| 346 |
+
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/* 4. ๊ธฐ๋ณธ ์์ ๋คํฌ๋ชจ๋ ์ ์ฉ */
|
| 350 |
+
body {
|
| 351 |
+
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 352 |
+
background-color: var(--background-color) !important;
|
| 353 |
+
color: var(--text-color) !important;
|
| 354 |
+
line-height: 1.6;
|
| 355 |
+
transition: background-color 0.3s ease, color 0.3s ease;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
/* 5. Gradio ์ปจํ
์ด๋ ๊ฐ์ ์ ์ฉ */
|
| 359 |
+
.gradio-container,
|
| 360 |
+
.gradio-container *,
|
| 361 |
+
.gr-app,
|
| 362 |
+
.gr-app *,
|
| 363 |
+
.gr-interface {
|
| 364 |
+
background-color: var(--background-color) !important;
|
| 365 |
+
color: var(--text-color) !important;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
/* Gradio ์ปจํ
์ด๋ ์ค๋ฒ๋ผ์ด๋ */
|
| 369 |
+
.gradio-container {
|
| 370 |
+
max-width: 100% !important;
|
| 371 |
+
width: 100% !important;
|
| 372 |
+
margin: 0 auto !important;
|
| 373 |
+
padding: 0 !important;
|
| 374 |
+
background-color: var(--background-color) !important;
|
| 375 |
+
box-sizing: border-box !important;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
/* ์ถ๊ฐ: ๋ด๋ถ ์ปจํ
์ด๋๋ 100% ๋๋น๋ก ์ค์ */
|
| 379 |
+
.contain {
|
| 380 |
+
max-width: 100% !important;
|
| 381 |
+
width: 100% !important;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/* ์ถ๊ฐ: ๊ฐ ํ(Row)๋ 100% ๋๋น๋ก ์ค์ */
|
| 385 |
+
.gr-padded {
|
| 386 |
+
padding: 0 !important;
|
| 387 |
+
width: 100% !important;
|
| 388 |
+
max-width: 100% !important;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
/* 6. ์นด๋ ๋ฐ ํจ๋ ์คํ์ผ */
|
| 392 |
+
.gr-group,
|
| 393 |
+
.gr-form,
|
| 394 |
+
.gr-box,
|
| 395 |
+
.gr-panel,
|
| 396 |
+
.custom-frame,
|
| 397 |
+
[class*="frame"],
|
| 398 |
+
[class*="card"],
|
| 399 |
+
[class*="panel"] {
|
| 400 |
+
background-color: var(--card-bg) !important;
|
| 401 |
+
border-radius: var(--border-radius) !important;
|
| 402 |
+
box-shadow: var(--shadow) !important;
|
| 403 |
+
padding: 1.5rem !important;
|
| 404 |
+
margin-bottom: 1.5rem !important;
|
| 405 |
+
border: 1px solid var(--border-color) !important;
|
| 406 |
+
transition: transform 0.3s ease, background-color 0.3s ease;
|
| 407 |
+
color: var(--text-color) !important;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
.gr-group:hover {
|
| 411 |
+
transform: translateY(-5px);
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
/* 7. ์
๋ ฅ ํ๋ ์คํ์ผ */
|
| 415 |
+
input[type="text"],
|
| 416 |
+
input[type="number"],
|
| 417 |
+
input[type="email"],
|
| 418 |
+
input[type="password"],
|
| 419 |
+
textarea,
|
| 420 |
+
select,
|
| 421 |
+
.gr-input,
|
| 422 |
+
.gr-text-input,
|
| 423 |
+
.gr-textarea,
|
| 424 |
+
.gr-dropdown {
|
| 425 |
+
background-color: var(--input-bg) !important;
|
| 426 |
+
color: var(--text-color) !important;
|
| 427 |
+
border: 1px solid var(--border-color) !important;
|
| 428 |
+
border-radius: var(--border-radius) !important;
|
| 429 |
+
padding: 12px !important;
|
| 430 |
+
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
| 431 |
+
transition: all 0.3s ease !important;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
input[type="text"]:focus,
|
| 435 |
+
input[type="number"]:focus,
|
| 436 |
+
input[type="email"]:focus,
|
| 437 |
+
input[type="password"]:focus,
|
| 438 |
+
textarea:focus,
|
| 439 |
+
select:focus,
|
| 440 |
+
.gr-input:focus,
|
| 441 |
+
.gr-text-input:focus,
|
| 442 |
+
.gr-textarea:focus,
|
| 443 |
+
.gr-dropdown:focus {
|
| 444 |
+
border-color: var(--primary-color) !important;
|
| 445 |
+
outline: none !important;
|
| 446 |
+
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
/* 8. ๋ผ๋ฒจ ๋ฐ ํ
์คํธ ์์ */
|
| 450 |
+
label,
|
| 451 |
+
.gr-label,
|
| 452 |
+
.gr-checkbox label,
|
| 453 |
+
.gr-radio label,
|
| 454 |
+
p, span, div {
|
| 455 |
+
color: var(--text-color) !important;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
/* 9. ์น์
์ ๋ชฉ */
|
| 459 |
+
.section-title {
|
| 460 |
+
font-size: 22px !important;
|
| 461 |
+
font-weight: 700 !important;
|
| 462 |
+
color: var(--text-color) !important;
|
| 463 |
+
margin-bottom: 1rem !important;
|
| 464 |
+
padding-bottom: 0.5rem !important;
|
| 465 |
+
border-bottom: 2px solid var(--primary-color) !important;
|
| 466 |
+
display: flex;
|
| 467 |
+
align-items: center;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
.section-title span {
|
| 471 |
+
color: var(--primary-color);
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
/* 10. ๋ฒํผ ์คํ์ผ๋ง */
|
| 475 |
+
.custom-button {
|
| 476 |
+
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
| 477 |
+
color: white !important;
|
| 478 |
+
font-weight: 600 !important;
|
| 479 |
+
border: none !important;
|
| 480 |
+
border-radius: 30px !important;
|
| 481 |
+
padding: 12px 24px !important;
|
| 482 |
+
box-shadow: 0 4px 8px rgba(251, 127, 13, 0.25) !important;
|
| 483 |
+
transition: all 0.3s ease !important;
|
| 484 |
+
text-transform: none !important;
|
| 485 |
+
display: flex !important;
|
| 486 |
+
align-items: center !important;
|
| 487 |
+
justify-content: center !important;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
.custom-button:hover {
|
| 491 |
+
transform: translateY(-2px) !important;
|
| 492 |
+
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3) !important;
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
.custom-button.primary {
|
| 496 |
+
background: linear-gradient(135deg, var(--accent-color), #ff9a8b) !important;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"]) {
|
| 500 |
+
background-color: var(--card-bg) !important;
|
| 501 |
+
color: var(--text-color) !important;
|
| 502 |
+
border: 1px solid var(--border-color) !important;
|
| 503 |
+
border-radius: var(--border-radius) !important;
|
| 504 |
+
transition: all 0.3s ease !important;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
/* 11. ์ด๋ฏธ์ง ์ปจํ
์ด๋ */
|
| 508 |
+
.image-container {
|
| 509 |
+
border-radius: var(--border-radius);
|
| 510 |
+
overflow: hidden;
|
| 511 |
+
border: 1px solid var(--border-color);
|
| 512 |
+
transition: all 0.3s ease;
|
| 513 |
+
background-color: var(--card-bg);
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
.image-container:hover {
|
| 517 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
/* 12. ํ
์ด๋ธ ์คํ์ผ */
|
| 521 |
+
table {
|
| 522 |
+
background-color: var(--card-bg) !important;
|
| 523 |
+
color: var(--text-color) !important;
|
| 524 |
+
border-color: var(--border-color) !important;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
table th {
|
| 528 |
+
background-color: var(--primary-color) !important;
|
| 529 |
+
color: white !important;
|
| 530 |
+
border-color: var(--border-color) !important;
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
table td {
|
| 534 |
+
background-color: var(--card-bg) !important;
|
| 535 |
+
color: var(--text-color) !important;
|
| 536 |
+
border-color: var(--border-color) !important;
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
table tbody tr:nth-child(even) {
|
| 540 |
+
background-color: var(--table-even-bg) !important;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
table tbody tr:hover {
|
| 544 |
+
background-color: var(--table-hover-bg) !important;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
/* 13. ์ฒดํฌ๋ฐ์ค ๋ฐ ๋ผ๋์ค ๋ฒํผ */
|
| 548 |
+
input[type="checkbox"],
|
| 549 |
+
input[type="radio"] {
|
| 550 |
+
accent-color: var(--primary-color) !important;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
/* 14. ๋ฒํผ ๊ทธ๋ฃน */
|
| 554 |
+
.button-grid {
|
| 555 |
+
display: grid;
|
| 556 |
+
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
| 557 |
+
gap: 0.8rem;
|
| 558 |
+
margin-bottom: 1.2rem;
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
/* 15. ์คํฌ๋กค๋ฐ ์คํ์ผ */
|
| 562 |
+
::-webkit-scrollbar-thumb:hover {
|
| 563 |
+
background: var(--secondary-color);
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
/* 16. ์์ฝ๋์ธ ๋ฐ ๋๋กญ๋ค์ด */
|
| 567 |
+
details {
|
| 568 |
+
background-color: var(--card-bg) !important;
|
| 569 |
+
border-color: var(--border-color) !important;
|
| 570 |
+
color: var(--text-color) !important;
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
details summary {
|
| 574 |
+
background-color: var(--card-bg) !important;
|
| 575 |
+
color: var(--text-color) !important;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
/* 17. ํดํ ๋ฐ ํ์
*/
|
| 579 |
+
[data-tooltip]:hover::after,
|
| 580 |
+
.tooltip,
|
| 581 |
+
.popup {
|
| 582 |
+
background-color: var(--card-bg) !important;
|
| 583 |
+
color: var(--text-color) !important;
|
| 584 |
+
border-color: var(--border-color) !important;
|
| 585 |
+
box-shadow: var(--shadow-light) !important;
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
/* 18. ๋ชจ๋ฌ ๋ฐ ์ค๋ฒ๋ ์ด */
|
| 589 |
+
.modal,
|
| 590 |
+
.overlay,
|
| 591 |
+
[class*="modal"],
|
| 592 |
+
[class*="overlay"] {
|
| 593 |
+
background-color: var(--card-bg) !important;
|
| 594 |
+
color: var(--text-color) !important;
|
| 595 |
+
border-color: var(--border-color) !important;
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
/* 19. ์ถ๊ฐ Gradio ์ปดํฌ๋ํธ๋ค */
|
| 599 |
+
.gr-block,
|
| 600 |
+
.gr-group,
|
| 601 |
+
.gr-row,
|
| 602 |
+
.gr-column {
|
| 603 |
+
background-color: var(--background-color) !important;
|
| 604 |
+
color: var(--text-color) !important;
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
/* 20. ์ฝ๋ ๋ธ๋ก ๋ฐ pre ํ๊ทธ */
|
| 608 |
+
code,
|
| 609 |
+
pre,
|
| 610 |
+
.code-block {
|
| 611 |
+
background-color: var(--table-even-bg) !important;
|
| 612 |
+
color: var(--text-color) !important;
|
| 613 |
+
border-color: var(--border-color) !important;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
/* 21. ์๋ฆผ ๋ฐ ๋ฉ์์ง */
|
| 617 |
+
.alert,
|
| 618 |
+
.message,
|
| 619 |
+
.notification,
|
| 620 |
+
[class*="alert"],
|
| 621 |
+
[class*="message"],
|
| 622 |
+
[class*="notification"] {
|
| 623 |
+
background-color: var(--card-bg) !important;
|
| 624 |
+
color: var(--text-color) !important;
|
| 625 |
+
border-color: var(--border-color) !important;
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
/* 22. ์ ๋๋ฉ์ด์
์คํ์ผ */
|
| 629 |
+
@keyframes fadeIn {
|
| 630 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 631 |
+
to { opacity: 1; transform: translateY(0); }
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
.fade-in {
|
| 635 |
+
animation: fadeIn 0.5s ease-out;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
/* 23. Examples ์น์
์คํ์ผ */
|
| 639 |
+
.examples-section {
|
| 640 |
+
display: grid;
|
| 641 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 642 |
+
gap: 1.5rem;
|
| 643 |
+
margin-top: 1rem;
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
.example-item {
|
| 647 |
+
background-color: var(--card-bg);
|
| 648 |
+
border-radius: var(--border-radius);
|
| 649 |
+
overflow: hidden;
|
| 650 |
+
box-shadow: var(--shadow);
|
| 651 |
+
transition: transform 0.3s ease, background-color 0.3s ease;
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
.example-item:hover {
|
| 655 |
+
transform: translateY(-5px);
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
/* 24. ์ ํ ์ ๋๋ฉ์ด์
*/
|
| 659 |
+
* {
|
| 660 |
+
transition: background-color 0.3s ease,
|
| 661 |
+
color 0.3s ease,
|
| 662 |
+
border-color 0.3s ease !important;
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
/* 25. ๋ฐ์ํ */
|
| 666 |
+
@media (max-width: 768px) {
|
| 667 |
+
.button-grid {
|
| 668 |
+
grid-template-columns: repeat(2, 1fr);
|
| 669 |
+
}
|
| 670 |
+
.examples-section {
|
| 671 |
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
"""
|
| 675 |
+
|
| 676 |
+
# FontAwesome ์์ด์ฝ ํฌํจ
|
| 677 |
+
fontawesome_link = """
|
| 678 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
| 679 |
+
"""
|
| 680 |
+
|
| 681 |
+
# ์ ๋ชฉ๊ณผ ์ฌ์ฉ ๊ฐ์ด๋ ์ ๊ฑฐ
|
| 682 |
+
header_html = ""
|
| 683 |
+
image_generator_guide_html = ""
|
| 684 |
+
|
| 685 |
+
# UI ๊ตฌ์ฑ
|
| 686 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Default(
|
| 687 |
+
primary_hue="orange",
|
| 688 |
+
secondary_hue="orange",
|
| 689 |
+
font=[gr.themes.GoogleFont("Noto Sans KR"), "ui-sans-serif", "system-ui"]
|
| 690 |
+
)) as demo:
|
| 691 |
+
gr.HTML(fontawesome_link)
|
| 692 |
+
|
| 693 |
+
# ํญ ์ ๊ฑฐํ๊ณ ์ด๋ฏธ์ง ์์ฑ๊ธฐ ๋ด์ฉ์ ์ง์ ๋ฐฐ์น
|
| 694 |
+
with gr.Row(equal_height=True):
|
| 695 |
+
with gr.Column(scale=1):
|
| 696 |
+
# ======== ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์ค์ ์น์
========
|
| 697 |
+
with gr.Group():
|
| 698 |
+
gr.HTML('<div class="section-title"><i class="fas fa-upload"></i> <span>์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์ค์ </span></div>')
|
| 699 |
+
with gr.Row():
|
| 700 |
+
image1_input = gr.Image(type="pil", label="#1", image_mode="RGB", elem_classes="image-container", height=400)
|
| 701 |
+
image2_input = gr.Image(type="pil", label="#2", image_mode="RGB", elem_classes="image-container", height=400)
|
| 702 |
+
image3_input = gr.Image(type="pil", label="#3", image_mode="RGB", elem_classes="image-container", height=400)
|
| 703 |
+
|
| 704 |
+
# ํ๋กฌํํธ ์
๋ ฅ ํ๋ ์ถ๊ฐ
|
| 705 |
+
prompt_input = gr.Textbox(
|
| 706 |
+
lines=3,
|
| 707 |
+
placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๋น์๋๋ฉด ์๋ ํฉ์ฑ๋ฉ๋๋ค. '#1', '#2', '#3'์ผ๋ก ๊ฐ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํ ์ ์์ต๋๋ค.",
|
| 708 |
+
label="ํ๋กฌํํธ (์ ํ ์ฌํญ)",
|
| 709 |
+
elem_classes="gr-text-input"
|
| 710 |
+
)
|
| 711 |
+
|
| 712 |
+
# ======== ๋ณํ ์ต์
์น์
========
|
| 713 |
+
with gr.Group():
|
| 714 |
+
gr.HTML('<div class="section-title"><i class="fas fa-sliders-h"></i> <span>ํ๋กฌํํธ ํ
ํ๋ฆฟ</span></div>')
|
| 715 |
+
with gr.Column(elem_classes="button-grid"):
|
| 716 |
+
image_change_btn1 = gr.Button('๐ ๋ถ๋ถ๋ณ๊ฒฝ-1', elem_classes="custom-button")
|
| 717 |
+
image_change_btn2 = gr.Button('๐ ๋ถ๋ถ๋ณ๊ฒฝ-2', elem_classes="custom-button")
|
| 718 |
+
image_change_btn3= gr.Button('๐ ๋ถ๋ถ๋ณ๊ฒฝ-3', elem_classes="custom-button")
|
| 719 |
+
text_remove_btn = gr.Button('๐งน ๊ธ์์ง์ฐ๊ธฐ', elem_classes="custom-button")
|
| 720 |
+
text_change_btn = gr.Button('๐ค ๊ธ์๋ณ๊ฒฝ', elem_classes="custom-button")
|
| 721 |
+
clothes_change_btn1 = gr.Button('๐ ์ํ์ฐฉ์ฉ-1', elem_classes="custom-button")
|
| 722 |
+
clothes_change_btn2 = gr.Button('๐ ์ํ์ฐฉ์ฉ-2', elem_classes="custom-button")
|
| 723 |
+
holding_product_btn = gr.Button('๐ท ์ํ๋ค๊ณ ', elem_classes="custom-button")
|
| 724 |
+
background_change_btn = gr.Button('๐ผ๏ธ ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ', elem_classes="custom-button")
|
| 725 |
+
composite_product_btn = gr.Button('โ๏ธ ๋ถ๋ถ์ง์ฐ๊ธฐ', elem_classes="custom-button")
|
| 726 |
+
outpainting_btn = gr.Button('๐ ์ด๋ฏธ์งํ์ฅ', elem_classes="custom-button")
|
| 727 |
+
food_btn_1 = gr.Button('๐ฝ๏ธ ํ๋ ์ดํ
-1', elem_classes="custom-button")
|
| 728 |
+
food_btn_2 = gr.Button('๐ฝ๏ธ ํ๋ ์ดํ
-2', elem_classes="custom-button")
|
| 729 |
+
food_btn_3 = gr.Button('๐ฝ๏ธ ํ๋ ์ดํ
-3', elem_classes="custom-button")
|
| 730 |
+
|
| 731 |
+
# ======== ์ด๋ฏธ์ง ์์ฑ ์น์
========
|
| 732 |
+
with gr.Group():
|
| 733 |
+
gr.HTML('<div class="section-title"><i class="fas fa-image"></i> <span>์ด๋ฏธ์ง ์์ฑ</span></div>')
|
| 734 |
+
submit_single_btn = gr.Button('โจ ์ด๋ฏธ์ง ์์ฑ (1์ฅ)', elem_classes="custom-button primary")
|
| 735 |
+
submit_btn = gr.Button('โจ ์ด๋ฏธ์ง ์์ฑ (2์ฅ)', elem_classes="custom-button primary")
|
| 736 |
+
|
| 737 |
+
with gr.Column(scale=1):
|
| 738 |
+
# ======== ์์ฑ๋ ์ด๋ฏธ์ง ์น์
========
|
| 739 |
+
with gr.Group():
|
| 740 |
+
gr.HTML('<div class="section-title"><i class="fas fa-images"></i> <span>์์ฑ๋ ์ด๋ฏธ์ง</span></div>')
|
| 741 |
+
with gr.Row():
|
| 742 |
+
with gr.Column():
|
| 743 |
+
output_image1 = gr.Image(label="์ด๋ฏธ์ง #1", elem_classes="image-container", height=400)
|
| 744 |
+
with gr.Column():
|
| 745 |
+
output_image2 = gr.Image(label="์ด๋ฏธ์ง #2", elem_classes="image-container", height=400)
|
| 746 |
+
|
| 747 |
+
# ======== ๊ฒฐ๊ณผ ์ ๋ณด ์น์
========
|
| 748 |
+
with gr.Group():
|
| 749 |
+
gr.HTML('<div class="section-title"><i class="fas fa-info-circle"></i> <span>๊ฒฐ๊ณผ ์ ๋ณด</span></div>')
|
| 750 |
+
output_text = gr.Textbox(label="์ํ ๋ฉ์์ง", lines=2, elem_classes="gr-text-input")
|
| 751 |
+
prompt_display = gr.Textbox(label="์ฌ์ฉ๋ ํ๋กฌํํธ (์์ด)", visible=True, lines=2, elem_classes="gr-text-input")
|
| 752 |
+
|
| 753 |
+
# ======== ์์ ์ด๋ฏธ์ง ์น์
========
|
| 754 |
+
gr.HTML('<div class="section-title"><i class="fas fa-lightbulb"></i> <span>์์ ์ด๋ฏธ์ง</span></div>')
|
| 755 |
+
|
| 756 |
+
# ๋ชจ๋ ์์ ํ ํ์ด์ง์ ํ์
|
| 757 |
+
examples = [
|
| 758 |
+
["down/๋ชจ๋ธ.jpg", None, None, "(#1์ ์ฌ์ฑ)์ด ์ด์ง ๋ค๋ก ๋์๋ณด๋ ๋ชจ์ต์ผ๋ก ์ต๋ํ ์ด์ seed๋ฅผ ์ ์งํ์ฒด ์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํ๋ผ."],
|
| 759 |
+
["down/์์ด๋ ๊ณ ๋ชจํ.png", None, None, "(#1 ๋ ๋ชจ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ง ๊ฒ์์ ๊ณ ๋๋ ๊ณ ๋ก ๋ณ๊ฒฝํ๊ณ ๋๋จธ์ง ๋ถ๋ถ์ seed๋ฅผ ๋ณ๊ฒฝ์ ํ์ง๋ง๋ผ."],
|
| 760 |
+
["down/์ผ์๊ฐ๋ฐฉ.png", None, None, "(#1 ์ฌํ์ฉ ์ผ์๋ฐ์ค)์์ ์ผ์์ด ๋ด๊ธด 3์์ ์ฝ๋ผ๊ฐ ๋์ฌ์๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ."],
|
| 761 |
+
["down/์ค๊ตญ์ด.png", None, None, "(#1 ์ด๋ฏธ์ง)์ ์๋ ์ค๊ตญ์ด๋ฅผ ๋ชจ๋ ์ ๊ฑฐํ๋ผ."],
|
| 762 |
+
["down/ํ
์คํธ.webp", None, None, '(#1์ ํ
์คํธ)๋ฅผ ์คํ์ผ์ ์ ์งํ์ฒด ํ
์คํธ๋ง "Hello"๋ก ๋ฐ๊ฟ๋ผ'],
|
| 763 |
+
["down/๋ชจ๋ธ2.png", "down/์ ๊ธ๋ผ์ค.png", "down/์ฒญ๋ฐ์ง.png", "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด (#2์ ์ ๊ธ๋ผ์ค)์ (#3์ ์ฒญ๋ฐ์ง)๋ฅผ ์ง์ ๋ชจ๋ธ์ด ์ฐฉ์ฉํ๊ฒ ์ฒ๋ผ ์์ฐ์ค๋ฝ๊ฒ ๋ชจ์ต์ ์์ฑํ๋ผ."],
|
| 764 |
+
["down/๋ชจ๋ธ2.png", "down/์ ๊ธ๋ผ์ค.png", "down/์นดํ์ ๊ฒฝ.png", "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2์ ์ ๊ธ๋ผ์ค)์ ์ฐฉ์ฉํ๊ณ (#3์ ๋ท๋ฐฐ๊ฒฝ์ ์นดํ์ ์ฒด๊ฐ ๋ณด์ด๋ฉฐ) ์์์ ์์ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ."],
|
| 765 |
+
["down/๋ชจ๋ธ2.png", "down/์์ธ์.png", None, "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด(#2์ ์์ธ์)์ ๋ค๊ณ ์๋ ์์ฐ์ค๋ฌ์ด ๋ชจ์ต์ ์์ฑํ๋ผ."],
|
| 766 |
+
["down/๋ชจ๋ธ2.png", "down/์นดํ์ ๊ฒฝ.png", None, "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2 ์นดํ)์์ ์์ฐ์ค๋ฝ๊ฒ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ."],
|
| 767 |
+
["down/์์ด๋ ๊ณ ๋ชจํ.png", None, None, "(#1์ ๋ ๊ณ ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ฅผ ์ ๊ฑฐํ ํ, ๊ทธ ์๋ฆฌ๋ฅผ ์ฃผ๋ณ ๋ฐฐ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ฐ๋ฌ์ง๋๋ก ์ฑ์์ฃผ์ธ์. ๋จ, ์ด๋ฏธ์ง์ ๋ค๋ฅธ ๋ถ๋ถ์ ์ฃผ์ ์์๋ ๋์ผํ๊ฒ ์ ์งํด์ผํ๋ค."],
|
| 768 |
+
["down/์นดํ์ ๊ฒฝ.png", None, None, "(#1 ์ด๋ฏธ์ง)๋ฅผ ์๋ณธ๊ทธ๋๋ก ์ค์์ ๋๊ณ ๋น์จ๋ก ์ ์งํ ์ฒด ์์๋ ๋ฐ ์ข์ฐ๋ก ํฌ๊ฒ ํ์ฅํ๋ผ."],
|
| 769 |
+
["down/์๋ฌ๋.png", None, None, "(#1์
๋ฌ๋)์ ๋ด์ ์ฉ๊ธฐ๋ ๋ฒ๋ฆฌ๊ณ ๋๊ณ ํฐ ์์ ์ ์์ (#1์
๋ฌ๋)์์๋ง ๊ฐ๋ ์ฑ์์ ์์
์ ์ธ ๊ฐ๋๋ก ์ด์ธ๋ฆฌ๋ ์ํ๊ณผ ํจ๊ป ํ๋ ์ดํ
ํ ๋ชจ์ต์ ์ด๋ฏธ์ง๋ก ์์ฑํ๋ผ. "],
|
| 770 |
+
["down/์๋ฌ๋.png", "down/ํ๋ ์ดํ
.png", None, "(#2 ํ๋ ์ดํ
ํ ์ด๋ฏธ์ง)์ ๋ด๊ธด ์์์ (#1 ์๋ฌ๋)๋ก ๋ฐ๊พธ๊ณ ๋๋จธ์ง๋ ์๋๋ฅผ ์ ์งํ ์ฒด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ."],
|
| 771 |
+
["down/์ปต.png", None, None, "(#1์ปต)์ ๋ธ๊ธฐ, ๋ฐ๋๋ผ, ์ด์ฝ ์์ด์คํฌ๋ฆผ์ ๋ด๊ณ ๊ทธ ์์ ์ด์ฝ ์๋ฝ์ด ํ๋ฅด๊ฒ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ."]
|
| 772 |
+
]
|
| 773 |
+
|
| 774 |
+
# ๋ชจ๋ ์์ ๋ฅผ ํ ํ์ด์ง์ ํ์ํ๋๋ก ์์ ๋ ๋ถ๋ถ
|
| 775 |
+
gr.Examples(
|
| 776 |
+
examples=examples,
|
| 777 |
+
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 778 |
+
examples_per_page=len(examples) # ๋ชจ๋ ์์ ๋ฅผ ํ ํ์ด์ง์ ํ์
|
| 779 |
+
)
|
| 780 |
+
|
| 781 |
+
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ์ด๋ฒคํธ ์ฐ๊ฒฐ ==========
|
| 782 |
+
# ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 783 |
+
image_change_btn1.click(
|
| 784 |
+
fn=lambda: "(#1์ ์ฌ์ฑ)์ด ์ด์ง ๋ค๋ก ๋์๋ณด๋ ๋ชจ์ต์ผ๋ก ์ต๋ํ ์ด์ seed๋ฅผ ์ ์งํํ
์์ฐ๏ฟฝ๏ฟฝ๋ฝ๊ฒ ๋ณ๊ฒฝํ๋ผ.",
|
| 785 |
+
inputs=[],
|
| 786 |
+
outputs=prompt_input
|
| 787 |
+
)
|
| 788 |
+
image_change_btn2.click(
|
| 789 |
+
fn=lambda: "(#1 ๋ ๋ชจ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ง ๊ฒ์์ ๊ณ ๋๋ ๊ณ ๋ก ๋ณ๊ฒฝํ๊ณ ๋๋จธ์ง ๋ถ๋ถ์ seed๋ฅผ ๋ณ๊ฒฝ์ ํ์ง๋ง๋ผ.",
|
| 790 |
+
inputs=[],
|
| 791 |
+
outputs=prompt_input
|
| 792 |
+
)
|
| 793 |
+
image_change_btn3.click(
|
| 794 |
+
fn=lambda: "(#1 ์ฌํ์ฉ ์ผ์๋ฐ์ค)์์ ์ผ์์ด ๋ด๊ธด 3์์ ์ฝ๋ผ๊ฐ ๋์ฌ์๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ.",
|
| 795 |
+
inputs=[],
|
| 796 |
+
outputs=prompt_input
|
| 797 |
+
)
|
| 798 |
+
|
| 799 |
+
text_remove_btn.click(
|
| 800 |
+
fn=lambda: "(#1 ์ด๋ฏธ์ง)์ ์๋ ์ค๊ตญ์ด๋ฅผ ๋ชจ๋ ์ ๊ฑฐํ๋ผ.",
|
| 801 |
+
inputs=[],
|
| 802 |
+
outputs=prompt_input
|
| 803 |
+
)
|
| 804 |
+
text_change_btn.click(
|
| 805 |
+
fn=lambda: '(#1์ ํ
์คํธ)๋ฅผ ์คํ์ผ์ ์ ์งํ์ฒด ํ
์คํธ๋ง "Hello"๋ก ๋ฐ๊ฟ๋ผ',
|
| 806 |
+
inputs=[],
|
| 807 |
+
outputs=prompt_input
|
| 808 |
+
)
|
| 809 |
+
clothes_change_btn1.click(
|
| 810 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด (#2์ ์ ๊ธ๋ผ์ค)์ (#3์ ์ฒญ๋ฐ์ง)๋ฅผ ์ง์ ๋ชจ๋ธ์ด ์ฐฉ์ฉํ๊ฒ ์ฒ๋ผ ์์ฐ์ค๋ฝ๊ฒ ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 811 |
+
inputs=[],
|
| 812 |
+
outputs=prompt_input
|
| 813 |
+
)
|
| 814 |
+
clothes_change_btn2.click(
|
| 815 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2์ ์ ๊ธ๋ผ์ค)์ ์ฐฉ์ฉํ๊ณ (#3์ ๋ท๋ฐฐ๊ฒฝ์ ์นดํ์ ์ฒด๊ฐ ๋ณด์ด๋ฉฐ) ์์์ ์์ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 816 |
+
inputs=[],
|
| 817 |
+
outputs=prompt_input
|
| 818 |
+
)
|
| 819 |
+
holding_product_btn.click(
|
| 820 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด(#2์ ์์ธ์)์ ๋ค๊ณ ์๋ ์์ฐ์ค๋ฌ์ด ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 821 |
+
inputs=[],
|
| 822 |
+
outputs=prompt_input
|
| 823 |
+
)
|
| 824 |
+
background_change_btn.click(
|
| 825 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2 ์นดํ)์์ ์์ฐ์ค๋ฝ๊ฒ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 826 |
+
inputs=[],
|
| 827 |
+
outputs=prompt_input
|
| 828 |
+
)
|
| 829 |
+
composite_product_btn.click(
|
| 830 |
+
fn=lambda: "(#1์ ๋ ๊ณ ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ฅผ ์ ๊ฑฐํ ํ, ๊ทธ ์๋ฆฌ๋ฅผ ์ฃผ๋ณ ๋ฐฐ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ฐ๋ฌ์ง๋๋ก ์ฑ์์ฃผ์ธ์. ๋จ, ์ด๋ฏธ์ง์ ๋ค๋ฅธ ๋ถ๋ถ์ ์ฃผ์ ์์๋ ๋์ผํ๊ฒ ์ ์ง ํด์ผํ๋ค.",
|
| 831 |
+
inputs=[],
|
| 832 |
+
outputs=prompt_input
|
| 833 |
+
)
|
| 834 |
+
outpainting_btn.click(
|
| 835 |
+
fn=lambda: "(#1 ์ด๋ฏธ์ง)๋ฅผ ์๋ณธ๊ทธ๋๋ก ์ค์์ ๋๊ณ ๋น์จ๋ก ์ ์งํ ์ฒด ์์๋ ๋ฐ ์ข์ฐ๋ก ํฌ๊ฒ ํ์ฅํ๋ผ.",
|
| 836 |
+
inputs=[],
|
| 837 |
+
outputs=prompt_input
|
| 838 |
+
|
| 839 |
+
)
|
| 840 |
+
food_btn_1.click(
|
| 841 |
+
fn=lambda: "(#1์
๋ฌ๋)์ ๋ด์ ์ฉ๊ธฐ๋ ๋ฒ๋ฆฌ๊ณ ๋๊ณ ํฐ ์์ ์ ์์ (#1์
๋ฌ๋)์์๋ง ๊ฐ๋ ์ฑ์์ ์์
์ ์ธ ๊ฐ๋๋ก ์ด์ธ๋ฆฌ๋ ์ํ๊ณผ ํจ๊ป ํ๋ ์ดํ
ํ ๋ชจ์ต์ ์ด๋ฏธ์ง๋ก ์์ฑํ๋ผ. ",
|
| 842 |
+
inputs=[],
|
| 843 |
+
outputs=prompt_input
|
| 844 |
+
)
|
| 845 |
+
food_btn_2.click(
|
| 846 |
+
fn=lambda: "(#2 ํ๋ ์ดํ
ํ ์ด๋ฏธ์ง)์ ๋ด๊ธด ์์์ (#1 ์๋ฌ๋)๋ก ๋ฐ๊พธ๊ณ ๋๋จธ์ง๋ ์๋๋ฅผ ์ ์งํ ์ฒด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ.",
|
| 847 |
+
inputs=[],
|
| 848 |
+
outputs=prompt_input
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
food_btn_3.click(
|
| 852 |
+
fn=lambda: "(#1์ปต)์ ๋ธ๊ธฐ, ๋ฐ๋๋ผ, ์ด์ฝ ์์ด์คํฌ๋ฆผ์ ๋ด๊ณ ๊ทธ ์์ ์ด์ฝ ์๋ฝ์ด ํ๋ฅด๊ฒ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ.",
|
| 853 |
+
inputs=[],
|
| 854 |
+
outputs=prompt_input
|
| 855 |
+
)
|
| 856 |
+
|
| 857 |
+
# ๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 858 |
+
def generate_single_image(image1, image2, image3, prompt):
|
| 859 |
+
return process_images_with_prompt(image1, image2, image3, prompt, 0, 3)
|
| 860 |
+
|
| 861 |
+
submit_single_btn.click(
|
| 862 |
+
fn=generate_single_image,
|
| 863 |
+
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 864 |
+
outputs=[output_image1, output_text, prompt_display],
|
| 865 |
+
)
|
| 866 |
+
|
| 867 |
+
# 2์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 868 |
+
submit_btn.click(
|
| 869 |
+
fn=generate_multiple_images,
|
| 870 |
+
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 871 |
+
outputs=[output_image1, output_image2, output_text, prompt_display],
|
| 872 |
+
)
|
| 873 |
+
|
| 874 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 875 |
+
if __name__ == "__main__":
|
| 876 |
+
# API ์๋ํฌ์ธํธ ํ์ธ
|
| 877 |
+
endpoint = get_api_endpoint()
|
| 878 |
+
if endpoint:
|
| 879 |
+
logger.info("์ปจํธ๋กค ํ์๊ฐ ์์๋์์ต๋๋ค.")
|
| 880 |
+
else:
|
| 881 |
+
logger.warning("API_ENDPOINT ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํด์ฃผ์ธ์.")
|
| 882 |
+
|
| 883 |
+
demo.queue()
|
| 884 |
+
demo.launch(share=False, inbrowser=True, width="100%")
|