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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# ------------------- ์์ ํญ์ ์ํ ํจ์ -------------------
|
27 |
def load_image_cached(image_path):
|
@@ -191,7 +451,6 @@ def create_app():
|
|
191 |
return demo
|
192 |
|
193 |
if __name__ == "__main__":
|
194 |
-
initialize_backgrounds()
|
195 |
preload_example_images() # ์์ ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ ๋ก๋
|
196 |
app = create_app()
|
197 |
app.queue(max_size=10) # ์์ฒญ์ ์์ฐจ์ ์ผ๋ก ์ฒ๋ฆฌํ๋๋ก ํ ์ค์
|
|
|
1 |
+
import os
|
2 |
+
import logging
|
3 |
+
import json
|
4 |
+
import time
|
5 |
+
from PIL import Image
|
6 |
+
import gradio as gr
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
# ------------------- ๋ก๊น
์ค์ -------------------
|
12 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
+
logger = logging.getLogger(__name__)
|
14 |
+
|
15 |
+
# ------------------- ๋ฐฐ๊ฒฝ ๋๋ ํ ๋ฆฌ ์ค์ -------------------
|
16 |
+
BACKGROUNDS_DIR = "./background"
|
17 |
+
if not os.path.exists(BACKGROUNDS_DIR):
|
18 |
+
os.makedirs(BACKGROUNDS_DIR)
|
19 |
+
logger.info(f"๋ฐฐ๊ฒฝ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํ์ต๋๋ค: {BACKGROUNDS_DIR}")
|
20 |
+
|
21 |
+
# ์์ ๋ฐ์ดํฐ ๋ก๋
|
22 |
+
from db_examples import product_background_examples
|
23 |
+
|
24 |
+
# ------------------- ์ ์ญ ๋ณ์ ์ค์ -------------------
|
25 |
+
IMAGE_CACHE = {} # ์ด๋ฏธ์ง ์บ์ ์ถ๊ฐ
|
26 |
+
|
27 |
+
# ์ปค์คํ
CSS ์คํ์ผ
|
28 |
+
custom_css = """
|
29 |
+
:root {
|
30 |
+
--primary-color: #FB7F0D;
|
31 |
+
--secondary-color: #ff9a8b;
|
32 |
+
--accent-color: #FF6B6B;
|
33 |
+
--background-color: #FFFFFF; /* ๋ฒ ์ด์ง์(#FFF3E9)์์ ์์ ํ ํฐ์(#FFFFFF)์ผ๋ก ๋ณ๊ฒฝ */
|
34 |
+
--card-bg: #ffffff;
|
35 |
+
--text-color: #334155;
|
36 |
+
--border-radius: 18px;
|
37 |
+
--shadow: 0 8px 30px rgba(251, 127, 13, 0.08);
|
38 |
+
}
|
39 |
+
|
40 |
+
/* ์์ ๊ฐค๋ฌ๋ฆฌ ์คํ์ผ */
|
41 |
+
.example-gallery {
|
42 |
+
display: grid;
|
43 |
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
44 |
+
gap: 20px;
|
45 |
+
padding: 20px;
|
46 |
+
}
|
47 |
+
|
48 |
+
.example-item {
|
49 |
+
cursor: pointer;
|
50 |
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
51 |
+
border-radius: var(--border-radius);
|
52 |
+
overflow: hidden;
|
53 |
+
transition: all 0.3s ease;
|
54 |
+
background: white;
|
55 |
+
}
|
56 |
+
|
57 |
+
.example-item:hover {
|
58 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
59 |
+
transform: translateY(-2px);
|
60 |
+
}
|
61 |
+
|
62 |
+
.example-item img {
|
63 |
+
width: 100%;
|
64 |
+
height: 250px;
|
65 |
+
object-fit: cover;
|
66 |
+
}
|
67 |
+
|
68 |
+
.example-label {
|
69 |
+
padding: 10px;
|
70 |
+
text-align: center;
|
71 |
+
font-weight: bold;
|
72 |
+
background: rgba(251, 127, 13, 0.1);
|
73 |
+
}
|
74 |
+
|
75 |
+
.example-detail-view {
|
76 |
+
margin-bottom: 30px;
|
77 |
+
}
|
78 |
+
|
79 |
+
.example-params {
|
80 |
+
background: white;
|
81 |
+
padding: 20px;
|
82 |
+
border-radius: var(--border-radius);
|
83 |
+
box-shadow: var(--shadow);
|
84 |
+
}
|
85 |
+
|
86 |
+
.example-params p {
|
87 |
+
margin: 10px 0;
|
88 |
+
font-size: 16px;
|
89 |
+
}
|
90 |
+
|
91 |
+
.example-params strong {
|
92 |
+
color: var(--primary-color);
|
93 |
+
}
|
94 |
+
|
95 |
+
/* ์ ํ๋ ์์ ํ์ด๋ผ์ดํธ */
|
96 |
+
.example-item.selected {
|
97 |
+
border: 3px solid var(--primary-color);
|
98 |
+
}
|
99 |
+
|
100 |
+
/* โโ ๊ทธ๋ฃน ๋ํผ ๋ฐฐ๊ฒฝ ์์ ์ ๊ฑฐ โโ */
|
101 |
+
.custom-section-group,
|
102 |
+
.gr-block.gr-group {
|
103 |
+
background-color: var(--background-color) !important; /* ๋ณ๊ฒฝ๋ ๋ฐฐ๊ฒฝ์ ๋ณ์ ์ฌ์ฉ */
|
104 |
+
box-shadow: none !important;
|
105 |
+
}
|
106 |
+
.custom-section-group::before,
|
107 |
+
.custom-section-group::after,
|
108 |
+
.gr-block.gr-group::before,
|
109 |
+
.gr-block.gr-group::after {
|
110 |
+
display: none !important;
|
111 |
+
content: none !important;
|
112 |
+
}
|
113 |
+
|
114 |
+
/* ๊ทธ๋ฃน ์ปจํ
์ด๋ ๋ฐฐ๊ฒฝ์ ์์ด๋ณด๋ฆฌ๋ก, ๊ทธ๋ฆผ์ ์ ๊ฑฐ */
|
115 |
+
.custom-section-group {
|
116 |
+
background-color: var(--background-color) !important; /* ๋ณ๊ฒฝ๋ ๋ฐฐ๊ฒฝ์ ๋ณ์ ์ฌ์ฉ */
|
117 |
+
box-shadow: none !important;
|
118 |
+
}
|
119 |
+
/* ์๋จยทํ๋จ์ ๊ทธ๋ ค์ง๋ ํ์ ์บก(๋ฅ๊ทผ ๋ชจ์๋ฆฌ) ์ ๊ฑฐ */
|
120 |
+
.custom-section-group::before,
|
121 |
+
.custom-section-group::after {
|
122 |
+
display: none !important;
|
123 |
+
content: none !important;
|
124 |
+
}
|
125 |
+
|
126 |
+
body {
|
127 |
+
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
128 |
+
background-color: var(--background-color); /* ๋ณ๊ฒฝ๋ ๋ฐฐ๊ฒฝ์ ๋ณ์ ์ฌ์ฉ */
|
129 |
+
color: var(--text-color);
|
130 |
+
line-height: 1.6;
|
131 |
+
margin: 0;
|
132 |
+
padding: 0;
|
133 |
+
}
|
134 |
+
|
135 |
+
/* ํธํฐ ์จ๊น ์ค์ ์ถ๊ฐ */
|
136 |
+
footer {
|
137 |
+
visibility: hidden;
|
138 |
+
}
|
139 |
+
|
140 |
+
.gradio-container {
|
141 |
+
width: 100%; /* ์ ์ฒด ๋๋น 100% ๊ณ ์ */
|
142 |
+
margin: 0 auto;
|
143 |
+
padding: 20px;
|
144 |
+
background-color: var(--background-color); /* ๋ณ๊ฒฝ๋ ๋ฐฐ๊ฒฝ์ ๋ณ์ ์ฌ์ฉ */
|
145 |
+
}
|
146 |
+
|
147 |
+
/* ์ฝํ
์ธ ๋ฐ์ค (ํ๋ ์) ์คํ์ผ */
|
148 |
+
.custom-frame {
|
149 |
+
background-color: var(--card-bg);
|
150 |
+
border: 1px solid rgba(0, 0, 0, 0.04);
|
151 |
+
border-radius: var(--border-radius);
|
152 |
+
padding: 20px;
|
153 |
+
margin: 10px 0;
|
154 |
+
box-shadow: var(--shadow);
|
155 |
+
}
|
156 |
+
|
157 |
+
/* ์น์
๊ทธ๋ฃน ์คํ์ผ - ํ์ ๋ฐฐ๊ฒฝ ์์ ์ ๊ฑฐ */
|
158 |
+
.custom-section-group {
|
159 |
+
margin-top: 20px;
|
160 |
+
padding: 0;
|
161 |
+
border: none;
|
162 |
+
border-radius: 0;
|
163 |
+
background-color: var(--background-color); /* ํ์ โ ์์ด๋ณด๋ฆฌ(์ ์ฒด ๋ฐฐ๊ฒฝ์) */
|
164 |
+
box-shadow: none !important; /* ํน์ ๋จ์์๋ ๊ทธ๋ฆผ์๋ ๊ฐ์ด ์ ๊ฑฐ */
|
165 |
+
}
|
166 |
+
|
167 |
+
/* ๋ฒํผ ์คํ์ผ - ๊ธ์ ํฌ๊ธฐ 18px */
|
168 |
+
.custom-button {
|
169 |
+
border-radius: 30px !important;
|
170 |
+
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
171 |
+
color: white !important;
|
172 |
+
font-size: 18px !important;
|
173 |
+
padding: 10px 20px !important;
|
174 |
+
border: none;
|
175 |
+
box-shadow: 0 4px 8px rgba(251, 127, 13, 0.25);
|
176 |
+
transition: transform 0.3s ease;
|
177 |
+
}
|
178 |
+
.custom-button:hover {
|
179 |
+
transform: translateY(-2px);
|
180 |
+
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3);
|
181 |
+
}
|
182 |
+
|
183 |
+
/* ์ ๋ชฉ ์คํ์ผ (๋ชจ๋ ํญ๋ชฉ๋ช
์ด ๋์ผํ๊ฒ custom-title ํด๋์ค๋ก) */
|
184 |
+
.custom-title {
|
185 |
+
font-size: 28px;
|
186 |
+
font-weight: bold;
|
187 |
+
margin-bottom: 10px;
|
188 |
+
color: var(--text-color);
|
189 |
+
border-bottom: 2px solid var(--primary-color);
|
190 |
+
padding-bottom: 5px;
|
191 |
+
}
|
192 |
+
|
193 |
+
/* ์ด๋ฏธ์ง ์ปจํ
์ด๋ */
|
194 |
+
.image-container {
|
195 |
+
border-radius: var(--border-radius);
|
196 |
+
overflow: hidden;
|
197 |
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
198 |
+
transition: all 0.3s ease;
|
199 |
+
background-color: white;
|
200 |
+
aspect-ratio: 1 / 1; /* ์ ์ฌ๊ฐํ ๋น์จ ๊ฐ์ */
|
201 |
+
}
|
202 |
+
|
203 |
+
.image-container:hover {
|
204 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
205 |
+
}
|
206 |
+
|
207 |
+
.image-container img {
|
208 |
+
width: 100%;
|
209 |
+
height: 100%;
|
210 |
+
object-fit: contain; /* ์ด๋ฏธ์ง ๋น์จ ์ ์งํ๋ฉด์ ์ปจํ
์ด๋์ ๋ง์ถค */
|
211 |
+
}
|
212 |
+
|
213 |
+
/* ์
๋ ฅ ํ๋ ์คํ์ผ */
|
214 |
+
.gr-input, .gr-text-input, .gr-sample-inputs {
|
215 |
+
border-radius: var(--border-radius) !important;
|
216 |
+
border: 1px solid #dddddd !important;
|
217 |
+
padding: 12px !important;
|
218 |
+
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
219 |
+
transition: all 0.3s ease !important;
|
220 |
+
}
|
221 |
+
|
222 |
+
.gr-input:focus, .gr-text-input:focus {
|
223 |
+
border-color: var(--primary-color) !important;
|
224 |
+
outline: none !important;
|
225 |
+
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
|
226 |
+
}
|
227 |
+
|
228 |
+
/* ๋ฉ์ธ ์ปจํ
์ธ ์คํฌ๋กค๋ฐ */
|
229 |
+
::-webkit-scrollbar {
|
230 |
+
width: 8px;
|
231 |
+
height: 8px;
|
232 |
+
}
|
233 |
+
|
234 |
+
::-webkit-scrollbar-track {
|
235 |
+
background: rgba(0, 0, 0, 0.05);
|
236 |
+
border-radius: 10px;
|
237 |
+
}
|
238 |
+
|
239 |
+
::-webkit-scrollbar-thumb {
|
240 |
+
background: var(--primary-color);
|
241 |
+
border-radius: 10px;
|
242 |
+
}
|
243 |
+
|
244 |
+
/* ์ ๋๋ฉ์ด์
์คํ์ผ */
|
245 |
+
@keyframes fadeIn {
|
246 |
+
from { opacity: 0; transform: translateY(10px); }
|
247 |
+
to { opacity: 1; transform: translateY(0); }
|
248 |
+
}
|
249 |
+
|
250 |
+
.fade-in {
|
251 |
+
animation: fadeIn 0.5s ease-out;
|
252 |
+
}
|
253 |
+
|
254 |
+
/* ๋ฐ์ํ */
|
255 |
+
@media (max-width: 768px) {
|
256 |
+
.button-grid {
|
257 |
+
grid-template-columns: repeat(2, 1fr);
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
/* ์น์
์ ๋ชฉ ์คํ์ผ - ์ฐธ์กฐ์ฝ๋ ์คํ์ผ๊ณผ ๋์ผํ๊ฒ ์ ์ฉ */
|
262 |
+
.section-title {
|
263 |
+
display: flex;
|
264 |
+
align-items: center;
|
265 |
+
font-size: 20px;
|
266 |
+
font-weight: 700;
|
267 |
+
color: #333333;
|
268 |
+
margin-bottom: 10px;
|
269 |
+
padding-bottom: 5px;
|
270 |
+
border-bottom: 2px solid #FB7F0D;
|
271 |
+
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
272 |
+
}
|
273 |
+
|
274 |
+
.section-title img {
|
275 |
+
margin-right: 10px;
|
276 |
+
width: 24px;
|
277 |
+
height: 24px;
|
278 |
+
}
|
279 |
+
"""
|
280 |
+
|
281 |
+
# FontAwesome ์์ด์ฝ ํฌํจ
|
282 |
+
fontawesome_link = """
|
283 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
284 |
+
"""
|
285 |
|
286 |
# ------------------- ์์ ํญ์ ์ํ ํจ์ -------------------
|
287 |
def load_image_cached(image_path):
|
|
|
451 |
return demo
|
452 |
|
453 |
if __name__ == "__main__":
|
|
|
454 |
preload_example_images() # ์์ ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ ๋ก๋
|
455 |
app = create_app()
|
456 |
app.queue(max_size=10) # ์์ฒญ์ ์์ฐจ์ ์ผ๋ก ์ฒ๋ฆฌํ๋๋ก ํ ์ค์
|