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,181 +21,340 @@ load_dotenv()
|
|
19 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
20 |
logger = logging.getLogger(__name__)
|
21 |
|
22 |
-
# API
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
def
|
45 |
-
"""
|
46 |
-
|
47 |
-
return None
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
if hasattr(image, 'save'):
|
52 |
-
# ์์ ํ์ผ ์์ฑ
|
53 |
-
temp_file = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
54 |
-
image.save(temp_file.name, format='PNG')
|
55 |
-
temp_file.close()
|
56 |
-
return temp_file.name
|
57 |
-
# ์ด๋ฏธ ํ์ผ ๊ฒฝ๋ก์ธ ๊ฒฝ์ฐ
|
58 |
-
elif isinstance(image, str):
|
59 |
-
return image
|
60 |
-
# ๊ธฐํ ๊ฒฝ์ฐ
|
61 |
-
else:
|
62 |
-
return image
|
63 |
-
except Exception as e:
|
64 |
-
logger.error(f"์ด๋ฏธ์ง ํ์ผ ๋ณํ ์คํจ: {e}")
|
65 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ๊ด๋ จ ํจ์
|
68 |
-
def
|
69 |
-
""
|
70 |
-
|
71 |
-
# ์ด๋ฏธ์ง ํ์ผ ์ฒ๋ฆฌ - PIL Image๋ฅผ ์์ ํ์ผ๋ก ๋ณํ
|
72 |
-
image1_path = convert_image_to_file(image1)
|
73 |
-
image2_path = convert_image_to_file(image2)
|
74 |
-
image3_path = convert_image_to_file(image3)
|
75 |
-
|
76 |
-
# handle_file๋ก ์ฒ๋ฆฌ
|
77 |
-
image1_file = handle_file(image1_path) if image1_path else None
|
78 |
-
image2_file = handle_file(image2_path) if image2_path else None
|
79 |
-
image3_file = handle_file(image3_path) if image3_path else None
|
80 |
-
|
81 |
-
result = safe_client_call(
|
82 |
-
"/generate_single_image",
|
83 |
-
image1=image1_file,
|
84 |
-
image2=image2_file,
|
85 |
-
image3=image3_file,
|
86 |
-
prompt=prompt
|
87 |
-
)
|
88 |
-
|
89 |
-
if result:
|
90 |
-
return result[0], result[1], result[2]
|
91 |
-
else:
|
92 |
-
return None, "API ํธ์ถ ์คํจ", ""
|
93 |
-
|
94 |
-
except Exception as e:
|
95 |
-
logger.error(f"๋จ์ผ ์ด๋ฏธ์ง ์์ฑ ์คํจ: {e}")
|
96 |
-
return None, f"์ค๋ฅ ๋ฐ์: {str(e)}", ""
|
97 |
|
98 |
-
def
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
try:
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
image1_file = handle_file(image1_path) if image1_path else None
|
110 |
-
image2_file = handle_file(image2_path) if image2_path else None
|
111 |
-
image3_file = handle_file(image3_path) if image3_path else None
|
112 |
|
113 |
-
|
|
|
|
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
121 |
)
|
122 |
|
123 |
-
|
|
|
|
|
|
|
124 |
|
125 |
-
if
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
else:
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
130 |
except Exception as e:
|
131 |
-
logger.
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
return '(#1์ ํ
์คํธ)๋ฅผ ์คํ์ผ์ ์ ์งํ์ฒด ํ
์คํธ๋ง "Hello"๋ก ๋ฐ๊ฟ๋ผ'
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
return "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด ์ ์ฒด ๋น์จ๊ณผ ํฌ์ฆ๋ ์ ์งํ ์ฒด (#2์ ์ ๊ธ๋ผ์ค)์ (#3์ ์ฒญ๋ฐ์ง)๋ฅผ ์ง์ ๋ชจ๋ธ์ด ์ฐฉ์ฉํ๊ฒ ์ฒ๋ผ ์์ฐ์ค๋ฝ๊ฒ ๋ชจ์ต์ ์์ฑํ๋ผ."
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
return "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด (#2์ ์ ๊ธ๋ผ์ค)์ ์ฐฉ์ฉํ๊ณ (#3์ ๋ท๋ฐฐ๊ฒฝ์ ์นดํ์ ์ฒด๊ฐ ๋ณด์ด๋ฉฐ) ์์์ ์์ ์๋ ๋ชจ์ต์ ์์ฑํ๋ผ."
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
return "(#1์ ์ฌ์ฑ๋ชจ๋ธ)์ด(#2์ ์์ธ์)์ ๋ค๊ณ ์๋ ์์ฐ์ค๋ฌ์ด ๋ชจ์ต์ ์์ฑํ๋ผ."
|
166 |
|
167 |
-
def
|
168 |
-
|
169 |
-
|
|
|
|
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
return "(#1์ ๋ ๊ณ ๋ชจํ)์์ ์ฒญ์์์ด๋ ๊ณ ๋ฅผ ์ ๊ฑฐํ ํ, ๊ทธ ์๋ฆฌ๋ฅผ ์ฃผ๋ณ ๋ฐฐ๊ฒฝ๊ณผ ์์ฐ์ค๋ฝ๊ฒ ์ด์ฐ๋ฌ์ง๋๋ก ์ฑ์์ฃผ์ธ์. ๋จ, ์ด๋ฏธ์ง์ ๋ค๋ฅธ ๋ถ๋ถ์ ์ฃผ์ ์์๋ ๋์ผํ๊ฒ ์ ์ง ํด์ผํ๋ค."
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
-
def
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
-
def
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
# ๋คํฌ๋ชจ๋ ์๋ ์ ์ฉ ์ปค์คํ
CSS ์คํ์ผ
|
192 |
custom_css = """
|
193 |
/* ============================================
|
194 |
๋คํฌ๋ชจ๋ ์๋ ๋ณ๊ฒฝ ํ
ํ๋ฆฟ CSS
|
195 |
============================================ */
|
196 |
-
|
197 |
/* 1. CSS ๋ณ์ ์ ์ (๋ผ์ดํธ๋ชจ๋ - ๊ธฐ๋ณธ๊ฐ) */
|
198 |
:root {
|
199 |
/* ๋ฉ์ธ ์ปฌ๋ฌ */
|
@@ -225,7 +386,6 @@ custom_css = """
|
|
225 |
/* ๊ธฐํ */
|
226 |
--border-radius: 18px;
|
227 |
}
|
228 |
-
|
229 |
/* 2. ๋คํฌ๋ชจ๋ ์์ ๋ณ์ (์๋ ๊ฐ์ง) */
|
230 |
@media (prefers-color-scheme: dark) {
|
231 |
:root {
|
@@ -251,7 +411,6 @@ custom_css = """
|
|
251 |
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
252 |
}
|
253 |
}
|
254 |
-
|
255 |
/* 3. ์๋ ๋คํฌ๋ชจ๋ ํด๋์ค (Gradio ํ ๊ธ์ฉ) */
|
256 |
[data-theme="dark"],
|
257 |
.dark,
|
@@ -277,7 +436,6 @@ custom_css = """
|
|
277 |
--shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
278 |
--shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
|
279 |
}
|
280 |
-
|
281 |
/* 4. ๊ธฐ๋ณธ ์์ ๋คํฌ๋ชจ๋ ์ ์ฉ */
|
282 |
body {
|
283 |
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
@@ -286,7 +444,6 @@ body {
|
|
286 |
line-height: 1.6;
|
287 |
transition: background-color 0.3s ease, color 0.3s ease;
|
288 |
}
|
289 |
-
|
290 |
/* 5. Gradio ์ปจํ
์ด๋ ๊ฐ์ ์ ์ฉ */
|
291 |
.gradio-container,
|
292 |
.gradio-container *,
|
@@ -296,7 +453,6 @@ body {
|
|
296 |
background-color: var(--background-color) !important;
|
297 |
color: var(--text-color) !important;
|
298 |
}
|
299 |
-
|
300 |
/* Gradio ์ปจํ
์ด๋ ์ค๋ฒ๋ผ์ด๋ */
|
301 |
.gradio-container {
|
302 |
max-width: 100% !important;
|
@@ -306,20 +462,17 @@ body {
|
|
306 |
background-color: var(--background-color) !important;
|
307 |
box-sizing: border-box !important;
|
308 |
}
|
309 |
-
|
310 |
/* ์ถ๊ฐ: ๋ด๋ถ ์ปจํ
์ด๋๋ 100% ๋๋น๋ก ์ค์ */
|
311 |
.contain {
|
312 |
max-width: 100% !important;
|
313 |
width: 100% !important;
|
314 |
}
|
315 |
-
|
316 |
/* ์ถ๊ฐ: ๊ฐ ํ(Row)๋ 100% ๋๋น๋ก ์ค์ */
|
317 |
.gr-padded {
|
318 |
padding: 0 !important;
|
319 |
width: 100% !important;
|
320 |
max-width: 100% !important;
|
321 |
}
|
322 |
-
|
323 |
/* 6. ์นด๋ ๋ฐ ํจ๋ ์คํ์ผ */
|
324 |
.gr-group,
|
325 |
.gr-form,
|
@@ -338,11 +491,9 @@ body {
|
|
338 |
transition: transform 0.3s ease, background-color 0.3s ease;
|
339 |
color: var(--text-color) !important;
|
340 |
}
|
341 |
-
|
342 |
.gr-group:hover {
|
343 |
transform: translateY(-5px);
|
344 |
}
|
345 |
-
|
346 |
/* 7. ์
๋ ฅ ํ๋ ์คํ์ผ */
|
347 |
input[type="text"],
|
348 |
input[type="number"],
|
@@ -362,7 +513,6 @@ select,
|
|
362 |
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
363 |
transition: all 0.3s ease !important;
|
364 |
}
|
365 |
-
|
366 |
input[type="text"]:focus,
|
367 |
input[type="number"]:focus,
|
368 |
input[type="email"]:focus,
|
@@ -377,7 +527,6 @@ select:focus,
|
|
377 |
outline: none !important;
|
378 |
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
|
379 |
}
|
380 |
-
|
381 |
/* 8. ๋ผ๋ฒจ ๋ฐ ํ
์คํธ ์์ */
|
382 |
label,
|
383 |
.gr-label,
|
@@ -386,7 +535,6 @@ label,
|
|
386 |
p, span, div {
|
387 |
color: var(--text-color) !important;
|
388 |
}
|
389 |
-
|
390 |
/* 9. ์น์
์ ๋ชฉ */
|
391 |
.section-title {
|
392 |
font-size: 22px !important;
|
@@ -398,11 +546,9 @@ p, span, div {
|
|
398 |
display: flex;
|
399 |
align-items: center;
|
400 |
}
|
401 |
-
|
402 |
.section-title span {
|
403 |
color: var(--primary-color);
|
404 |
}
|
405 |
-
|
406 |
/* 10. ๋ฒํผ ์คํ์ผ๋ง */
|
407 |
.custom-button {
|
408 |
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
@@ -418,16 +564,13 @@ p, span, div {
|
|
418 |
align-items: center !important;
|
419 |
justify-content: center !important;
|
420 |
}
|
421 |
-
|
422 |
.custom-button:hover {
|
423 |
transform: translateY(-2px) !important;
|
424 |
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3) !important;
|
425 |
}
|
426 |
-
|
427 |
.custom-button.primary {
|
428 |
background: linear-gradient(135deg, var(--accent-color), #ff9a8b) !important;
|
429 |
}
|
430 |
-
|
431 |
button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"]) {
|
432 |
background-color: var(--card-bg) !important;
|
433 |
color: var(--text-color) !important;
|
@@ -435,7 +578,6 @@ button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"])
|
|
435 |
border-radius: var(--border-radius) !important;
|
436 |
transition: all 0.3s ease !important;
|
437 |
}
|
438 |
-
|
439 |
/* 11. ์ด๋ฏธ์ง ์ปจํ
์ด๋ */
|
440 |
.image-container {
|
441 |
border-radius: var(--border-radius);
|
@@ -444,44 +586,36 @@ button:not([class*="custom"]):not([class*="primary"]):not([class*="secondary"])
|
|
444 |
transition: all 0.3s ease;
|
445 |
background-color: var(--card-bg);
|
446 |
}
|
447 |
-
|
448 |
.image-container:hover {
|
449 |
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
450 |
}
|
451 |
-
|
452 |
/* 12. ํ
์ด๋ธ ์คํ์ผ */
|
453 |
table {
|
454 |
background-color: var(--card-bg) !important;
|
455 |
color: var(--text-color) !important;
|
456 |
border-color: var(--border-color) !important;
|
457 |
}
|
458 |
-
|
459 |
table th {
|
460 |
background-color: var(--primary-color) !important;
|
461 |
color: white !important;
|
462 |
border-color: var(--border-color) !important;
|
463 |
}
|
464 |
-
|
465 |
table td {
|
466 |
background-color: var(--card-bg) !important;
|
467 |
color: var(--text-color) !important;
|
468 |
border-color: var(--border-color) !important;
|
469 |
}
|
470 |
-
|
471 |
table tbody tr:nth-child(even) {
|
472 |
background-color: var(--table-even-bg) !important;
|
473 |
}
|
474 |
-
|
475 |
table tbody tr:hover {
|
476 |
background-color: var(--table-hover-bg) !important;
|
477 |
}
|
478 |
-
|
479 |
/* 13. ์ฒดํฌ๋ฐ์ค ๋ฐ ๋ผ๋์ค ๋ฒํผ */
|
480 |
input[type="checkbox"],
|
481 |
input[type="radio"] {
|
482 |
accent-color: var(--primary-color) !important;
|
483 |
}
|
484 |
-
|
485 |
/* 14. ๋ฒํผ ๊ทธ๋ฃน */
|
486 |
.button-grid {
|
487 |
display: grid;
|
@@ -489,24 +623,20 @@ input[type="radio"] {
|
|
489 |
gap: 0.8rem;
|
490 |
margin-bottom: 1.2rem;
|
491 |
}
|
492 |
-
|
493 |
/* 15. ์คํฌ๋กค๋ฐ ์คํ์ผ */
|
494 |
::-webkit-scrollbar-thumb:hover {
|
495 |
background: var(--secondary-color);
|
496 |
}
|
497 |
-
|
498 |
/* 16. ์์ฝ๋์ธ ๋ฐ ๋๋กญ๋ค์ด */
|
499 |
details {
|
500 |
background-color: var(--card-bg) !important;
|
501 |
border-color: var(--border-color) !important;
|
502 |
color: var(--text-color) !important;
|
503 |
}
|
504 |
-
|
505 |
details summary {
|
506 |
background-color: var(--card-bg) !important;
|
507 |
color: var(--text-color) !important;
|
508 |
}
|
509 |
-
|
510 |
/* 17. ํดํ ๋ฐ ํ์
*/
|
511 |
[data-tooltip]:hover::after,
|
512 |
.tooltip,
|
@@ -516,7 +646,6 @@ details summary {
|
|
516 |
border-color: var(--border-color) !important;
|
517 |
box-shadow: var(--shadow-light) !important;
|
518 |
}
|
519 |
-
|
520 |
/* 18. ๋ชจ๋ฌ ๋ฐ ์ค๋ฒ๋ ์ด */
|
521 |
.modal,
|
522 |
.overlay,
|
@@ -526,7 +655,6 @@ details summary {
|
|
526 |
color: var(--text-color) !important;
|
527 |
border-color: var(--border-color) !important;
|
528 |
}
|
529 |
-
|
530 |
/* 19. ์ถ๊ฐ Gradio ์ปดํฌ๋ํธ๋ค */
|
531 |
.gr-block,
|
532 |
.gr-group,
|
@@ -535,7 +663,6 @@ details summary {
|
|
535 |
background-color: var(--background-color) !important;
|
536 |
color: var(--text-color) !important;
|
537 |
}
|
538 |
-
|
539 |
/* 20. ์ฝ๋ ๋ธ๋ก ๋ฐ pre ํ๊ทธ */
|
540 |
code,
|
541 |
pre,
|
@@ -544,7 +671,6 @@ pre,
|
|
544 |
color: var(--text-color) !important;
|
545 |
border-color: var(--border-color) !important;
|
546 |
}
|
547 |
-
|
548 |
/* 21. ์๋ฆผ ๋ฐ ๋ฉ์์ง */
|
549 |
.alert,
|
550 |
.message,
|
@@ -556,17 +682,14 @@ pre,
|
|
556 |
color: var(--text-color) !important;
|
557 |
border-color: var(--border-color) !important;
|
558 |
}
|
559 |
-
|
560 |
/* 22. ์ ๋๋ฉ์ด์
์คํ์ผ */
|
561 |
@keyframes fadeIn {
|
562 |
from { opacity: 0; transform: translateY(10px); }
|
563 |
to { opacity: 1; transform: translateY(0); }
|
564 |
}
|
565 |
-
|
566 |
.fade-in {
|
567 |
animation: fadeIn 0.5s ease-out;
|
568 |
}
|
569 |
-
|
570 |
/* 23. Examples ์น์
์คํ์ผ */
|
571 |
.examples-section {
|
572 |
display: grid;
|
@@ -574,7 +697,6 @@ pre,
|
|
574 |
gap: 1.5rem;
|
575 |
margin-top: 1rem;
|
576 |
}
|
577 |
-
|
578 |
.example-item {
|
579 |
background-color: var(--card-bg);
|
580 |
border-radius: var(--border-radius);
|
@@ -582,18 +704,15 @@ pre,
|
|
582 |
box-shadow: var(--shadow);
|
583 |
transition: transform 0.3s ease, background-color 0.3s ease;
|
584 |
}
|
585 |
-
|
586 |
.example-item:hover {
|
587 |
transform: translateY(-5px);
|
588 |
}
|
589 |
-
|
590 |
/* 24. ์ ํ ์ ๋๋ฉ์ด์
*/
|
591 |
* {
|
592 |
transition: background-color 0.3s ease,
|
593 |
color 0.3s ease,
|
594 |
border-color 0.3s ease !important;
|
595 |
}
|
596 |
-
|
597 |
/* 25. ๋ฐ์ํ */
|
598 |
@media (max-width: 768px) {
|
599 |
.button-grid {
|
@@ -621,7 +740,10 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default(
|
|
621 |
font=[gr.themes.GoogleFont("Noto Sans KR"), "ui-sans-serif", "system-ui"]
|
622 |
)) as demo:
|
623 |
gr.HTML(fontawesome_link)
|
|
|
|
|
624 |
|
|
|
625 |
with gr.Row(equal_height=True):
|
626 |
with gr.Column(scale=1):
|
627 |
# ======== ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์ค์ ์น์
========
|
@@ -710,36 +832,100 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default(
|
|
710 |
)
|
711 |
|
712 |
# ========== ์ด๋ฏธ์ง ์์ฑ๊ธฐ ์ด๋ฒคํธ ์ฐ๊ฒฐ ==========
|
713 |
-
# ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
714 |
-
image_change_btn1.click(
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
730 |
submit_single_btn.click(
|
731 |
fn=generate_single_image,
|
732 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
733 |
outputs=[output_image1, output_text, prompt_display],
|
734 |
)
|
735 |
|
736 |
-
# 2์ฅ ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
737 |
submit_btn.click(
|
738 |
fn=generate_multiple_images,
|
739 |
inputs=[image1_input, image2_input, image3_input, prompt_input],
|
740 |
outputs=[output_image1, output_image2, output_text, prompt_display],
|
741 |
)
|
742 |
|
743 |
-
|
|
|
|
|
744 |
demo.queue()
|
745 |
-
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 ํ๋ผ๋ฏธํฐ ์ถ๊ฐ
|