Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 {
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
"""
|
| 87 |
|
| 88 |
with gr.Blocks(css=css) as app:
|
|
|
|
|
|
|
| 89 |
with gr.Column(elem_classes="container"):
|
| 90 |
-
gr.Markdown("#
|
| 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("π¨
|
| 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)
|