fantos commited on
Commit
f207d6b
β€’
1 Parent(s): 146a407

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +130 -26
app.py CHANGED
@@ -5,6 +5,9 @@ from PIL import Image
5
  from diffusers import DiffusionPipeline
6
  import random
7
  from transformers import pipeline
 
 
 
8
 
9
  torch.backends.cudnn.deterministic = True
10
  torch.backends.cudnn.benchmark = False
@@ -22,6 +25,23 @@ pipe.load_lora_weights(lora_repo)
22
 
23
  pipe.to("cuda")
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  MAX_SEED = 2**32-1
26
 
27
  @spaces.GPU()
@@ -73,42 +93,126 @@ def load_example():
73
  example_image = Image.open(example_image_path)
74
  return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale, example_image
75
 
76
-
77
  css = """
78
- .container {max-width: 1400px; margin: auto; padding: 20px;}
79
- .header {text-align: center; margin-bottom: 30px;}
80
- .generate-btn {background-color: #2ecc71 !important; color: white !important; margin: 20px auto !important; display: block !important; width: 200px !important;}
81
- .generate-btn:hover {background-color: #27ae60 !important;}
82
- .parameter-box {background-color: #f5f6fa; padding: 20px; border-radius: 10px; margin: 10px 0;}
83
- .result-box {background-color: #f5f6fa; padding: 20px; border-radius: 10px; margin: 0 auto 20px auto; text-align: center;}
84
- .image-output {margin: 0 auto; display: block; max-width: 800px !important;}
85
- .accordion {margin-top: 20px;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  """
87
 
88
  with gr.Blocks(css=css) as app:
 
 
89
  with gr.Column(elem_classes="container"):
90
- gr.Markdown("# 🎨 X-MAS LoRA", elem_classes="header")
91
 
92
- # 이미지 좜λ ₯ μ˜μ—­μ„ λ¨Όμ € 배치
 
 
 
 
 
 
 
 
 
 
 
 
93
  with gr.Group(elem_classes="result-box"):
94
  gr.Markdown("### πŸ–ΌοΈ Generated Image")
95
  result = gr.Image(label="Result", elem_classes="image-output")
96
-
97
- # 생성 λ²„νŠΌ
98
- generate_button = gr.Button(
99
- "πŸš€ Generate Image",
100
- elem_classes="generate-btn"
101
- )
102
 
103
  # μ˜΅μ…˜λ“€μ„ μ•„μ½”λ””μ–ΈμœΌλ‘œ ꡬ성
104
- with gr.Accordion("🎨 Generation Options", open=False, elem_classes="accordion"):
105
- with gr.Group(elem_classes="parameter-box"):
106
- prompt = gr.TextArea(
107
- label="✍️ Your Prompt (ν•œκΈ€ λ˜λŠ” μ˜μ–΄)",
108
- placeholder="이미지λ₯Ό μ„€λͺ…ν•˜μ„Έμš”... (ν•œκΈ€ μž…λ ₯μ‹œ μžλ™μœΌλ‘œ μ˜μ–΄λ‘œ λ²ˆμ—­λ©λ‹ˆλ‹€)",
109
- lines=5
110
- )
111
-
112
  with gr.Group(elem_classes="parameter-box"):
113
  gr.Markdown("### πŸŽ›οΈ Generation Parameters")
114
  with gr.Row():
@@ -181,4 +285,4 @@ with gr.Blocks(css=css) as app:
181
  )
182
 
183
  app.queue()
184
- app.launch()
 
5
  from diffusers import DiffusionPipeline
6
  import random
7
  from transformers import pipeline
8
+ import pygame
9
+ import os
10
+ import threading
11
 
12
  torch.backends.cudnn.deterministic = True
13
  torch.backends.cudnn.benchmark = False
 
25
 
26
  pipe.to("cuda")
27
 
28
+ # pygame μ΄ˆκΈ°ν™” 및 μŒμ•… μ„€μ •
29
+ pygame.mixer.init()
30
+ def play_music():
31
+ pygame.mixer.music.load("1.mp3")
32
+ pygame.mixer.music.play()
33
+ pygame.mixer.music.queue("2.mp3")
34
+ pygame.mixer.music.set_endevent(pygame.USEREVENT)
35
+ while True:
36
+ for event in pygame.event.get():
37
+ if event.type == pygame.USEREVENT:
38
+ pygame.mixer.music.queue("1.mp3")
39
+ pygame.mixer.music.queue("2.mp3")
40
+
41
+ # λ°°κ²½μŒμ•… μž¬μƒ μ‹œμž‘ (별도 μŠ€λ ˆλ“œμ—μ„œ μ‹€ν–‰)
42
+ music_thread = threading.Thread(target=play_music, daemon=True)
43
+ music_thread.start()
44
+
45
  MAX_SEED = 2**32-1
46
 
47
  @spaces.GPU()
 
93
  example_image = Image.open(example_image_path)
94
  return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale, example_image
95
 
 
96
  css = """
97
+ .container {
98
+ max-width: 1400px;
99
+ margin: auto;
100
+ padding: 20px;
101
+ position: relative;
102
+ background-image: url('file/example0.webp');
103
+ background-size: cover;
104
+ background-position: center;
105
+ min-height: 100vh;
106
+ }
107
+ .header {
108
+ text-align: center;
109
+ margin-bottom: 30px;
110
+ color: white;
111
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
112
+ }
113
+ .generate-btn {
114
+ background-color: #2ecc71 !important;
115
+ color: white !important;
116
+ margin: 20px auto !important;
117
+ display: block !important;
118
+ width: 200px !important;
119
+ }
120
+ .generate-btn:hover {
121
+ background-color: #27ae60 !important;
122
+ }
123
+ .parameter-box {
124
+ background-color: rgba(245, 246, 250, 0.9);
125
+ padding: 20px;
126
+ border-radius: 10px;
127
+ margin: 10px 0;
128
+ }
129
+ .result-box {
130
+ background-color: rgba(245, 246, 250, 0.9);
131
+ padding: 20px;
132
+ border-radius: 10px;
133
+ margin: 0 auto 20px auto;
134
+ text-align: center;
135
+ }
136
+ .image-output {
137
+ margin: 0 auto;
138
+ display: block;
139
+ max-width: 800px !important;
140
+ }
141
+ .accordion {
142
+ margin-top: 20px;
143
+ }
144
+ .prompt-box {
145
+ position: fixed;
146
+ top: 20px;
147
+ right: 20px;
148
+ width: 300px;
149
+ background-color: rgba(245, 246, 250, 0.9);
150
+ padding: 20px;
151
+ border-radius: 10px;
152
+ z-index: 1000;
153
+ }
154
+
155
+ @keyframes snow {
156
+ 0% {
157
+ transform: translateY(0) translateX(0);
158
+ }
159
+ 100% {
160
+ transform: translateY(100vh) translateX(100px);
161
+ }
162
+ }
163
+
164
+ .snowflake {
165
+ position: fixed;
166
+ top: -10px;
167
+ color: white;
168
+ font-size: 20px;
169
+ animation: snow 5s linear infinite;
170
+ }
171
+ """
172
+
173
+ js_code = """
174
+ function createSnowflake() {
175
+ const snowflake = document.createElement('div');
176
+ snowflake.classList.add('snowflake');
177
+ snowflake.innerHTML = '❄';
178
+ snowflake.style.left = Math.random() * 100 + 'vw';
179
+ snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
180
+ snowflake.style.opacity = Math.random();
181
+ document.body.appendChild(snowflake);
182
+
183
+ setTimeout(() => {
184
+ snowflake.remove();
185
+ }, 5000);
186
+ }
187
+
188
+ setInterval(createSnowflake, 100);
189
  """
190
 
191
  with gr.Blocks(css=css) as app:
192
+ gr.HTML(f"<script>{js_code}</script>")
193
+
194
  with gr.Column(elem_classes="container"):
195
+ gr.Markdown("# πŸŽ„ X-MAS LoRA", elem_classes="header")
196
 
197
+ # ν”„λ‘¬ν”„νŠΈ μž…λ ₯ λ°•μŠ€λ₯Ό λ³„λ„λ‘œ 배치
198
+ with gr.Group(elem_classes="prompt-box"):
199
+ prompt = gr.TextArea(
200
+ label="✍️ Your Prompt (ν•œκΈ€ λ˜λŠ” μ˜μ–΄)",
201
+ placeholder="이미지λ₯Ό μ„€λͺ…ν•˜μ„Έμš”...",
202
+ lines=5
203
+ )
204
+ generate_button = gr.Button(
205
+ "πŸš€ Generate Image",
206
+ elem_classes="generate-btn"
207
+ )
208
+
209
+ # 이미지 좜λ ₯ μ˜μ—­
210
  with gr.Group(elem_classes="result-box"):
211
  gr.Markdown("### πŸ–ΌοΈ Generated Image")
212
  result = gr.Image(label="Result", elem_classes="image-output")
 
 
 
 
 
 
213
 
214
  # μ˜΅μ…˜λ“€μ„ μ•„μ½”λ””μ–ΈμœΌλ‘œ ꡬ성
215
+ with gr.Accordion("🎨 Advanced Options", open=False, elem_classes="accordion"):
 
 
 
 
 
 
 
216
  with gr.Group(elem_classes="parameter-box"):
217
  gr.Markdown("### πŸŽ›οΈ Generation Parameters")
218
  with gr.Row():
 
285
  )
286
 
287
  app.queue()
288
+ app.launch(js=js_code)