Spaces:
Running
on
Zero
Running
on
Zero
Delete app-backup.py
Browse files- app-backup.py +0 -377
app-backup.py
DELETED
@@ -1,377 +0,0 @@
|
|
1 |
-
import spaces
|
2 |
-
import gradio as gr
|
3 |
-
import torch
|
4 |
-
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
|
11 |
-
torch.backends.cuda.matmul.allow_tf32 = True
|
12 |
-
|
13 |
-
# ๋ฒ์ญ ๋ชจ๋ธ ์ด๊ธฐํ
|
14 |
-
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
15 |
-
|
16 |
-
base_model = "black-forest-labs/FLUX.1-dev"
|
17 |
-
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
18 |
-
|
19 |
-
lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA"
|
20 |
-
trigger_word = ""
|
21 |
-
pipe.load_lora_weights(lora_repo)
|
22 |
-
|
23 |
-
pipe.to("cuda")
|
24 |
-
|
25 |
-
MAX_SEED = 2**32-1
|
26 |
-
|
27 |
-
@spaces.GPU()
|
28 |
-
def translate_and_generate(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
29 |
-
# ํ๊ธ ๊ฐ์ง ๋ฐ ๋ฒ์ญ
|
30 |
-
def contains_korean(text):
|
31 |
-
return any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text)
|
32 |
-
|
33 |
-
if contains_korean(prompt):
|
34 |
-
# ํ๊ธ์ ์์ด๋ก ๋ฒ์ญ
|
35 |
-
translated = translator(prompt)[0]['translation_text']
|
36 |
-
actual_prompt = translated
|
37 |
-
else:
|
38 |
-
actual_prompt = prompt
|
39 |
-
|
40 |
-
if randomize_seed:
|
41 |
-
seed = random.randint(0, MAX_SEED)
|
42 |
-
generator = torch.Generator(device="cuda").manual_seed(seed)
|
43 |
-
|
44 |
-
progress(0, "Starting image generation...")
|
45 |
-
|
46 |
-
for i in range(1, steps + 1):
|
47 |
-
if i % (steps // 10) == 0:
|
48 |
-
progress(i / steps * 100, f"Processing step {i} of {steps}...")
|
49 |
-
|
50 |
-
image = pipe(
|
51 |
-
prompt=f"{actual_prompt} {trigger_word}",
|
52 |
-
num_inference_steps=steps,
|
53 |
-
guidance_scale=cfg_scale,
|
54 |
-
width=width,
|
55 |
-
height=height,
|
56 |
-
generator=generator,
|
57 |
-
joint_attention_kwargs={"scale": lora_scale},
|
58 |
-
).images[0]
|
59 |
-
|
60 |
-
progress(100, "Completed!")
|
61 |
-
return image, seed
|
62 |
-
|
63 |
-
example_image_path = "example0.webp"
|
64 |
-
example_prompt = """Cozy winter scene with a Christmas atmosphere: a snow-covered cabin in the forest, warm light glowing from the windows, surrounded by sparkling Christmas decorations and a beautifully adorned Christmas tree. The sky is filled with stars, and soft snowflakes are gently falling, creating a serene and warm ambiance"""
|
65 |
-
example_cfg_scale = 3.2
|
66 |
-
example_steps = 32
|
67 |
-
example_width = 1152
|
68 |
-
example_height = 896
|
69 |
-
example_seed = 3981632454
|
70 |
-
example_lora_scale = 0.85
|
71 |
-
|
72 |
-
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 |
-
custom_css = """
|
79 |
-
/* ๊ธฐ๋ณธ ์คํ์ผ */
|
80 |
-
body {
|
81 |
-
margin: 0;
|
82 |
-
padding: 0;
|
83 |
-
background: url('file/example0.webp') no-repeat center center fixed;
|
84 |
-
background-size: cover;
|
85 |
-
min-height: 100vh;
|
86 |
-
}
|
87 |
-
|
88 |
-
/* ์ปจํ
์ด๋ */
|
89 |
-
.container {
|
90 |
-
max-width: 1200px;
|
91 |
-
margin: 0 auto;
|
92 |
-
padding: 20px;
|
93 |
-
box-sizing: border-box;
|
94 |
-
}
|
95 |
-
|
96 |
-
/* ํค๋ */
|
97 |
-
.header {
|
98 |
-
text-align: center;
|
99 |
-
color: white;
|
100 |
-
text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
|
101 |
-
margin-bottom: 30px;
|
102 |
-
font-size: 2.5em;
|
103 |
-
}
|
104 |
-
|
105 |
-
/* ๋ฐ์ค ๊ณตํต ์คํ์ผ */
|
106 |
-
.box-common {
|
107 |
-
background-color: rgba(255, 255, 255, 0.85);
|
108 |
-
backdrop-filter: blur(10px);
|
109 |
-
border-radius: 15px;
|
110 |
-
padding: 20px;
|
111 |
-
margin: 20px 0;
|
112 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
113 |
-
}
|
114 |
-
|
115 |
-
/* ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ๋ฐ์ค */
|
116 |
-
.result-box {
|
117 |
-
width: 90%;
|
118 |
-
max-width: 1000px;
|
119 |
-
margin: 20px auto;
|
120 |
-
}
|
121 |
-
|
122 |
-
.image-output {
|
123 |
-
width: 100%;
|
124 |
-
max-width: 800px;
|
125 |
-
margin: 0 auto;
|
126 |
-
display: block;
|
127 |
-
}
|
128 |
-
|
129 |
-
/* ํ๋กฌํํธ ์
๋ ฅ ๋ฐ์ค */
|
130 |
-
.prompt-box {
|
131 |
-
width: 90%;
|
132 |
-
max-width: 1000px;
|
133 |
-
margin: 20px auto;
|
134 |
-
}
|
135 |
-
|
136 |
-
/* ๋ฒํผ ์คํ์ผ */
|
137 |
-
.generate-btn {
|
138 |
-
background-color: #2ecc71 !important;
|
139 |
-
color: white !important;
|
140 |
-
padding: 12px 30px !important;
|
141 |
-
border-radius: 8px !important;
|
142 |
-
border: none !important;
|
143 |
-
font-size: 1.1em !important;
|
144 |
-
cursor: pointer !important;
|
145 |
-
transition: background-color 0.3s ease !important;
|
146 |
-
width: 200px !important;
|
147 |
-
margin: 20px auto !important;
|
148 |
-
display: block !important;
|
149 |
-
}
|
150 |
-
|
151 |
-
.generate-btn:hover {
|
152 |
-
background-color: #27ae60 !important;
|
153 |
-
}
|
154 |
-
|
155 |
-
/* ์์ฝ๋์ธ ์คํ์ผ */
|
156 |
-
.accordion {
|
157 |
-
width: 90%;
|
158 |
-
max-width: 1000px;
|
159 |
-
margin: 20px auto;
|
160 |
-
}
|
161 |
-
|
162 |
-
/* ์ค๋์ค ์ปจํธ๋กค */
|
163 |
-
.audio-controls {
|
164 |
-
position: fixed;
|
165 |
-
bottom: 20px;
|
166 |
-
right: 20px;
|
167 |
-
z-index: 1000;
|
168 |
-
display: flex;
|
169 |
-
gap: 10px;
|
170 |
-
background-color: rgba(255, 255, 255, 0.9);
|
171 |
-
padding: 15px;
|
172 |
-
border-radius: 10px;
|
173 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
174 |
-
}
|
175 |
-
|
176 |
-
.audio-btn {
|
177 |
-
background-color: #3498db;
|
178 |
-
color: white;
|
179 |
-
border: none;
|
180 |
-
padding: 8px 15px;
|
181 |
-
border-radius: 5px;
|
182 |
-
cursor: pointer;
|
183 |
-
transition: background-color 0.3s ease;
|
184 |
-
}
|
185 |
-
|
186 |
-
.audio-btn:hover {
|
187 |
-
background-color: #2980b9;
|
188 |
-
}
|
189 |
-
|
190 |
-
/* ๋ ๋ด๋ฆฌ๋ ํจ๊ณผ */
|
191 |
-
@keyframes snowfall {
|
192 |
-
0% {
|
193 |
-
transform: translateY(-10vh) translateX(0);
|
194 |
-
opacity: 1;
|
195 |
-
}
|
196 |
-
100% {
|
197 |
-
transform: translateY(100vh) translateX(100px);
|
198 |
-
opacity: 0.3;
|
199 |
-
}
|
200 |
-
}
|
201 |
-
|
202 |
-
.snowflake {
|
203 |
-
position: fixed;
|
204 |
-
color: white;
|
205 |
-
font-size: 1.5em;
|
206 |
-
user-select: none;
|
207 |
-
z-index: 1000;
|
208 |
-
pointer-events: none;
|
209 |
-
animation: snowfall linear infinite;
|
210 |
-
}
|
211 |
-
"""
|
212 |
-
|
213 |
-
# JavaScript ์ฝ๋
|
214 |
-
snow_js = """
|
215 |
-
function createSnowflake() {
|
216 |
-
const snowflake = document.createElement('div');
|
217 |
-
snowflake.innerHTML = 'โ';
|
218 |
-
snowflake.className = 'snowflake';
|
219 |
-
snowflake.style.left = Math.random() * 100 + 'vw';
|
220 |
-
snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
|
221 |
-
snowflake.style.opacity = Math.random();
|
222 |
-
document.body.appendChild(snowflake);
|
223 |
-
|
224 |
-
setTimeout(() => {
|
225 |
-
snowflake.remove();
|
226 |
-
}, 5000);
|
227 |
-
}
|
228 |
-
|
229 |
-
setInterval(createSnowflake, 200);
|
230 |
-
"""
|
231 |
-
|
232 |
-
audio_js = """
|
233 |
-
let currentlyPlaying = null;
|
234 |
-
|
235 |
-
function toggleAudio(num) {
|
236 |
-
const audio = document.getElementById('bgMusic' + num);
|
237 |
-
const otherAudio = document.getElementById('bgMusic' + (num === 1 ? 2 : 1));
|
238 |
-
|
239 |
-
if (currentlyPlaying === audio) {
|
240 |
-
audio.pause();
|
241 |
-
currentlyPlaying = null;
|
242 |
-
} else {
|
243 |
-
if (currentlyPlaying) {
|
244 |
-
currentlyPlaying.pause();
|
245 |
-
}
|
246 |
-
otherAudio.pause();
|
247 |
-
audio.play();
|
248 |
-
currentlyPlaying = audio;
|
249 |
-
}
|
250 |
-
}
|
251 |
-
|
252 |
-
function stopAllAudio() {
|
253 |
-
const audios = document.querySelectorAll('audio');
|
254 |
-
audios.forEach(audio => audio.pause());
|
255 |
-
currentlyPlaying = null;
|
256 |
-
}
|
257 |
-
"""
|
258 |
-
|
259 |
-
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
260 |
-
app = gr.Blocks(css=custom_css,theme="Yntec/HaleyCH_Theme_Orange")
|
261 |
-
|
262 |
-
with app:
|
263 |
-
# JavaScript ์ด๊ธฐํ
|
264 |
-
gr.HTML(f"<script>{snow_js}</script>")
|
265 |
-
|
266 |
-
with gr.Column(elem_classes="container"):
|
267 |
-
gr.Markdown("# ๐ X-MAS LoRA", elem_classes="header")
|
268 |
-
|
269 |
-
# ์ด๋ฏธ์ง ์ถ๋ ฅ ์์ญ
|
270 |
-
with gr.Group(elem_classes="result-box box-common"):
|
271 |
-
gr.Markdown("### ๐ผ๏ธ Generated Image")
|
272 |
-
result = gr.Image(label="Result", elem_classes="image-output")
|
273 |
-
|
274 |
-
# ํ๋กฌํํธ ์
๋ ฅ ์์ญ
|
275 |
-
with gr.Group(elem_classes="prompt-box box-common"):
|
276 |
-
prompt = gr.TextArea(
|
277 |
-
label="โ๏ธ Your Prompt (ํ๊ธ ๋๋ ์์ด)",
|
278 |
-
placeholder="์ด๋ฏธ์ง๋ฅผ ์ค๋ช
ํ์ธ์...",
|
279 |
-
lines=5
|
280 |
-
)
|
281 |
-
generate_button = gr.Button(
|
282 |
-
"๐ Generate Image",
|
283 |
-
elem_classes="generate-btn"
|
284 |
-
)
|
285 |
-
|
286 |
-
# ๊ณ ๊ธ ์ต์
|
287 |
-
with gr.Accordion("๐จ Advanced Options", open=False, elem_classes="accordion box-common"):
|
288 |
-
with gr.Group(elem_classes="parameter-box"):
|
289 |
-
gr.Markdown("### ๐๏ธ Generation Parameters")
|
290 |
-
with gr.Row():
|
291 |
-
with gr.Column():
|
292 |
-
cfg_scale = gr.Slider(
|
293 |
-
label="CFG Scale",
|
294 |
-
minimum=1,
|
295 |
-
maximum=20,
|
296 |
-
step=0.5,
|
297 |
-
value=example_cfg_scale
|
298 |
-
)
|
299 |
-
steps = gr.Slider(
|
300 |
-
label="Steps",
|
301 |
-
minimum=1,
|
302 |
-
maximum=100,
|
303 |
-
step=1,
|
304 |
-
value=example_steps
|
305 |
-
)
|
306 |
-
lora_scale = gr.Slider(
|
307 |
-
label="LoRA Scale",
|
308 |
-
minimum=0,
|
309 |
-
maximum=1,
|
310 |
-
step=0.01,
|
311 |
-
value=example_lora_scale
|
312 |
-
)
|
313 |
-
|
314 |
-
with gr.Group(elem_classes="parameter-box"):
|
315 |
-
gr.Markdown("### ๐ Image Dimensions")
|
316 |
-
with gr.Row():
|
317 |
-
width = gr.Slider(
|
318 |
-
label="Width",
|
319 |
-
minimum=256,
|
320 |
-
maximum=1536,
|
321 |
-
step=64,
|
322 |
-
value=example_width
|
323 |
-
)
|
324 |
-
height = gr.Slider(
|
325 |
-
label="Height",
|
326 |
-
minimum=256,
|
327 |
-
maximum=1536,
|
328 |
-
step=64,
|
329 |
-
value=example_height
|
330 |
-
)
|
331 |
-
|
332 |
-
with gr.Group(elem_classes="parameter-box"):
|
333 |
-
gr.Markdown("### ๐ฒ Seed Settings")
|
334 |
-
with gr.Row():
|
335 |
-
randomize_seed = gr.Checkbox(
|
336 |
-
True,
|
337 |
-
label="Randomize seed"
|
338 |
-
)
|
339 |
-
seed = gr.Slider(
|
340 |
-
label="Seed",
|
341 |
-
minimum=0,
|
342 |
-
maximum=MAX_SEED,
|
343 |
-
step=1,
|
344 |
-
value=example_seed
|
345 |
-
)
|
346 |
-
|
347 |
-
# ์ค๋์ค ์ปจํธ๋กค
|
348 |
-
gr.HTML(f"""
|
349 |
-
<div class="audio-controls">
|
350 |
-
<button class="audio-btn" onclick="toggleAudio(1)">๐ต Music 1</button>
|
351 |
-
<button class="audio-btn" onclick="toggleAudio(2)">๐ต Music 2</button>
|
352 |
-
<button class="audio-btn" onclick="stopAllAudio()">โน Stop</button>
|
353 |
-
</div>
|
354 |
-
<audio id="bgMusic1" loop>
|
355 |
-
<source src="file/1.mp3" type="audio/mp3">
|
356 |
-
</audio>
|
357 |
-
<audio id="bgMusic2" loop>
|
358 |
-
<source src="file/2.mp3" type="audio/mp3">
|
359 |
-
</audio>
|
360 |
-
<script>{audio_js}</script>
|
361 |
-
""")
|
362 |
-
|
363 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
364 |
-
app.load(
|
365 |
-
load_example,
|
366 |
-
inputs=[],
|
367 |
-
outputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, result]
|
368 |
-
)
|
369 |
-
|
370 |
-
generate_button.click(
|
371 |
-
translate_and_generate,
|
372 |
-
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale],
|
373 |
-
outputs=[result, seed]
|
374 |
-
)
|
375 |
-
|
376 |
-
app.queue()
|
377 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|