ssboost commited on
Commit
42fde2a
ยท
verified ยท
1 Parent(s): 9a19108

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +284 -25
app.py CHANGED
@@ -1,27 +1,287 @@
1
- global SPECIAL_BACKGROUNDS
2
-
3
- logger.info(f"Backgrounds ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ: {BACKGROUNDS_DIR}")
4
- logger.info(f"๋””๋ ‰ํ† ๋ฆฌ ๋‚ด ํŒŒ์ผ ๋ชฉ๋ก: {os.listdir(BACKGROUNDS_DIR)}")
5
-
6
- SIMPLE_BACKGROUNDS = load_background_json("simple_backgrounds.json")
7
- STUDIO_BACKGROUNDS = load_background_json("studio_backgrounds.json")
8
- NATURE_BACKGROUNDS = load_background_json("nature_backgrounds.json")
9
- INDOOR_BACKGROUNDS = load_background_json("indoor_backgrounds.json")
10
- SPECIAL_BACKGROUNDS = load_background_json("special_backgrounds.json")
11
-
12
- # ๊ธฐ๋ณธ๊ฐ’ ์„ค์ • (ํŒŒ์ผ์ด ์—†๊ฑฐ๋‚˜ ๋น„์–ด์žˆ๋Š” ๊ฒฝ์šฐ)
13
- if not SIMPLE_BACKGROUNDS:
14
- SIMPLE_BACKGROUNDS = {"ํด๋ž˜์‹ ํ™”์ดํŠธ": "clean white background with soft even lighting"}
15
- if not STUDIO_BACKGROUNDS:
16
- STUDIO_BACKGROUNDS = {"๋ฏธ๋‹ˆ๋ฉ€ ํ”Œ๋žซ๋ ˆ์ด": "minimalist flat lay with clean white background"}
17
- if not NATURE_BACKGROUNDS:
18
- NATURE_BACKGROUNDS = {"์—ด๋Œ€ ํ•ด๋ณ€": "tropical beach with crystal clear water"}
19
- if not INDOOR_BACKGROUNDS:
20
- INDOOR_BACKGROUNDS = {"๋ฏธ๋‹ˆ๋ฉ€ ์Šค์นธ๋””๋‚˜๋น„์•ˆ ๊ฑฐ์‹ค": "minimalist Scandinavian living room"}
21
- if not SPECIAL_BACKGROUNDS:
22
- SPECIAL_BACKGROUNDS = {"๋„ค์˜จ ๋ผ์ดํŠธ": "neon light background with vibrant glowing elements"}
23
-
24
- logger.info("๋ชจ๋“  ๋ฐฐ๊ฒฝ ์˜ต์…˜ ์ดˆ๊ธฐํ™” ์™„๋ฃŒ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) # ์š”์ฒญ์„ ์ˆœ์ฐจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ ์„ค์ •