Update app.py
Browse files
app.py
CHANGED
|
@@ -10,8 +10,10 @@ import numpy as np
|
|
| 10 |
from io import BytesIO
|
| 11 |
from datetime import datetime, timedelta
|
| 12 |
import random
|
|
|
|
|
|
|
|
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
-
from gradio_client import Client, handle_file
|
| 15 |
|
| 16 |
load_dotenv()
|
| 17 |
|
|
@@ -19,182 +21,340 @@ load_dotenv()
|
|
| 19 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 20 |
logger = logging.getLogger(__name__)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
if not API_ENDPOINT:
|
| 27 |
-
raise ValueError("API_ENDPOINT ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 28 |
-
|
| 29 |
-
# ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
| 30 |
-
try:
|
| 31 |
-
client = Client(API_ENDPOINT)
|
| 32 |
-
logger.info("ํด๋ผ์ด์ธํธ ์ด๊ธฐํ ์๋ฃ")
|
| 33 |
-
except Exception as e:
|
| 34 |
-
logger.error(f"ํด๋ผ์ด์ธํธ ์ด๊ธฐํ ์คํจ: {e}")
|
| 35 |
-
raise
|
| 36 |
-
|
| 37 |
-
def safe_client_call(api_name, **kwargs):
|
| 38 |
-
"""์์ ํ ํด๋ผ์ด์ธํธ ํธ์ถ ํจ์"""
|
| 39 |
-
try:
|
| 40 |
-
return client.predict(api_name=api_name, **kwargs)
|
| 41 |
-
except Exception as e:
|
| 42 |
-
logger.error(f"API ํธ์ถ ์คํจ ({api_name}): {e}")
|
| 43 |
-
return None
|
| 44 |
-
|
| 45 |
-
def convert_image_to_file(image):
|
| 46 |
-
"""PIL Image ๊ฐ์ฒด๋ฅผ ์์ ํ์ผ๋ก ๋ณํ"""
|
| 47 |
-
if image is None:
|
| 48 |
-
return None
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
if hasattr(image, 'save'):
|
| 53 |
-
# ์์ ํ์ผ ์์ฑ
|
| 54 |
-
temp_file = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
| 55 |
-
image.save(temp_file.name, format='PNG')
|
| 56 |
-
temp_file.close()
|
| 57 |
-
return temp_file.name
|
| 58 |
-
# ์ด๋ฏธ ํ์ผ ๊ฒฝ๋ก์ธ ๊ฒฝ์ฐ
|
| 59 |
-
elif isinstance(image, str):
|
| 60 |
-
return image
|
| 61 |
-
# ๊ธฐํ ๊ฒฝ์ฐ
|
| 62 |
-
else:
|
| 63 |
-
return image
|
| 64 |
-
except Exception as e:
|
| 65 |
-
logger.error(f"์ด๋ฏธ์ง ํ์ผ ๋ณํ ์คํจ: {e}")
|
| 66 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ๊ด๋ จ ํจ์
|
| 69 |
-
def
|
| 70 |
-
""
|
| 71 |
-
|
| 72 |
-
# ์ด๋ฏธ์ง ํ์ผ ์ฒ๋ฆฌ - PIL Image๋ฅผ ์์ ํ์ผ๋ก ๋ณํ
|
| 73 |
-
image1_path = convert_image_to_file(image1)
|
| 74 |
-
image2_path = convert_image_to_file(image2)
|
| 75 |
-
image3_path = convert_image_to_file(image3)
|
| 76 |
-
|
| 77 |
-
# handle_file๋ก ์ฒ๋ฆฌ
|
| 78 |
-
image1_file = handle_file(image1_path) if image1_path else None
|
| 79 |
-
image2_file = handle_file(image2_path) if image2_path else None
|
| 80 |
-
image3_file = handle_file(image3_path) if image3_path else None
|
| 81 |
-
|
| 82 |
-
result = safe_client_call(
|
| 83 |
-
"/generate_single_image",
|
| 84 |
-
image1=image1_file,
|
| 85 |
-
image2=image2_file,
|
| 86 |
-
image3=image3_file,
|
| 87 |
-
prompt=prompt
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
if result:
|
| 91 |
-
return result[0], result[1], result[2]
|
| 92 |
-
else:
|
| 93 |
-
return None, "API ํธ์ถ ์คํจ", ""
|
| 94 |
-
|
| 95 |
-
except Exception as e:
|
| 96 |
-
logger.error(f"๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ์คํจ: {e}")
|
| 97 |
-
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", ""
|
| 98 |
|
| 99 |
-
def
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
try:
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
image1_file = handle_file(image1_path) if image1_path else None
|
| 111 |
-
image2_file = handle_file(image2_path) if image2_path else None
|
| 112 |
-
image3_file = handle_file(image3_path) if image3_path else None
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
)
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
if
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
else:
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
| 131 |
except Exception as e:
|
| 132 |
-
logger.
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
return '(#1์ ํ
์คํธ)๋ฅผ ์คํ์ผ์ ์ ์งํ์ฒด ํ
์คํธ๋ง "Hello"๋ก ๋ฐ๊ฟ๋ผ'
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
return "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด (#2์ ์ ๊ธ๋ผ์ค)์ (#3์ ์ฒญ๋ฐ์ง)๋ฅผ ์ง์ ๋ชจ๋ธ์ด ์ฐฉ์ฉํ๊ฒ ์ฒ๋ผ ์์ฐ์ค๋ฝ๊ฒ ๋ชจ์ต์ ์์ฑํ๋ผ."
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
return "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2์ ์ ๊ธ๋ผ์ค)์ ์ฐฉ์ฉํ๊ณ (#3์ ๋ท๋ฐฐ๊ฒฝ์ ์นดํ์ ์ฒด๊ฐ ๋ณด์ด๋ฉฐ) ์์์ ์์ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ."
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
return "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด(#2์ ์์ธ์)์ ๋ค๊ณ ์๋ ์์ฐ์ค๋ฌ์ด ๋ชจ์ต์ ์์ฑํ๋ผ."
|
| 167 |
|
| 168 |
-
def
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
return "(#1์ ๋ ๊ณ ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ฅผ ์ ๊ฑฐํ ํ, ๊ทธ ์๋ฆฌ๋ฅผ ์ฃผ๋ณ ๋ฐฐ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ฐ๋ฌ์ง๋๋ก ์ฑ์์ฃผ์ธ์. ๋จ, ์ด๋ฏธ์ง์ ๋ค๋ฅธ ๋ถ๋ถ์ ์ฃผ์ ์์๋ ๋์ผํ๊ฒ ์ ์ง ํด์ผํ๋ค."
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
def
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
def
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
# ๋คํฌ๋ชจ๋ ์๋ ์ ์ฉ ์ปค์คํ
CSS ์คํ์ผ
|
| 193 |
custom_css = """
|
| 194 |
/* ============================================
|
| 195 |
๋คํฌ๋ชจ๋ ์๋ ๋ณ๊ฒฝ ํ
ํ๋ฆฟ CSS
|
| 196 |
============================================ */
|
| 197 |
-
|
| 198 |
/* 1. CSS ๋ณ์ ์ ์ (๋ผ์ดํธ๋ชจ๋ - ๊ธฐ๋ณธ๊ฐ) */
|
| 199 |
:root {
|
| 200 |
/* ๋ฉ์ธ ์ปฌ๋ฌ */
|
|
@@ -226,7 +386,6 @@ custom_css = """
|
|
| 226 |
/* ๊ธฐํ */
|
| 227 |
--border-radius: 18px;
|
| 228 |
}
|
| 229 |
-
|
| 230 |
/* 2. ๋คํฌ๋ชจ๋ ์์ ๋ณ์ (์๋ ๊ฐ์ง) */
|
| 231 |
@media (prefers-color-scheme: dark) {
|
| 232 |
:root {
|
|
@@ -252,7 +411,6 @@ custom_css = """
|
|
| 252 |
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 253 |
}
|
| 254 |
}
|
| 255 |
-
|
| 256 |
/* 3. ์๋ ๋คํฌ๋ชจ๋ ํด๋์ค (Gradio ํ ๊ธ์ฉ) */
|
| 257 |
[data-theme="dark"],
|
| 258 |
.dark,
|
|
@@ -278,7 +436,6 @@ custom_css = """
|
|
| 278 |
--shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
| 279 |
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 280 |
}
|
| 281 |
-
|
| 282 |
/* 4. ๊ธฐ๋ณธ ์์ ๋คํฌ๋ชจ๋ ์ ์ฉ */
|
| 283 |
body {
|
| 284 |
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
@@ -287,7 +444,6 @@ body {
|
|
| 287 |
line-height: 1.6;
|
| 288 |
transition: background-color 0.3s ease, color 0.3s ease;
|
| 289 |
}
|
| 290 |
-
|
| 291 |
/* 5. Gradio ์ปจํ
์ด๋ ๊ฐ์ ์ ์ฉ */
|
| 292 |
.gradio-container,
|
| 293 |
.gradio-container *,
|
|
@@ -297,7 +453,6 @@ body {
|
|
| 297 |
background-color: var(--background-color) !important;
|
| 298 |
color: var(--text-color) !important;
|
| 299 |
}
|
| 300 |
-
|
| 301 |
/* Gradio ์ปจํ
์ด๋ ์ค๋ฒ๋ผ์ด๋ */
|
| 302 |
.gradio-container {
|
| 303 |
max-width: 100% !important;
|
|
@@ -307,20 +462,17 @@ body {
|
|
| 307 |
background-color: var(--background-color) !important;
|
| 308 |
box-sizing: border-box !important;
|
| 309 |
}
|
| 310 |
-
|
| 311 |
/* ์ถ๊ฐ: ๋ด๋ถ ์ปจํ
์ด๋๋ 100% ๋๋น๋ก ์ค์ */
|
| 312 |
.contain {
|
| 313 |
max-width: 100% !important;
|
| 314 |
width: 100% !important;
|
| 315 |
}
|
| 316 |
-
|
| 317 |
/* ์ถ๊ฐ: ๊ฐ ํ(Row)๋ 100% ๋๋น๋ก ์ค์ */
|
| 318 |
.gr-padded {
|
| 319 |
padding: 0 !important;
|
| 320 |
width: 100% !important;
|
| 321 |
max-width: 100% !important;
|
| 322 |
}
|
| 323 |
-
|
| 324 |
/* 6. ์นด๋ ๋ฐ ํจ๋ ์คํ์ผ */
|
| 325 |
.gr-group,
|
| 326 |
.gr-form,
|
|
@@ -339,11 +491,9 @@ body {
|
|
| 339 |
transition: transform 0.3s ease, background-color 0.3s ease;
|
| 340 |
color: var(--text-color) !important;
|
| 341 |
}
|
| 342 |
-
|
| 343 |
.gr-group:hover {
|
| 344 |
transform: translateY(-5px);
|
| 345 |
}
|
| 346 |
-
|
| 347 |
/* 7. ์
๋ ฅ ํ๋ ์คํ์ผ */
|
| 348 |
input[type="text"],
|
| 349 |
input[type="number"],
|
|
@@ -363,7 +513,6 @@ select,
|
|
| 363 |
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
| 364 |
transition: all 0.3s ease !important;
|
| 365 |
}
|
| 366 |
-
|
| 367 |
input[type="text"]:focus,
|
| 368 |
input[type="number"]:focus,
|
| 369 |
input[type="email"]:focus,
|
|
@@ -378,7 +527,6 @@ select:focus,
|
|
| 378 |
outline: none !important;
|
| 379 |
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
|
| 380 |
}
|
| 381 |
-
|
| 382 |
/* 8. ๋ผ๋ฒจ ๋ฐ ํ
์คํธ ์์ */
|
| 383 |
label,
|
| 384 |
.gr-label,
|
|
@@ -387,7 +535,6 @@ label,
|
|
| 387 |
p, span, div {
|
| 388 |
color: var(--text-color) !important;
|
| 389 |
}
|
| 390 |
-
|
| 391 |
/* 9. ์น์
์ ๋ชฉ */
|
| 392 |
.section-title {
|
| 393 |
font-size: 22px !important;
|
|
@@ -399,11 +546,9 @@ p, span, div {
|
|
| 399 |
display: flex;
|
| 400 |
align-items: center;
|
| 401 |
}
|
| 402 |
-
|
| 403 |
.section-title span {
|
| 404 |
color: var(--primary-color);
|
| 405 |
}
|
| 406 |
-
|
| 407 |
/* 10. ๋ฒํผ ์คํ์ผ๋ง */
|
| 408 |
.custom-button {
|
| 409 |
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
|
@@ -419,16 +564,13 @@ p, span, div {
|
|
| 419 |
align-items: center !important;
|
| 420 |
justify-content: center !important;
|
| 421 |
}
|
| 422 |
-
|
| 423 |
.custom-button:hover {
|
| 424 |
transform: translateY(-2px) !important;
|
| 425 |
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3) !important;
|
| 426 |
}
|
| 427 |
-
|
| 428 |
.custom-button.primary {
|
| 429 |
background: linear-gradient(135deg, var(--accent-color), #ff9a8b) !important;
|
| 430 |
}
|
| 431 |
-
|
| 432 |
button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"]) {
|
| 433 |
background-color: var(--card-bg) !important;
|
| 434 |
color: var(--text-color) !important;
|
|
@@ -436,7 +578,6 @@ button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"])
|
|
| 436 |
border-radius: var(--border-radius) !important;
|
| 437 |
transition: all 0.3s ease !important;
|
| 438 |
}
|
| 439 |
-
|
| 440 |
/* 11. ์ด๋ฏธ์ง ์ปจํ
์ด๋ */
|
| 441 |
.image-container {
|
| 442 |
border-radius: var(--border-radius);
|
|
@@ -445,44 +586,36 @@ button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"])
|
|
| 445 |
transition: all 0.3s ease;
|
| 446 |
background-color: var(--card-bg);
|
| 447 |
}
|
| 448 |
-
|
| 449 |
.image-container:hover {
|
| 450 |
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 451 |
}
|
| 452 |
-
|
| 453 |
/* 12. ํ
์ด๋ธ ์คํ์ผ */
|
| 454 |
table {
|
| 455 |
background-color: var(--card-bg) !important;
|
| 456 |
color: var(--text-color) !important;
|
| 457 |
border-color: var(--border-color) !important;
|
| 458 |
}
|
| 459 |
-
|
| 460 |
table th {
|
| 461 |
background-color: var(--primary-color) !important;
|
| 462 |
color: white !important;
|
| 463 |
border-color: var(--border-color) !important;
|
| 464 |
}
|
| 465 |
-
|
| 466 |
table td {
|
| 467 |
background-color: var(--card-bg) !important;
|
| 468 |
color: var(--text-color) !important;
|
| 469 |
border-color: var(--border-color) !important;
|
| 470 |
}
|
| 471 |
-
|
| 472 |
table tbody tr:nth-child(even) {
|
| 473 |
background-color: var(--table-even-bg) !important;
|
| 474 |
}
|
| 475 |
-
|
| 476 |
table tbody tr:hover {
|
| 477 |
background-color: var(--table-hover-bg) !important;
|
| 478 |
}
|
| 479 |
-
|
| 480 |
/* 13. ์ฒดํฌ๋ฐ์ค ๋ฐ ๋ผ๋์ค ๋ฒํผ */
|
| 481 |
input[type="checkbox"],
|
| 482 |
input[type="radio"] {
|
| 483 |
accent-color: var(--primary-color) !important;
|
| 484 |
}
|
| 485 |
-
|
| 486 |
/* 14. ๋ฒํผ ๊ทธ๋ฃน */
|
| 487 |
.button-grid {
|
| 488 |
display: grid;
|
|
@@ -490,24 +623,20 @@ input[type="radio"] {
|
|
| 490 |
gap: 0.8rem;
|
| 491 |
margin-bottom: 1.2rem;
|
| 492 |
}
|
| 493 |
-
|
| 494 |
/* 15. ์คํฌ๋กค๋ฐ ์คํ์ผ */
|
| 495 |
::-webkit-scrollbar-thumb:hover {
|
| 496 |
background: var(--secondary-color);
|
| 497 |
}
|
| 498 |
-
|
| 499 |
/* 16. ์์ฝ๋์ธ ๋ฐ ๋๋กญ๋ค์ด */
|
| 500 |
details {
|
| 501 |
background-color: var(--card-bg) !important;
|
| 502 |
border-color: var(--border-color) !important;
|
| 503 |
color: var(--text-color) !important;
|
| 504 |
}
|
| 505 |
-
|
| 506 |
details summary {
|
| 507 |
background-color: var(--card-bg) !important;
|
| 508 |
color: var(--text-color) !important;
|
| 509 |
}
|
| 510 |
-
|
| 511 |
/* 17. ํดํ ๋ฐ ํ์
*/
|
| 512 |
[data-tooltip]:hover::after,
|
| 513 |
.tooltip,
|
|
@@ -517,7 +646,6 @@ details summary {
|
|
| 517 |
border-color: var(--border-color) !important;
|
| 518 |
box-shadow: var(--shadow-light) !important;
|
| 519 |
}
|
| 520 |
-
|
| 521 |
/* 18. ๋ชจ๋ฌ ๋ฐ ์ค๋ฒ๋ ์ด */
|
| 522 |
.modal,
|
| 523 |
.overlay,
|
|
@@ -527,7 +655,6 @@ details summary {
|
|
| 527 |
color: var(--text-color) !important;
|
| 528 |
border-color: var(--border-color) !important;
|
| 529 |
}
|
| 530 |
-
|
| 531 |
/* 19. ์ถ๊ฐ Gradio ์ปดํฌ๋ํธ๋ค */
|
| 532 |
.gr-block,
|
| 533 |
.gr-group,
|
|
@@ -536,7 +663,6 @@ details summary {
|
|
| 536 |
background-color: var(--background-color) !important;
|
| 537 |
color: var(--text-color) !important;
|
| 538 |
}
|
| 539 |
-
|
| 540 |
/* 20. ์ฝ๋ ๋ธ๋ก ๋ฐ pre ํ๊ทธ */
|
| 541 |
code,
|
| 542 |
pre,
|
|
@@ -545,7 +671,6 @@ pre,
|
|
| 545 |
color: var(--text-color) !important;
|
| 546 |
border-color: var(--border-color) !important;
|
| 547 |
}
|
| 548 |
-
|
| 549 |
/* 21. ์๋ฆผ ๋ฐ ๋ฉ์์ง */
|
| 550 |
.alert,
|
| 551 |
.message,
|
|
@@ -557,17 +682,14 @@ pre,
|
|
| 557 |
color: var(--text-color) !important;
|
| 558 |
border-color: var(--border-color) !important;
|
| 559 |
}
|
| 560 |
-
|
| 561 |
/* 22. ์ ๋๋ฉ์ด์
์คํ์ผ */
|
| 562 |
@keyframes fadeIn {
|
| 563 |
from { opacity: 0; transform: translateY(10px); }
|
| 564 |
to { opacity: 1; transform: translateY(0); }
|
| 565 |
}
|
| 566 |
-
|
| 567 |
.fade-in {
|
| 568 |
animation: fadeIn 0.5s ease-out;
|
| 569 |
}
|
| 570 |
-
|
| 571 |
/* 23. Examples ์น์
์คํ์ผ */
|
| 572 |
.examples-section {
|
| 573 |
display: grid;
|
|
@@ -575,7 +697,6 @@ pre,
|
|
| 575 |
gap: 1.5rem;
|
| 576 |
margin-top: 1rem;
|
| 577 |
}
|
| 578 |
-
|
| 579 |
.example-item {
|
| 580 |
background-color: var(--card-bg);
|
| 581 |
border-radius: var(--border-radius);
|
|
@@ -583,18 +704,15 @@ pre,
|
|
| 583 |
box-shadow: var(--shadow);
|
| 584 |
transition: transform 0.3s ease, background-color 0.3s ease;
|
| 585 |
}
|
| 586 |
-
|
| 587 |
.example-item:hover {
|
| 588 |
transform: translateY(-5px);
|
| 589 |
}
|
| 590 |
-
|
| 591 |
/* 24. ์ ํ ์ ๋๋ฉ์ด์
*/
|
| 592 |
* {
|
| 593 |
transition: background-color 0.3s ease,
|
| 594 |
color 0.3s ease,
|
| 595 |
border-color 0.3s ease !important;
|
| 596 |
}
|
| 597 |
-
|
| 598 |
/* 25. ๋ฐ์ํ */
|
| 599 |
@media (max-width: 768px) {
|
| 600 |
.button-grid {
|
|
@@ -622,7 +740,10 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default(
|
|
| 622 |
font=[gr.themes.GoogleFont("Noto Sans KR"), "ui-sans-serif", "system-ui"]
|
| 623 |
)) as demo:
|
| 624 |
gr.HTML(fontawesome_link)
|
|
|
|
|
|
|
| 625 |
|
|
|
|
| 626 |
with gr.Row(equal_height=True):
|
| 627 |
with gr.Column(scale=1):
|
| 628 |
# ======== ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์ค์ ์น์
========
|
|
@@ -711,36 +832,100 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default(
|
|
| 711 |
)
|
| 712 |
|
| 713 |
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ์ด๋ฒคํธ ์ฐ๊ฒฐ ==========
|
| 714 |
-
# ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 715 |
-
image_change_btn1.click(
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
submit_single_btn.click(
|
| 732 |
fn=generate_single_image,
|
| 733 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 734 |
outputs=[output_image1, output_text, prompt_display],
|
| 735 |
)
|
| 736 |
|
| 737 |
-
# 2์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 738 |
submit_btn.click(
|
| 739 |
fn=generate_multiple_images,
|
| 740 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 741 |
outputs=[output_image1, output_image2, output_text, prompt_display],
|
| 742 |
)
|
| 743 |
|
| 744 |
-
|
|
|
|
|
|
|
| 745 |
demo.queue()
|
| 746 |
-
demo.launch(share=False, inbrowser=True, width="100%")
|
|
|
|
| 10 |
from io import BytesIO
|
| 11 |
from datetime import datetime, timedelta
|
| 12 |
import random
|
| 13 |
+
|
| 14 |
+
from google import genai
|
| 15 |
+
from google.genai import types
|
| 16 |
from dotenv import load_dotenv
|
|
|
|
| 17 |
|
| 18 |
load_dotenv()
|
| 19 |
|
|
|
|
| 21 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
| 24 |
+
# ------------------- API ํค ์ํ ์์คํ
-------------------
|
| 25 |
+
# API ํค ์ค์ - ํ๊ฒฝ๋ณ์์์ API_KEYS = [...] ๊ตฌ๋ฌธ ๊ทธ๋๋ก ์คํ
|
| 26 |
+
def load_api_configs_from_env():
|
| 27 |
+
env_configs = os.getenv('API_KEYS')
|
| 28 |
+
if env_configs:
|
| 29 |
+
try:
|
| 30 |
+
# API_KEYS = [...] ๊ตฌ๋ฌธ์ ๊ทธ๋๋ก ์คํ
|
| 31 |
+
exec(env_configs, globals())
|
| 32 |
+
return globals().get('API_KEYS', [])
|
| 33 |
+
except Exception as e:
|
| 34 |
+
logger.error(f"โ ๏ธ API_KEYS ํ๊ฒฝ๋ณ์ ์คํ ์ค๋ฅ: {e}")
|
| 35 |
+
return []
|
| 36 |
+
return []
|
| 37 |
+
|
| 38 |
+
# ํ๊ฒฝ๋ณ์์์ ๋ก๋ํ๊ฑฐ๋ ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ
|
| 39 |
+
loaded_configs = load_api_configs_from_env()
|
| 40 |
+
API_KEYS = loaded_configs if loaded_configs else [
|
| 41 |
+
"",
|
| 42 |
+
"",
|
| 43 |
+
"",
|
| 44 |
+
"",
|
| 45 |
+
"",
|
| 46 |
+
"",
|
| 47 |
+
"",
|
| 48 |
+
"",
|
| 49 |
+
"",
|
| 50 |
+
"",
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
current_key_index = -1 # -1์ ์์ง ์ฌ์ฉํ์ง ์์์์ ์๋ฏธ
|
| 54 |
+
|
| 55 |
+
def initialize_api_keys():
|
| 56 |
+
"""API ํค ๋ชฉ๋ก์ ์ด๊ธฐํํ๋ ํจ์"""
|
| 57 |
+
global API_KEYS
|
| 58 |
+
|
| 59 |
+
# ๋น ๋ฌธ์์ด์ด๋ None์ธ ํค๋ค ์ ๊ฑฐ
|
| 60 |
+
API_KEYS = [key for key in API_KEYS if key and key.strip() and not key.startswith("your_")]
|
| 61 |
+
|
| 62 |
+
logger.info(f"API ํค {len(API_KEYS)}๊ฐ๊ฐ ๋ก๋๋์์ต๋๋ค.")
|
| 63 |
+
|
| 64 |
+
if len(API_KEYS) == 0:
|
| 65 |
+
logger.error("์ฌ์ฉ ๊ฐ๋ฅํ API ํค๊ฐ ์์ต๋๋ค. API_KEYS ๋ฆฌ์คํธ์ ์ค์ ํค๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.")
|
| 66 |
|
| 67 |
+
def get_next_api_key():
|
| 68 |
+
"""๋ค์ API ํค๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์ (์ฒ์์๋ ๋๋ค, ์ดํ์๋ ์์ฐจ์ )"""
|
| 69 |
+
global current_key_index, API_KEYS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
if not API_KEYS:
|
| 72 |
+
logger.error("API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
return None
|
| 74 |
+
|
| 75 |
+
if current_key_index == -1:
|
| 76 |
+
# ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์ ๋๋ค์ผ๋ก ์์์ ์ ํ
|
| 77 |
+
current_key_index = random.randint(0, len(API_KEYS) - 1)
|
| 78 |
+
logger.info(f"์ฒซ ๋ฒ์งธ API ํค ๋๋ค ์ ํ: ์ธ๋ฑ์ค {current_key_index}")
|
| 79 |
+
else:
|
| 80 |
+
# ์ดํ์๋ ์์ฐจ์ ์ผ๋ก ๋ค์ ํค ์ฌ์ฉ
|
| 81 |
+
current_key_index = (current_key_index + 1) % len(API_KEYS)
|
| 82 |
+
logger.info(f"๋ค์ API ํค ์์ฐจ ์ ํ: ์ธ๋ฑ์ค {current_key_index}")
|
| 83 |
+
|
| 84 |
+
return API_KEYS[current_key_index]
|
| 85 |
|
| 86 |
+
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ๊ด๋ จ ํจ์ ==========
|
| 87 |
+
def save_binary_file(file_name, data):
|
| 88 |
+
with open(file_name, "wb") as f:
|
| 89 |
+
f.write(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
def translate_prompt_to_english(prompt):
|
| 92 |
+
if not re.search("[๊ฐ-ํฃ]", prompt):
|
| 93 |
+
return prompt
|
| 94 |
+
|
| 95 |
+
prompt = prompt.replace("#1", "IMAGE_TAG_ONE")
|
| 96 |
+
prompt = prompt.replace("#2", "IMAGE_TAG_TWO")
|
| 97 |
+
prompt = prompt.replace("#3", "IMAGE_TAG_THREE")
|
| 98 |
+
|
| 99 |
try:
|
| 100 |
+
api_key = get_next_api_key()
|
| 101 |
+
if not api_key:
|
| 102 |
+
logger.error("Gemini API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
| 103 |
+
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
| 104 |
+
prompt = prompt.replace("IMAGE_TAG_TWO", "#2")
|
| 105 |
+
prompt = prompt.replace("IMAGE_TAG_THREE", "#3")
|
| 106 |
+
return prompt
|
| 107 |
+
|
| 108 |
+
client = genai.Client(api_key=api_key)
|
| 109 |
+
translation_prompt = f"""
|
| 110 |
+
Translate the following Korean text to English:
|
| 111 |
|
| 112 |
+
{prompt}
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
IMPORTANT: The tokens IMAGE_TAG_ONE, IMAGE_TAG_TWO, and IMAGE_TAG_THREE are special tags
|
| 115 |
+
and must be preserved exactly as is in your translation. Do not translate these tokens.
|
| 116 |
+
"""
|
| 117 |
|
| 118 |
+
logger.info(f"Translation prompt: {translation_prompt}")
|
| 119 |
+
response = client.models.generate_content(
|
| 120 |
+
model="gemini-2.0-flash",
|
| 121 |
+
contents=[translation_prompt],
|
| 122 |
+
config=types.GenerateContentConfig(
|
| 123 |
+
response_modalities=['Text'],
|
| 124 |
+
temperature=0.2,
|
| 125 |
+
top_p=0.95,
|
| 126 |
+
top_k=40,
|
| 127 |
+
max_output_tokens=512
|
| 128 |
+
)
|
| 129 |
)
|
| 130 |
|
| 131 |
+
translated_text = ""
|
| 132 |
+
for part in response.candidates[0].content.parts:
|
| 133 |
+
if hasattr(part, 'text') and part.text:
|
| 134 |
+
translated_text += part.text
|
| 135 |
|
| 136 |
+
if translated_text.strip():
|
| 137 |
+
translated_text = translated_text.replace("IMAGE_TAG_ONE", "#1")
|
| 138 |
+
translated_text = translated_text.replace("IMAGE_TAG_TWO", "#2")
|
| 139 |
+
translated_text = translated_text.replace("IMAGE_TAG_THREE", "#3")
|
| 140 |
+
logger.info(f"Translated text: {translated_text.strip()}")
|
| 141 |
+
return translated_text.strip()
|
| 142 |
else:
|
| 143 |
+
logger.warning("๋ฒ์ญ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค. ์๋ณธ ํ๋กฌํํธ ์ฌ์ฉ")
|
| 144 |
+
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
| 145 |
+
prompt = prompt.replace("IMAGE_TAG_TWO", "#2")
|
| 146 |
+
prompt = prompt.replace("IMAGE_TAG_THREE", "#3")
|
| 147 |
+
return prompt
|
| 148 |
except Exception as e:
|
| 149 |
+
logger.exception("๋ฒ์ญ ์ค ์ค๋ฅ ๋ฐ์:")
|
| 150 |
+
prompt = prompt.replace("IMAGE_TAG_ONE", "#1")
|
| 151 |
+
prompt = prompt.replace("IMAGE_TAG_TWO", "#2")
|
| 152 |
+
prompt = prompt.replace("IMAGE_TAG_THREE", "#3")
|
| 153 |
+
return prompt
|
| 154 |
+
|
| 155 |
+
def preprocess_prompt(prompt, image1, image2, image3):
|
| 156 |
+
# ๊ธฐ์กด ํจ์ ์ ์ง
|
| 157 |
+
has_img1 = image1 is not None
|
| 158 |
+
has_img2 = image2 is not None
|
| 159 |
+
has_img3 = image3 is not None
|
| 160 |
+
|
| 161 |
+
if "#1" in prompt and not has_img1:
|
| 162 |
+
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
| 163 |
+
else:
|
| 164 |
+
prompt = prompt.replace("#1", "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
| 165 |
+
|
| 166 |
+
if "#2" in prompt and not has_img2:
|
| 167 |
+
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
| 168 |
+
else:
|
| 169 |
+
prompt = prompt.replace("#2", "๋ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
| 170 |
+
|
| 171 |
+
if "#3" in prompt and not has_img3:
|
| 172 |
+
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง(์์)")
|
| 173 |
+
else:
|
| 174 |
+
prompt = prompt.replace("#3", "์ธ ๋ฒ์งธ ์ด๋ฏธ์ง")
|
| 175 |
+
|
| 176 |
+
if "1. ์ด๋ฏธ์ง ๋ณ๊ฒฝ" in prompt:
|
| 177 |
+
desc_match = re.search(r'#1์ "(.*?)"์ผ๋ก ๋ฐ๊ฟ๋ผ', prompt)
|
| 178 |
+
if desc_match:
|
| 179 |
+
description = desc_match.group(1)
|
| 180 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ {description}์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์๋ณธ ์ด๋ฏธ์ง์ ์ฃผ์ ๋ด์ฉ์ ์ ์งํ๋ ์๋ก์ด ์คํ์ผ๊ณผ ๋ถ์๊ธฐ๋ก ์ฌํด์ํด์ฃผ์ธ์."
|
| 181 |
+
else:
|
| 182 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ฐฝ์์ ์ผ๋ก ๋ณํํด์ฃผ์ธ์. ๋ ์์ํ๊ณ ์์ ์ ์ธ ๋ฒ์ ์ผ๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
| 183 |
|
| 184 |
+
elif "2. ๊ธ์์ง์ฐ๊ธฐ" in prompt:
|
| 185 |
+
text_match = re.search(r'#1์์ "(.*?)"๋ฅผ ์ง์๋ผ', prompt)
|
| 186 |
+
if text_match:
|
| 187 |
+
text_to_remove = text_match.group(1)
|
| 188 |
+
prompt = f"์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ '{text_to_remove}' ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ํ
์คํธ๊ฐ ์๋ ๋ถ๋ถ์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ์ฑ์์ฃผ์ธ์."
|
| 189 |
+
else:
|
| 190 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์์ ๋ชจ๋ ํ
์คํธ๋ฅผ ์ฐพ์ ์์ฐ์ค๋ฝ๊ฒ ์ ๊ฑฐํด์ฃผ์ธ์. ๊น๋ํ ์ด๋ฏธ์ง๋ก ๋ง๋ค์ด์ฃผ์ธ์."
|
| 191 |
|
| 192 |
+
elif "4. ์ท๋ฐ๊พธ๊ธฐ" in prompt:
|
| 193 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ธ๋ฌผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์์์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์์์ ์คํ์ผ๊ณผ ์์์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋ฅด๋, ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๋ฅผ ์ ์งํด์ฃผ์ธ์."
|
|
|
|
| 194 |
|
| 195 |
+
elif "5. ๋ฐฐ๊ฒฝ๋ฐ๊พธ๊ธฐ" in prompt:
|
| 196 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์. ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ์ฃผ์ ํผ์ฌ์ฒด๋ ์ ์งํ๊ณ , ๋ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ๊ณผ ์กฐํ๋กญ๊ฒ ํฉ์ฑํด์ฃผ์ธ์."
|
|
|
|
| 197 |
|
| 198 |
+
elif "6. ์ด๋ฏธ์ง ํฉ์ฑ(์ํํฌํจ)" in prompt:
|
| 199 |
+
prompt = "์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ๋ ๋ฒ์งธ ์ด๋ฏธ์ง(๋๋ ์ธ ๋ฒ์งธ ์ด๋ฏธ์ง)๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํฉ์ฑํด์ฃผ์ธ์. ๋ชจ๋ ์ด๋ฏธ์ง์ ์ฃผ์ ์์๋ฅผ ํฌํจํ๊ณ , ํนํ ์ํ์ด ๋๋ณด์ด๋๋ก ์กฐํ๋กญ๊ฒ ํตํฉํด์ฃผ์ธ์."
|
|
|
|
| 200 |
|
| 201 |
+
prompt += " ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์. ์ด๋ฏธ์ง์ ํ
์คํธ๋ ๊ธ์๋ฅผ ํฌํจํ์ง ๋ง์ธ์."
|
| 202 |
+
return prompt
|
|
|
|
| 203 |
|
| 204 |
+
def generate_with_images(prompt, images, variation_index=0):
|
| 205 |
+
try:
|
| 206 |
+
api_key = get_next_api_key()
|
| 207 |
+
if not api_key:
|
| 208 |
+
return None, "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. API_KEYS ํ๊ฒฝ๋ณ์์ API ํค๋ฅผ ์ค์ ํด์ฃผ์ธ์."
|
| 209 |
|
| 210 |
+
client = genai.Client(api_key=api_key)
|
| 211 |
+
logger.info(f"Gemini API ์์ฒญ ์์ - ํ๋กฌํํธ: {prompt}, ๋ณํ ์ธ๋ฑ์ค: {variation_index}")
|
|
|
|
| 212 |
|
| 213 |
+
variation_suffixes = [
|
| 214 |
+
" Create this as the first variation. Do not add any text, watermarks, or labels to the image.",
|
| 215 |
+
" Create this as the second variation with more vivid colors. Do not add any text, watermarks, or labels to the image."
|
| 216 |
+
]
|
| 217 |
+
|
| 218 |
+
if variation_index < len(variation_suffixes):
|
| 219 |
+
prompt = prompt + variation_suffixes[variation_index]
|
| 220 |
+
else:
|
| 221 |
+
prompt = prompt + " Do not add any text, watermarks, or labels to the image."
|
| 222 |
+
|
| 223 |
+
contents = [prompt]
|
| 224 |
+
for idx, img in enumerate(images, 1):
|
| 225 |
+
if img is not None:
|
| 226 |
+
contents.append(img)
|
| 227 |
+
logger.info(f"์ด๋ฏธ์ง #{idx} ์ถ๊ฐ๋จ")
|
| 228 |
+
|
| 229 |
+
response = client.models.generate_content(
|
| 230 |
+
model="gemini-2.0-flash-exp-image-generation",
|
| 231 |
+
contents=contents,
|
| 232 |
+
config=types.GenerateContentConfig(
|
| 233 |
+
response_modalities=['Text', 'Image'],
|
| 234 |
+
temperature=1,
|
| 235 |
+
top_p=0.95,
|
| 236 |
+
top_k=40,
|
| 237 |
+
max_output_tokens=8192
|
| 238 |
+
)
|
| 239 |
+
)
|
| 240 |
|
| 241 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
| 242 |
+
temp_path = tmp.name
|
| 243 |
+
result_text = ""
|
| 244 |
+
image_found = False
|
| 245 |
+
for part in response.candidates[0].content.parts:
|
| 246 |
+
if hasattr(part, 'text') and part.text:
|
| 247 |
+
result_text += part.text
|
| 248 |
+
logger.info(f"์๋ต ํ
์คํธ: {part.text}")
|
| 249 |
+
elif hasattr(part, 'inline_data') and part.inline_data:
|
| 250 |
+
save_binary_file(temp_path, part.inline_data.data)
|
| 251 |
+
image_found = True
|
| 252 |
+
logger.info("์๋ต์์ ์ด๋ฏธ์ง ์ถ์ถ ์ฑ๊ณต")
|
| 253 |
+
if not image_found:
|
| 254 |
+
return None, f"API์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ์๋ต ํ
์คํธ: {result_text}"
|
| 255 |
+
result_img = Image.open(temp_path)
|
| 256 |
+
if result_img.mode == "RGBA":
|
| 257 |
+
result_img = result_img.convert("RGB")
|
| 258 |
+
return result_img, f"์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค. {result_text}"
|
| 259 |
+
except Exception as e:
|
| 260 |
+
logger.exception("์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์:")
|
| 261 |
+
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 262 |
|
| 263 |
+
def process_images_with_prompt(image1, image2, image3, prompt, variation_index=0, max_retries=3):
|
| 264 |
+
retry_count = 0
|
| 265 |
+
last_error = None
|
| 266 |
+
|
| 267 |
+
while retry_count < max_retries:
|
| 268 |
+
try:
|
| 269 |
+
images = [image1, image2, image3]
|
| 270 |
+
valid_images = [img for img in images if img is not None]
|
| 271 |
+
|
| 272 |
+
if not valid_images: # ์ฌ๊ธฐ๊ฐ 254๋ฒ์งธ ์ค ๊ทผ์ฒ์ผ ๊ฒ
|
| 273 |
+
if prompt and prompt.strip():
|
| 274 |
+
# ํ๋กฌํํธ๋ง ์๋ ๊ฒฝ์ฐ ํ
์คํธ ๊ธฐ๋ฐ ์์ฑ ์๋
|
| 275 |
+
logger.info("ํ
์คํธ ํ๋กฌํํธ๋ง์ผ๋ก ์ด๋ฏธ์ง ์์ฑ ์๋")
|
| 276 |
+
try:
|
| 277 |
+
# ๋น ์ด๋ฏธ์ง ๋ฆฌ์คํธ๋ก ์์ฑ ์๋
|
| 278 |
+
result_img, status = generate_with_images(prompt, [], variation_index)
|
| 279 |
+
if result_img is not None:
|
| 280 |
+
return result_img, status, prompt
|
| 281 |
+
except:
|
| 282 |
+
pass
|
| 283 |
+
return None, "์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ฑฐ๋ ํ
์คํธ ํ๋กฌํํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.", ""
|
| 284 |
+
|
| 285 |
+
if prompt and prompt.strip():
|
| 286 |
+
processed_prompt = preprocess_prompt(prompt, image1, image2, image3)
|
| 287 |
+
if re.search("[๊ฐ-ํฃ]", processed_prompt):
|
| 288 |
+
final_prompt = translate_prompt_to_english(processed_prompt)
|
| 289 |
+
else:
|
| 290 |
+
final_prompt = processed_prompt
|
| 291 |
+
else:
|
| 292 |
+
if len(valid_images) == 1:
|
| 293 |
+
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."
|
| 294 |
+
logger.info("Default prompt generated for single image")
|
| 295 |
+
elif len(valid_images) == 2:
|
| 296 |
+
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."
|
| 297 |
+
logger.info("Default prompt generated for two images")
|
| 298 |
+
else:
|
| 299 |
+
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."
|
| 300 |
+
logger.info("Default prompt generated for three images")
|
| 301 |
+
|
| 302 |
+
result_img, status = generate_with_images(final_prompt, valid_images, variation_index)
|
| 303 |
+
if result_img is not None:
|
| 304 |
+
return result_img, status, final_prompt
|
| 305 |
+
else:
|
| 306 |
+
last_error = status
|
| 307 |
+
retry_count += 1
|
| 308 |
+
logger.warning(f"์ด๋ฏธ์ง ์์ฑ ์คํจ, ์ฌ์๋ {retry_count}/{max_retries}: {status}")
|
| 309 |
+
time.sleep(1)
|
| 310 |
+
except Exception as e:
|
| 311 |
+
last_error = str(e)
|
| 312 |
+
retry_count += 1
|
| 313 |
+
logger.exception(f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์, ์ฌ์๋ {retry_count}/{max_retries}:")
|
| 314 |
+
time.sleep(1)
|
| 315 |
+
|
| 316 |
+
return None, f"์ต๋ ์ฌ์๋ ํ์({max_retries}ํ) ์ด๊ณผ ํ ์คํจ: {last_error}", prompt
|
| 317 |
|
| 318 |
+
def generate_multiple_images(image1, image2, image3, prompt, progress=gr.Progress()):
|
| 319 |
+
results = []
|
| 320 |
+
statuses = []
|
| 321 |
+
prompts = []
|
| 322 |
+
|
| 323 |
+
num_images = 2
|
| 324 |
+
max_retries = 3
|
| 325 |
+
|
| 326 |
+
progress(0, desc="์ด๋ฏธ์ง ์์ฑ ์ค๋น ์ค...")
|
| 327 |
+
|
| 328 |
+
for i in range(num_images):
|
| 329 |
+
progress((i / num_images), desc=f"{i+1}/{num_images} ์ด๋ฏธ์ง ์์ฑ ์ค...")
|
| 330 |
+
result_img, status, final_prompt = process_images_with_prompt(image1, image2, image3, prompt, i, max_retries)
|
| 331 |
+
|
| 332 |
+
if result_img is not None:
|
| 333 |
+
results.append(result_img)
|
| 334 |
+
statuses.append(f"์ด๋ฏธ์ง #{i+1}: {status}")
|
| 335 |
+
prompts.append(f"์ด๋ฏธ์ง #{i+1}: {final_prompt}")
|
| 336 |
+
else:
|
| 337 |
+
results.append(None)
|
| 338 |
+
statuses.append(f"์ด๋ฏธ์ง #{i+1} ์์ฑ ์คํจ: {status}")
|
| 339 |
+
prompts.append(f"์ด๋ฏธ์ง #{i+1}: {final_prompt}")
|
| 340 |
+
|
| 341 |
+
time.sleep(1)
|
| 342 |
+
|
| 343 |
+
progress(1.0, desc="์ด๋ฏธ์ง ์์ฑ ์๋ฃ!")
|
| 344 |
+
|
| 345 |
+
while len(results) < 2:
|
| 346 |
+
results.append(None)
|
| 347 |
+
|
| 348 |
+
combined_status = "\n".join(statuses)
|
| 349 |
+
combined_prompts = "\n".join(prompts)
|
| 350 |
+
|
| 351 |
+
return results[0], results[1], combined_status, combined_prompts
|
| 352 |
|
| 353 |
# ๋คํฌ๋ชจ๋ ์๋ ์ ์ฉ ์ปค์คํ
CSS ์คํ์ผ
|
| 354 |
custom_css = """
|
| 355 |
/* ============================================
|
| 356 |
๋คํฌ๋ชจ๋ ์๋ ๋ณ๊ฒฝ ํ
ํ๋ฆฟ CSS
|
| 357 |
============================================ */
|
|
|
|
| 358 |
/* 1. CSS ๋ณ์ ์ ์ (๋ผ์ดํธ๋ชจ๋ - ๊ธฐ๋ณธ๊ฐ) */
|
| 359 |
:root {
|
| 360 |
/* ๋ฉ์ธ ์ปฌ๋ฌ */
|
|
|
|
| 386 |
/* ๊ธฐํ */
|
| 387 |
--border-radius: 18px;
|
| 388 |
}
|
|
|
|
| 389 |
/* 2. ๋คํฌ๋ชจ๋ ์์ ๋ณ์ (์๋ ๊ฐ์ง) */
|
| 390 |
@media (prefers-color-scheme: dark) {
|
| 391 |
:root {
|
|
|
|
| 411 |
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 412 |
}
|
| 413 |
}
|
|
|
|
| 414 |
/* 3. ์๋ ๋คํฌ๋ชจ๋ ํด๋์ค (Gradio ํ ๊ธ์ฉ) */
|
| 415 |
[data-theme="dark"],
|
| 416 |
.dark,
|
|
|
|
| 436 |
--shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
| 437 |
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 438 |
}
|
|
|
|
| 439 |
/* 4. ๊ธฐ๋ณธ ์์ ๋คํฌ๋ชจ๋ ์ ์ฉ */
|
| 440 |
body {
|
| 441 |
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
|
|
| 444 |
line-height: 1.6;
|
| 445 |
transition: background-color 0.3s ease, color 0.3s ease;
|
| 446 |
}
|
|
|
|
| 447 |
/* 5. Gradio ์ปจํ
์ด๋ ๊ฐ์ ์ ์ฉ */
|
| 448 |
.gradio-container,
|
| 449 |
.gradio-container *,
|
|
|
|
| 453 |
background-color: var(--background-color) !important;
|
| 454 |
color: var(--text-color) !important;
|
| 455 |
}
|
|
|
|
| 456 |
/* Gradio ์ปจํ
์ด๋ ์ค๋ฒ๋ผ์ด๋ */
|
| 457 |
.gradio-container {
|
| 458 |
max-width: 100% !important;
|
|
|
|
| 462 |
background-color: var(--background-color) !important;
|
| 463 |
box-sizing: border-box !important;
|
| 464 |
}
|
|
|
|
| 465 |
/* ์ถ๊ฐ: ๋ด๋ถ ์ปจํ
์ด๋๋ 100% ๋๋น๋ก ์ค์ */
|
| 466 |
.contain {
|
| 467 |
max-width: 100% !important;
|
| 468 |
width: 100% !important;
|
| 469 |
}
|
|
|
|
| 470 |
/* ์ถ๊ฐ: ๊ฐ ํ(Row)๋ 100% ๋๋น๋ก ์ค์ */
|
| 471 |
.gr-padded {
|
| 472 |
padding: 0 !important;
|
| 473 |
width: 100% !important;
|
| 474 |
max-width: 100% !important;
|
| 475 |
}
|
|
|
|
| 476 |
/* 6. ์นด๋ ๋ฐ ํจ๋ ์คํ์ผ */
|
| 477 |
.gr-group,
|
| 478 |
.gr-form,
|
|
|
|
| 491 |
transition: transform 0.3s ease, background-color 0.3s ease;
|
| 492 |
color: var(--text-color) !important;
|
| 493 |
}
|
|
|
|
| 494 |
.gr-group:hover {
|
| 495 |
transform: translateY(-5px);
|
| 496 |
}
|
|
|
|
| 497 |
/* 7. ์
๋ ฅ ํ๋ ์คํ์ผ */
|
| 498 |
input[type="text"],
|
| 499 |
input[type="number"],
|
|
|
|
| 513 |
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
| 514 |
transition: all 0.3s ease !important;
|
| 515 |
}
|
|
|
|
| 516 |
input[type="text"]:focus,
|
| 517 |
input[type="number"]:focus,
|
| 518 |
input[type="email"]:focus,
|
|
|
|
| 527 |
outline: none !important;
|
| 528 |
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
|
| 529 |
}
|
|
|
|
| 530 |
/* 8. ๋ผ๋ฒจ ๋ฐ ํ
์คํธ ์์ */
|
| 531 |
label,
|
| 532 |
.gr-label,
|
|
|
|
| 535 |
p, span, div {
|
| 536 |
color: var(--text-color) !important;
|
| 537 |
}
|
|
|
|
| 538 |
/* 9. ์น์
์ ๋ชฉ */
|
| 539 |
.section-title {
|
| 540 |
font-size: 22px !important;
|
|
|
|
| 546 |
display: flex;
|
| 547 |
align-items: center;
|
| 548 |
}
|
|
|
|
| 549 |
.section-title span {
|
| 550 |
color: var(--primary-color);
|
| 551 |
}
|
|
|
|
| 552 |
/* 10. ๋ฒํผ ์คํ์ผ๋ง */
|
| 553 |
.custom-button {
|
| 554 |
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
|
|
|
| 564 |
align-items: center !important;
|
| 565 |
justify-content: center !important;
|
| 566 |
}
|
|
|
|
| 567 |
.custom-button:hover {
|
| 568 |
transform: translateY(-2px) !important;
|
| 569 |
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3) !important;
|
| 570 |
}
|
|
|
|
| 571 |
.custom-button.primary {
|
| 572 |
background: linear-gradient(135deg, var(--accent-color), #ff9a8b) !important;
|
| 573 |
}
|
|
|
|
| 574 |
button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"]) {
|
| 575 |
background-color: var(--card-bg) !important;
|
| 576 |
color: var(--text-color) !important;
|
|
|
|
| 578 |
border-radius: var(--border-radius) !important;
|
| 579 |
transition: all 0.3s ease !important;
|
| 580 |
}
|
|
|
|
| 581 |
/* 11. ์ด๋ฏธ์ง ์ปจํ
์ด๋ */
|
| 582 |
.image-container {
|
| 583 |
border-radius: var(--border-radius);
|
|
|
|
| 586 |
transition: all 0.3s ease;
|
| 587 |
background-color: var(--card-bg);
|
| 588 |
}
|
|
|
|
| 589 |
.image-container:hover {
|
| 590 |
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 591 |
}
|
|
|
|
| 592 |
/* 12. ํ
์ด๋ธ ์คํ์ผ */
|
| 593 |
table {
|
| 594 |
background-color: var(--card-bg) !important;
|
| 595 |
color: var(--text-color) !important;
|
| 596 |
border-color: var(--border-color) !important;
|
| 597 |
}
|
|
|
|
| 598 |
table th {
|
| 599 |
background-color: var(--primary-color) !important;
|
| 600 |
color: white !important;
|
| 601 |
border-color: var(--border-color) !important;
|
| 602 |
}
|
|
|
|
| 603 |
table td {
|
| 604 |
background-color: var(--card-bg) !important;
|
| 605 |
color: var(--text-color) !important;
|
| 606 |
border-color: var(--border-color) !important;
|
| 607 |
}
|
|
|
|
| 608 |
table tbody tr:nth-child(even) {
|
| 609 |
background-color: var(--table-even-bg) !important;
|
| 610 |
}
|
|
|
|
| 611 |
table tbody tr:hover {
|
| 612 |
background-color: var(--table-hover-bg) !important;
|
| 613 |
}
|
|
|
|
| 614 |
/* 13. ์ฒดํฌ๋ฐ์ค ๋ฐ ๋ผ๋์ค ๋ฒํผ */
|
| 615 |
input[type="checkbox"],
|
| 616 |
input[type="radio"] {
|
| 617 |
accent-color: var(--primary-color) !important;
|
| 618 |
}
|
|
|
|
| 619 |
/* 14. ๋ฒํผ ๊ทธ๋ฃน */
|
| 620 |
.button-grid {
|
| 621 |
display: grid;
|
|
|
|
| 623 |
gap: 0.8rem;
|
| 624 |
margin-bottom: 1.2rem;
|
| 625 |
}
|
|
|
|
| 626 |
/* 15. ์คํฌ๋กค๋ฐ ์คํ์ผ */
|
| 627 |
::-webkit-scrollbar-thumb:hover {
|
| 628 |
background: var(--secondary-color);
|
| 629 |
}
|
|
|
|
| 630 |
/* 16. ์์ฝ๋์ธ ๋ฐ ๋๋กญ๋ค์ด */
|
| 631 |
details {
|
| 632 |
background-color: var(--card-bg) !important;
|
| 633 |
border-color: var(--border-color) !important;
|
| 634 |
color: var(--text-color) !important;
|
| 635 |
}
|
|
|
|
| 636 |
details summary {
|
| 637 |
background-color: var(--card-bg) !important;
|
| 638 |
color: var(--text-color) !important;
|
| 639 |
}
|
|
|
|
| 640 |
/* 17. ํดํ ๋ฐ ํ์
*/
|
| 641 |
[data-tooltip]:hover::after,
|
| 642 |
.tooltip,
|
|
|
|
| 646 |
border-color: var(--border-color) !important;
|
| 647 |
box-shadow: var(--shadow-light) !important;
|
| 648 |
}
|
|
|
|
| 649 |
/* 18. ๋ชจ๋ฌ ๋ฐ ์ค๋ฒ๋ ์ด */
|
| 650 |
.modal,
|
| 651 |
.overlay,
|
|
|
|
| 655 |
color: var(--text-color) !important;
|
| 656 |
border-color: var(--border-color) !important;
|
| 657 |
}
|
|
|
|
| 658 |
/* 19. ์ถ๊ฐ Gradio ์ปดํฌ๋ํธ๋ค */
|
| 659 |
.gr-block,
|
| 660 |
.gr-group,
|
|
|
|
| 663 |
background-color: var(--background-color) !important;
|
| 664 |
color: var(--text-color) !important;
|
| 665 |
}
|
|
|
|
| 666 |
/* 20. ์ฝ๋ ๋ธ๋ก ๋ฐ pre ํ๊ทธ */
|
| 667 |
code,
|
| 668 |
pre,
|
|
|
|
| 671 |
color: var(--text-color) !important;
|
| 672 |
border-color: var(--border-color) !important;
|
| 673 |
}
|
|
|
|
| 674 |
/* 21. ์๋ฆผ ๋ฐ ๋ฉ์์ง */
|
| 675 |
.alert,
|
| 676 |
.message,
|
|
|
|
| 682 |
color: var(--text-color) !important;
|
| 683 |
border-color: var(--border-color) !important;
|
| 684 |
}
|
|
|
|
| 685 |
/* 22. ์ ๋๋ฉ์ด์
์คํ์ผ */
|
| 686 |
@keyframes fadeIn {
|
| 687 |
from { opacity: 0; transform: translateY(10px); }
|
| 688 |
to { opacity: 1; transform: translateY(0); }
|
| 689 |
}
|
|
|
|
| 690 |
.fade-in {
|
| 691 |
animation: fadeIn 0.5s ease-out;
|
| 692 |
}
|
|
|
|
| 693 |
/* 23. Examples ์น์
์คํ์ผ */
|
| 694 |
.examples-section {
|
| 695 |
display: grid;
|
|
|
|
| 697 |
gap: 1.5rem;
|
| 698 |
margin-top: 1rem;
|
| 699 |
}
|
|
|
|
| 700 |
.example-item {
|
| 701 |
background-color: var(--card-bg);
|
| 702 |
border-radius: var(--border-radius);
|
|
|
|
| 704 |
box-shadow: var(--shadow);
|
| 705 |
transition: transform 0.3s ease, background-color 0.3s ease;
|
| 706 |
}
|
|
|
|
| 707 |
.example-item:hover {
|
| 708 |
transform: translateY(-5px);
|
| 709 |
}
|
|
|
|
| 710 |
/* 24. ์ ํ ์ ๋๋ฉ์ด์
*/
|
| 711 |
* {
|
| 712 |
transition: background-color 0.3s ease,
|
| 713 |
color 0.3s ease,
|
| 714 |
border-color 0.3s ease !important;
|
| 715 |
}
|
|
|
|
| 716 |
/* 25. ๋ฐ์ํ */
|
| 717 |
@media (max-width: 768px) {
|
| 718 |
.button-grid {
|
|
|
|
| 740 |
font=[gr.themes.GoogleFont("Noto Sans KR"), "ui-sans-serif", "system-ui"]
|
| 741 |
)) as demo:
|
| 742 |
gr.HTML(fontawesome_link)
|
| 743 |
+
# ์ ๋ชฉ ์ ๊ฑฐ
|
| 744 |
+
# gr.HTML(header_html)
|
| 745 |
|
| 746 |
+
# ํญ ์ ๊ฑฐํ๊ณ ์ด๋ฏธ์ง ์์ฑ๊ธฐ ๋ด์ฉ์ ์ง์ ๋ฐฐ์น
|
| 747 |
with gr.Row(equal_height=True):
|
| 748 |
with gr.Column(scale=1):
|
| 749 |
# ======== ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์ค์ ์น์
========
|
|
|
|
| 832 |
)
|
| 833 |
|
| 834 |
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ์ด๋ฒคํธ ์ฐ๊ฒฐ ==========
|
| 835 |
+
# ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 836 |
+
image_change_btn1.click(
|
| 837 |
+
fn=lambda: "(#1์ ์ฌ์ฑ)์ด ์ด์ง ๋ค๋ก ๋์๋ณด๋ ๋ชจ์ต์ผ๋ก ์ต๋ํ ์ด์ seed๋ฅผ ์ ์งํํ
์์ฐ์ค๋ฝ๊ฒ ๋ณ๊ฒฝํ๋ผ.",
|
| 838 |
+
inputs=[],
|
| 839 |
+
outputs=prompt_input
|
| 840 |
+
)
|
| 841 |
+
image_change_btn2.click(
|
| 842 |
+
fn=lambda: "(#1 ๋ ๋ชจ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ง ๊ฒ์์ ๊ณ ๋๋ ๊ณ ๋ก ๋ณ๊ฒฝํ๊ณ ๋๋จธ์ง ๋ถ๋ถ์ seed๋ฅผ ๋ณ๊ฒฝ์ ํ์ง๋ง๋ผ.",
|
| 843 |
+
inputs=[],
|
| 844 |
+
outputs=prompt_input
|
| 845 |
+
)
|
| 846 |
+
image_change_btn3.click(
|
| 847 |
+
fn=lambda: "(#1 ์ฌํ์ฉ ์ผ์๋ฐ์ค)์์ ์ผ์์ด ๋ด๊ธด 3์์ ์ฝ๋ผ๊ฐ ๋์ฌ์๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ.",
|
| 848 |
+
inputs=[],
|
| 849 |
+
outputs=prompt_input
|
| 850 |
+
)
|
| 851 |
+
|
| 852 |
+
text_remove_btn.click(
|
| 853 |
+
fn=lambda: "(#1 ์ด๋ฏธ์ง)์ ์๋ ์ค๊ตญ์ด๋ฅผ ๋ชจ๋ ์ ๊ฑฐํ๋ผ.",
|
| 854 |
+
inputs=[],
|
| 855 |
+
outputs=prompt_input
|
| 856 |
+
)
|
| 857 |
+
text_change_btn.click(
|
| 858 |
+
fn=lambda: '(#1์ ํ
์คํธ)๋ฅผ ์คํ์ผ์ ์ ์งํ์ฒด ํ
์คํธ๋ง "Hello"๋ก ๋ฐ๊ฟ๋ผ',
|
| 859 |
+
inputs=[],
|
| 860 |
+
outputs=prompt_input
|
| 861 |
+
)
|
| 862 |
+
clothes_change_btn1.click(
|
| 863 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด (#2์ ์ ๊ธ๋ผ์ค)์ (#3์ ์ฒญ๋ฐ์ง)๋ฅผ ์ง์ ๋ชจ๋ธ์ด ์ฐฉ์ฉํ๊ฒ ์ฒ๋ผ ์์ฐ์ค๋ฝ๊ฒ ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 864 |
+
inputs=[],
|
| 865 |
+
outputs=prompt_input
|
| 866 |
+
)
|
| 867 |
+
clothes_change_btn2.click(
|
| 868 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2์ ์ ๊ธ๋ผ์ค)์ ์ฐฉ์ฉํ๊ณ (#3์ ๋ท๋ฐฐ๊ฒฝ์ ์นดํ์ ์ฒด๊ฐ ๋ณด์ด๋ฉฐ) ์์์ ์์ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 869 |
+
inputs=[],
|
| 870 |
+
outputs=prompt_input
|
| 871 |
+
)
|
| 872 |
+
holding_product_btn.click(
|
| 873 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด(#2์ ์์ธ์)์ ๋ค๊ณ ์๋ ์์ฐ์ค๋ฌ์ด ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 874 |
+
inputs=[],
|
| 875 |
+
outputs=prompt_input
|
| 876 |
+
)
|
| 877 |
+
background_change_btn.click(
|
| 878 |
+
fn=lambda: "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2 ์นดํ)์์ ์์ฐ์ค๋ฝ๊ฒ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ.",
|
| 879 |
+
inputs=[],
|
| 880 |
+
outputs=prompt_input
|
| 881 |
+
)
|
| 882 |
+
composite_product_btn.click(
|
| 883 |
+
fn=lambda: "(#1์ ๋ ๊ณ ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ฅผ ์ ๊ฑฐํ ํ, ๊ทธ ์๋ฆฌ๋ฅผ ์ฃผ๋ณ ๋ฐฐ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ฐ๋ฌ์ง๋๋ก ์ฑ์์ฃผ์ธ์. ๋จ, ์ด๋ฏธ์ง์ ๋ค๋ฅธ ๋ถ๋ถ์ ์ฃผ์ ์์๋ ๋์ผํ๊ฒ ์ ์ง ํด์ผํ๋ค.",
|
| 884 |
+
inputs=[],
|
| 885 |
+
outputs=prompt_input
|
| 886 |
+
)
|
| 887 |
+
outpainting_btn.click(
|
| 888 |
+
fn=lambda: "(#1 ์ด๋ฏธ์ง)๋ฅผ ์๋ณธ๊ทธ๋๋ก ์ค์์ ๋๊ณ ๋น์จ๋ก ์ ์งํ ์ฒด ์์๋ ๋ฐ ์ข์ฐ๋ก ํฌ๊ฒ ํ์ฅํ๋ผ.",
|
| 889 |
+
inputs=[],
|
| 890 |
+
outputs=prompt_input
|
| 891 |
+
|
| 892 |
+
)
|
| 893 |
+
food_btn_1.click(
|
| 894 |
+
fn=lambda: "(#1์
๋ฌ๋)์ ๋ด์ ์ฉ๊ธฐ๋ ๋ฒ๋ฆฌ๊ณ ๋๊ณ ํฐ ์์ ์ ์์ (#1์
๋ฌ๋)์์๋ง ๊ฐ๋ ์ฑ์์ ์์
์ ์ธ ๊ฐ๋๋ก ์ด์ธ๋ฆฌ๋ ์ํ๊ณผ ํจ๊ป ํ๋ ์ดํ
ํ ๋ชจ์ต์ ์ด๋ฏธ์ง๋ก ์์ฑํ๋ผ. ",
|
| 895 |
+
inputs=[],
|
| 896 |
+
outputs=prompt_input
|
| 897 |
+
)
|
| 898 |
+
food_btn_2.click(
|
| 899 |
+
fn=lambda: "(#2 ํ๋ ์ดํ
ํ ์ด๋ฏธ์ง)์ ๋ด๊ธด ์์์ (#1 ์๋ฌ๋)๋ก ๋ฐ๊พธ๊ณ ๋๋จธ์ง๋ ์๋๋ฅผ ์ ์งํ ์ฒด ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ.",
|
| 900 |
+
inputs=[],
|
| 901 |
+
outputs=prompt_input
|
| 902 |
+
)
|
| 903 |
+
|
| 904 |
+
food_btn_3.click(
|
| 905 |
+
fn=lambda: "(#1์ปต)์ ๋ธ๊ธฐ, ๋ฐ๋๋ผ, ์ด์ฝ ์์ด์คํฌ๋ฆผ์ ๋ด๊ณ ๊ทธ ์์ ์ด์ฝ ์๋ฝ์ด ํ๋ฅด๊ฒ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ผ.",
|
| 906 |
+
inputs=[],
|
| 907 |
+
outputs=prompt_input
|
| 908 |
+
)
|
| 909 |
+
|
| 910 |
+
# ๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ - API ํค ์
๋ ฅ๊ฐ ์ ๊ฑฐ
|
| 911 |
+
def generate_single_image(image1, image2, image3, prompt):
|
| 912 |
+
return process_images_with_prompt(image1, image2, image3, prompt, 0, 3)
|
| 913 |
+
|
| 914 |
submit_single_btn.click(
|
| 915 |
fn=generate_single_image,
|
| 916 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 917 |
outputs=[output_image1, output_text, prompt_display],
|
| 918 |
)
|
| 919 |
|
| 920 |
+
# 2์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ - API ํค ์
๋ ฅ๊ฐ ์ ๊ฑฐ
|
| 921 |
submit_btn.click(
|
| 922 |
fn=generate_multiple_images,
|
| 923 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
| 924 |
outputs=[output_image1, output_image2, output_text, prompt_display],
|
| 925 |
)
|
| 926 |
|
| 927 |
+
|
| 928 |
+
# API ํค ์ด๊ธฐํ ๋ฐ ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 929 |
+
initialize_api_keys() # API ํค ์ด๊ธฐํ ํจ์ ํธ์ถ
|
| 930 |
demo.queue()
|
| 931 |
+
demo.launch(share=False, inbrowser=True, width="100%") # width ํ๋ผ๋ฏธํฐ ์ถ๊ฐ
|