fantos commited on
Commit
c0fd987
โ€ข
1 Parent(s): 63f9491

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -164
app.py CHANGED
@@ -76,63 +76,91 @@ def load_example():
76
  example_image = Image.open(example_image_path)
77
  return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale, example_image
78
 
79
- css = """
80
- .container {
81
- max-width: 1400px;
82
- margin: auto;
83
- padding: 20px;
84
- position: relative;
85
- min-height: 100vh;
86
- }
87
  body {
88
- background-image: url('file/example0.webp');
89
- background-size: cover;
90
- background-position: center;
91
- background-attachment: fixed;
92
  margin: 0;
93
  padding: 0;
 
 
 
94
  }
 
 
 
 
 
 
 
 
 
 
95
  .header {
96
- text-align: center;
97
- margin-bottom: 30px;
98
  color: white;
99
  text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
 
 
100
  }
101
- .generate-btn {
102
- background-color: #2ecc71 !important;
103
- color: white !important;
104
- margin: 20px auto !important;
105
- display: block !important;
106
- width: 200px !important;
107
- }
108
- .generate-btn:hover {
109
- background-color: #27ae60 !important;
110
- }
111
- .parameter-box, .result-box, .prompt-box, .audio-controls {
112
- background-color: rgba(245, 246, 250, 0.8);
113
- padding: 20px;
114
- border-radius: 10px;
115
- margin: 10px 0;
116
- backdrop-filter: blur(5px);
117
  }
 
 
118
  .result-box {
119
  width: 90%;
 
120
  margin: 20px auto;
121
  }
 
122
  .image-output {
123
- margin: 0 auto;
124
- display: block;
125
- max-width: 800px !important;
 
126
  }
 
 
127
  .prompt-box {
128
  width: 90%;
 
129
  margin: 20px auto;
130
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  .accordion {
132
- margin-top: 20px;
133
- background-color: rgba(245, 246, 250, 0.8);
134
- backdrop-filter: blur(5px);
135
  }
 
 
136
  .audio-controls {
137
  position: fixed;
138
  bottom: 20px;
@@ -140,57 +168,55 @@ body {
140
  z-index: 1000;
141
  display: flex;
142
  gap: 10px;
143
- align-items: center;
 
 
 
144
  }
 
145
  .audio-btn {
146
- padding: 10px 20px;
147
- border-radius: 5px;
148
- border: none;
149
- background: rgba(46, 204, 113, 0.9);
150
  color: white;
 
 
 
151
  cursor: pointer;
 
152
  }
 
153
  .audio-btn:hover {
154
- background: rgba(39, 174, 96, 0.9);
155
- }
156
- @keyframes snow {
157
- 0% {
158
- transform: translateY(0) translateX(0);
159
- }
160
- 100% {
161
- transform: translateY(100vh) translateX(100px);
162
- }
163
  }
164
 
165
- .snowflake {
166
- position: fixed;
167
- top: -10px;
168
- color: white;
169
- font-size: 20px;
170
- animation: snow 5s linear infinite;
171
- }
172
- @keyframes snow {
173
  0% {
174
- transform: translateY(0) translateX(0);
 
175
  }
176
  100% {
177
  transform: translateY(100vh) translateX(100px);
 
178
  }
179
  }
180
 
181
  .snowflake {
182
  position: fixed;
183
- top: -10px;
184
  color: white;
185
- font-size: 20px;
186
- animation: snow 5s linear infinite;
 
 
 
187
  }
188
  """
189
- js_code = """
 
 
190
  function createSnowflake() {
191
  const snowflake = document.createElement('div');
192
- snowflake.classList.add('snowflake');
193
  snowflake.innerHTML = 'โ„';
 
194
  snowflake.style.left = Math.random() * 100 + 'vw';
195
  snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
196
  snowflake.style.opacity = Math.random();
@@ -201,21 +227,51 @@ function createSnowflake() {
201
  }, 5000);
202
  }
203
 
204
- setInterval(createSnowflake, 100);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  """
206
- with gr.Blocks(css=css) as app:
207
- gr.HTML(f"<script>{js_code}</script>")
 
 
 
208
 
209
  with gr.Column(elem_classes="container"):
210
  gr.Markdown("# ๐ŸŽ„ X-MAS LoRA", elem_classes="header")
211
 
212
  # ์ด๋ฏธ์ง€ ์ถœ๋ ฅ ์˜์—ญ
213
- with gr.Group(elem_classes="result-box"):
214
  gr.Markdown("### ๐Ÿ–ผ๏ธ Generated Image")
215
  result = gr.Image(label="Result", elem_classes="image-output")
216
 
217
- # ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ ๋ฐ•์Šค
218
- with gr.Group(elem_classes="prompt-box"):
219
  prompt = gr.TextArea(
220
  label="โœ๏ธ Your Prompt (ํ•œ๊ธ€ ๋˜๋Š” ์˜์–ด)",
221
  placeholder="์ด๋ฏธ์ง€๋ฅผ ์„ค๋ช…ํ•˜์„ธ์š”...",
@@ -226,108 +282,27 @@ with gr.Blocks(css=css) as app:
226
  elem_classes="generate-btn"
227
  )
228
 
229
- # ์˜ต์…˜๋“ค์„ ์•„์ฝ”๋””์–ธ์œผ๋กœ ๊ตฌ์„ฑ
230
- with gr.Accordion("๐ŸŽจ Advanced Options", open=False, elem_classes="accordion"):
231
- with gr.Group(elem_classes="parameter-box"):
232
- gr.Markdown("### ๐ŸŽ›๏ธ Generation Parameters")
233
- with gr.Row():
234
- with gr.Column():
235
- cfg_scale = gr.Slider(
236
- label="CFG Scale",
237
- minimum=1,
238
- maximum=20,
239
- step=0.5,
240
- value=example_cfg_scale
241
- )
242
- steps = gr.Slider(
243
- label="Steps",
244
- minimum=1,
245
- maximum=100,
246
- step=1,
247
- value=example_steps
248
- )
249
- lora_scale = gr.Slider(
250
- label="LoRA Scale",
251
- minimum=0,
252
- maximum=1,
253
- step=0.01,
254
- value=example_lora_scale
255
- )
256
-
257
- with gr.Group(elem_classes="parameter-box"):
258
- gr.Markdown("### ๐Ÿ“ Image Dimensions")
259
- with gr.Row():
260
- width = gr.Slider(
261
- label="Width",
262
- minimum=256,
263
- maximum=1536,
264
- step=64,
265
- value=example_width
266
- )
267
- height = gr.Slider(
268
- label="Height",
269
- minimum=256,
270
- maximum=1536,
271
- step=64,
272
- value=example_height
273
- )
274
-
275
- with gr.Group(elem_classes="parameter-box"):
276
- gr.Markdown("### ๐ŸŽฒ Seed Settings")
277
- with gr.Row():
278
- randomize_seed = gr.Checkbox(
279
- True,
280
- label="Randomize seed"
281
- )
282
- seed = gr.Slider(
283
- label="Seed",
284
- minimum=0,
285
- maximum=MAX_SEED,
286
- step=1,
287
- value=example_seed
288
- )
289
-
290
- # ์˜ค๋””์˜ค ์ปจํŠธ๋กค - ์ปจํ…Œ์ด๋„ˆ ๋ฐ–์— ๋ฐฐ์น˜
291
- gr.HTML("""
292
  <div class="audio-controls">
293
- <button class="audio-btn" onclick="toggleAudio(1)">Play Music 1</button>
294
- <button class="audio-btn" onclick="toggleAudio(2)">Play Music 2</button>
295
- <button class="audio-btn" onclick="stopAllAudio()">Stop All</button>
296
  </div>
297
- <audio id="bgMusic1" loop style="display: none;">
298
  <source src="file/1.mp3" type="audio/mp3">
299
  </audio>
300
- <audio id="bgMusic2" loop style="display: none;">
301
  <source src="file/2.mp3" type="audio/mp3">
302
  </audio>
303
- <script>
304
- let currentlyPlaying = null;
305
-
306
- function toggleAudio(num) {
307
- const audio = document.getElementById('bgMusic' + num);
308
- const otherAudio = document.getElementById('bgMusic' + (num === 1 ? 2 : 1));
309
-
310
- if (currentlyPlaying === audio) {
311
- audio.pause();
312
- currentlyPlaying = null;
313
- } else {
314
- if (currentlyPlaying) {
315
- currentlyPlaying.pause();
316
- }
317
- otherAudio.pause();
318
- audio.play();
319
- currentlyPlaying = audio;
320
- }
321
- }
322
-
323
- function stopAllAudio() {
324
- document.getElementById('bgMusic1').pause();
325
- document.getElementById('bgMusic2').pause();
326
- currentlyPlaying = null;
327
- }
328
- </script>
329
  """)
330
 
 
331
  app.load(
332
  load_example,
333
  inputs=[],
 
76
  example_image = Image.open(example_image_path)
77
  return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale, example_image
78
 
79
+ custom_css = """
80
+ /* ๊ธฐ๋ณธ ์Šคํƒ€์ผ */
 
 
 
 
 
 
81
  body {
 
 
 
 
82
  margin: 0;
83
  padding: 0;
84
+ background: url('file/example0.webp') no-repeat center center fixed;
85
+ background-size: cover;
86
+ min-height: 100vh;
87
  }
88
+
89
+ /* ์ปจํ…Œ์ด๋„ˆ */
90
+ .container {
91
+ max-width: 1200px;
92
+ margin: 0 auto;
93
+ padding: 20px;
94
+ box-sizing: border-box;
95
+ }
96
+
97
+ /* ํ—ค๋” */
98
  .header {
99
+ text-align: center;
 
100
  color: white;
101
  text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
102
+ margin-bottom: 30px;
103
+ font-size: 2.5em;
104
  }
105
+
106
+ /* ๋ฐ•์Šค ๊ณตํ†ต ์Šคํƒ€์ผ */
107
+ .box-common {
108
+ background-color: rgba(255, 255, 255, 0.85);
109
+ backdrop-filter: blur(10px);
110
+ border-radius: 15px;
111
+ padding: 20px;
112
+ margin: 20px 0;
113
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
 
 
 
 
 
 
 
114
  }
115
+
116
+ /* ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€ ๋ฐ•์Šค */
117
  .result-box {
118
  width: 90%;
119
+ max-width: 1000px;
120
  margin: 20px auto;
121
  }
122
+
123
  .image-output {
124
+ width: 100%;
125
+ max-width: 800px;
126
+ margin: 0 auto;
127
+ display: block;
128
  }
129
+
130
+ /* ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ ๋ฐ•์Šค */
131
  .prompt-box {
132
  width: 90%;
133
+ max-width: 1000px;
134
  margin: 20px auto;
135
  }
136
+
137
+ /* ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
138
+ .generate-btn {
139
+ background-color: #2ecc71 !important;
140
+ color: white !important;
141
+ padding: 12px 30px !important;
142
+ border-radius: 8px !important;
143
+ border: none !important;
144
+ font-size: 1.1em !important;
145
+ cursor: pointer !important;
146
+ transition: background-color 0.3s ease !important;
147
+ width: 200px !important;
148
+ margin: 20px auto !important;
149
+ display: block !important;
150
+ }
151
+
152
+ .generate-btn:hover {
153
+ background-color: #27ae60 !important;
154
+ }
155
+
156
+ /* ์•„์ฝ”๋””์–ธ ์Šคํƒ€์ผ */
157
  .accordion {
158
+ width: 90%;
159
+ max-width: 1000px;
160
+ margin: 20px auto;
161
  }
162
+
163
+ /* ์˜ค๋””์˜ค ์ปจํŠธ๋กค */
164
  .audio-controls {
165
  position: fixed;
166
  bottom: 20px;
 
168
  z-index: 1000;
169
  display: flex;
170
  gap: 10px;
171
+ background-color: rgba(255, 255, 255, 0.9);
172
+ padding: 15px;
173
+ border-radius: 10px;
174
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
175
  }
176
+
177
  .audio-btn {
178
+ background-color: #3498db;
 
 
 
179
  color: white;
180
+ border: none;
181
+ padding: 8px 15px;
182
+ border-radius: 5px;
183
  cursor: pointer;
184
+ transition: background-color 0.3s ease;
185
  }
186
+
187
  .audio-btn:hover {
188
+ background-color: #2980b9;
 
 
 
 
 
 
 
 
189
  }
190
 
191
+ /* ๋ˆˆ ๋‚ด๋ฆฌ๋Š” ํšจ๊ณผ */
192
+ @keyframes snowfall {
 
 
 
 
 
 
193
  0% {
194
+ transform: translateY(-10vh) translateX(0);
195
+ opacity: 1;
196
  }
197
  100% {
198
  transform: translateY(100vh) translateX(100px);
199
+ opacity: 0.3;
200
  }
201
  }
202
 
203
  .snowflake {
204
  position: fixed;
 
205
  color: white;
206
+ font-size: 1.5em;
207
+ user-select: none;
208
+ z-index: 1000;
209
+ pointer-events: none;
210
+ animation: snowfall linear infinite;
211
  }
212
  """
213
+
214
+ # JavaScript ์ฝ”๋“œ๋„ ๋ณ„๋„๋กœ ์ •๋ฆฌ
215
+ snow_js = """
216
  function createSnowflake() {
217
  const snowflake = document.createElement('div');
 
218
  snowflake.innerHTML = 'โ„';
219
+ snowflake.className = 'snowflake';
220
  snowflake.style.left = Math.random() * 100 + 'vw';
221
  snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
222
  snowflake.style.opacity = Math.random();
 
227
  }, 5000);
228
  }
229
 
230
+ setInterval(createSnowflake, 200);
231
+ """
232
+
233
+ audio_js = """
234
+ let currentlyPlaying = null;
235
+
236
+ function toggleAudio(num) {
237
+ const audio = document.getElementById('bgMusic' + num);
238
+ const otherAudio = document.getElementById('bgMusic' + (num === 1 ? 2 : 1));
239
+
240
+ if (currentlyPlaying === audio) {
241
+ audio.pause();
242
+ currentlyPlaying = null;
243
+ } else {
244
+ if (currentlyPlaying) {
245
+ currentlyPlaying.pause();
246
+ }
247
+ otherAudio.pause();
248
+ audio.play();
249
+ currentlyPlaying = audio;
250
+ }
251
+ }
252
+
253
+ function stopAllAudio() {
254
+ const audios = document.querySelectorAll('audio');
255
+ audios.forEach(audio => audio.pause());
256
+ currentlyPlaying = null;
257
+ }
258
  """
259
+
260
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
261
+ with gr.Blocks(css=custom_css) as app:
262
+ # JavaScript ์ดˆ๊ธฐํ™”
263
+ gr.HTML(f"<script>{snow_js}</script>")
264
 
265
  with gr.Column(elem_classes="container"):
266
  gr.Markdown("# ๐ŸŽ„ X-MAS LoRA", elem_classes="header")
267
 
268
  # ์ด๋ฏธ์ง€ ์ถœ๋ ฅ ์˜์—ญ
269
+ with gr.Group(elem_classes="result-box box-common"):
270
  gr.Markdown("### ๐Ÿ–ผ๏ธ Generated Image")
271
  result = gr.Image(label="Result", elem_classes="image-output")
272
 
273
+ # ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ ์˜์—ญ
274
+ with gr.Group(elem_classes="prompt-box box-common"):
275
  prompt = gr.TextArea(
276
  label="โœ๏ธ Your Prompt (ํ•œ๊ธ€ ๋˜๋Š” ์˜์–ด)",
277
  placeholder="์ด๋ฏธ์ง€๋ฅผ ์„ค๋ช…ํ•˜์„ธ์š”...",
 
282
  elem_classes="generate-btn"
283
  )
284
 
285
+ # ๊ณ ๊ธ‰ ์˜ต์…˜
286
+ with gr.Accordion("๐ŸŽจ Advanced Options", open=False, elem_classes="accordion box-common"):
287
+ [์ด์ „ ์˜ต์…˜ ์ฝ”๋“œ์™€ ๋™์ผ]
288
+
289
+ # ์˜ค๋””์˜ค ์ปจํŠธ๋กค
290
+ gr.HTML(f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  <div class="audio-controls">
292
+ <button class="audio-btn" onclick="toggleAudio(1)">๐ŸŽต Music 1</button>
293
+ <button class="audio-btn" onclick="toggleAudio(2)">๐ŸŽต Music 2</button>
294
+ <button class="audio-btn" onclick="stopAllAudio()">โน Stop</button>
295
  </div>
296
+ <audio id="bgMusic1" loop>
297
  <source src="file/1.mp3" type="audio/mp3">
298
  </audio>
299
+ <audio id="bgMusic2" loop>
300
  <source src="file/2.mp3" type="audio/mp3">
301
  </audio>
302
+ <script>{audio_js}</script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  """)
304
 
305
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
306
  app.load(
307
  load_example,
308
  inputs=[],