Spaces:
Running
Running
File size: 9,164 Bytes
69620c8 6960db5 54d0511 31c0b50 6960db5 8c89a89 69620c8 8c89a89 69620c8 8c89a89 c1bd24e 69620c8 8c89a89 c401dbb 8c89a89 6960db5 8c89a89 69620c8 8c89a89 69620c8 4f076f3 69620c8 6960db5 69620c8 4f076f3 69620c8 ab309a4 c0fd987 26c3a03 8c89a89 f207d6b c0fd987 f207d6b c0fd987 8c89a89 c0fd987 8c89a89 f207d6b c0fd987 8c89a89 c0fd987 8c89a89 c0fd987 f207d6b c0fd987 8c89a89 f207d6b 26c3a03 c0fd987 26c3a03 f207d6b c0fd987 f207d6b c0fd987 f207d6b c0fd987 26c3a03 c0fd987 26c3a03 c0fd987 8c89a89 c0fd987 8c89a89 c0fd987 8c89a89 c0fd987 8c89a89 c0fd987 8c89a89 c0fd987 f207d6b c0fd987 f207d6b c0fd987 8c89a89 c0fd987 8c89a89 63f9491 26c3a03 8c89a89 c0fd987 63f9491 c0fd987 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de d32c1fa 2cb92de 8c89a89 2cb92de f207d6b 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de 8c89a89 2cb92de c0fd987 69620c8 8c89a89 69620c8 63f9491 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
import spaces
import gradio as gr
import torch
from PIL import Image
from diffusers import DiffusionPipeline
import random
from transformers import pipeline
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.backends.cuda.matmul.allow_tf32 = True
# ๋ฒ์ญ ๋ชจ๋ธ ์ด๊ธฐํ
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
# ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ฐ LoRA ์ค์
base_model = "black-forest-labs/FLUX.1-dev"
model_lora_repo = "Motas/Flux_Fashion_Photography_Style" # ํจ์
๋ชจ๋ธ LoRA
clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA" # ์๋ฅ LoRA
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
pipe.to("cuda")
MAX_SEED = 2**32-1
# ์์ ์ค์
example_model_prompts = [
"professional fashion model, full body shot, standing pose, natural lighting, studio background, high fashion, elegant pose",
"fashion model portrait, upper body, confident pose, fashion photography, neutral background, professional lighting",
"stylish fashion model, three-quarter view, editorial pose, high-end fashion magazine style, minimal background"
]
example_clothes_prompts = [
"luxury designer sweater, cashmere material, cream color, cable knit pattern, high-end fashion, product photography",
"elegant business blazer, tailored fit, charcoal grey, premium wool fabric, professional wear",
"modern streetwear hoodie, oversized fit, minimalist design, premium cotton, urban style"
]
@spaces.GPU()
def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
# ํ๊ธ ๊ฐ์ง ๋ฐ ๋ฒ์ญ
def contains_korean(text):
return any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text)
if contains_korean(prompt):
translated = translator(prompt)[0]['translation_text']
actual_prompt = translated
else:
actual_prompt = prompt
# ๋ชจ๋์ ๋ฐ๋ฅธ LoRA ๋ฐ ํธ๋ฆฌ๊ฑฐ์๋ ์ค์
if mode == "Generate Model":
pipe.load_lora_weights(model_lora_repo)
trigger_word = "fashion photography, professional model"
else:
pipe.load_lora_weights(clothes_lora_repo)
trigger_word = "upper clothing, fashion item"
if randomize_seed:
seed = random.randint(0, MAX_SEED)
generator = torch.Generator(device="cuda").manual_seed(seed)
progress(0, "Starting fashion generation...")
for i in range(1, steps + 1):
if i % (steps // 10) == 0:
progress(i / steps * 100, f"Processing step {i} of {steps}...")
image = pipe(
prompt=f"{actual_prompt} {trigger_word}",
num_inference_steps=steps,
guidance_scale=cfg_scale,
width=width,
height=height,
generator=generator,
joint_attention_kwargs={"scale": lora_scale},
).images[0]
progress(100, "Completed!")
return image, seed
# CSS ์ ์
custom_css = """
body {
background-color: #f5f5f5;
font-family: 'Arial', sans-serif;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
color: #333;
margin-bottom: 30px;
font-size: 2.5em;
text-transform: uppercase;
letter-spacing: 2px;
}
.box-common {
background-color: white;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.mode-box {
background-color: #fff;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
border: 2px solid #eee;
}
.result-box {
width: 90%;
max-width: 1000px;
margin: 20px auto;
}
.image-output {
width: 100%;
max-width: 800px;
margin: 0 auto;
display: block;
}
.prompt-box {
width: 90%;
max-width: 1000px;
margin: 20px auto;
}
.generate-btn {
background: linear-gradient(45deg, #ff6b6b, #ff8e8e) !important;
color: white !important;
padding: 15px 30px !important;
border-radius: 8px !important;
border: none !important;
font-size: 1.1em !important;
cursor: pointer !important;
transition: all 0.3s ease !important;
width: 250px !important;
margin: 20px auto !important;
display: block !important;
text-transform: uppercase !important;
letter-spacing: 1px !important;
}
.generate-btn:hover {
background: linear-gradient(45deg, #ff8e8e, #ff6b6b) !important;
transform: translateY(-2px) !important;
box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4) !important;
}
.accordion {
width: 90%;
max-width: 1000px;
margin: 20px auto;
}
.examples-table {
background-color: rgba(255, 255, 255, 0.95);
border-radius: 8px;
padding: 15px;
margin-top: 20px;
}
.parameter-box {
background-color: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin: 10px 0;
}
"""
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
with gr.Blocks(css=custom_css, theme="Yntec/HaleyCH_Theme_Orange") as app:
with gr.Column(elem_classes="container"):
gr.Markdown("# ๐ญ Fashion Generation Studio", elem_classes="header")
# ๋ชจ๋ ์ ํ
with gr.Group(elem_classes="mode-box box-common"):
mode = gr.Radio(
choices=["Generate Model", "Generate Clothes"],
label="Generation Mode",
value="Generate Model"
)
# ์ด๋ฏธ์ง ์ถ๋ ฅ ์์ญ
with gr.Group(elem_classes="result-box box-common"):
gr.Markdown("### ๐ผ๏ธ Generated Fashion")
result = gr.Image(label="Result", elem_classes="image-output")
# ํ๋กฌํํธ ์
๋ ฅ ์์ญ
with gr.Group(elem_classes="prompt-box box-common"):
prompt = gr.TextArea(
label="โ๏ธ Fashion Description (ํ๊ธ ๋๋ ์์ด)",
placeholder="ํจ์
๋ชจ๋ธ์ด๋ ์๋ฅ๋ฅผ ์ค๋ช
ํ์ธ์...",
lines=5
)
generate_button = gr.Button(
"๐ Generate Fashion",
elem_classes="generate-btn"
)
# ์์ ํญ
with gr.Tabs():
with gr.TabItem("Model Examples"):
gr.Examples(
examples=example_model_prompts,
inputs=prompt,
label="Model Prompts"
)
with gr.TabItem("Clothes Examples"):
gr.Examples(
examples=example_clothes_prompts,
inputs=prompt,
label="Clothes Prompts"
)
# ๊ณ ๊ธ ์ต์
with gr.Accordion("๐จ Advanced Options", open=False, elem_classes="accordion box-common"):
with gr.Group(elem_classes="parameter-box"):
gr.Markdown("### ๐๏ธ Generation Parameters")
with gr.Row():
with gr.Column():
cfg_scale = gr.Slider(
label="CFG Scale",
minimum=1,
maximum=20,
step=0.5,
value=7.0
)
steps = gr.Slider(
label="Steps",
minimum=1,
maximum=100,
step=1,
value=30
)
lora_scale = gr.Slider(
label="LoRA Scale",
minimum=0,
maximum=1,
step=0.01,
value=0.85
)
with gr.Group(elem_classes="parameter-box"):
gr.Markdown("### ๐ Image Dimensions")
with gr.Row():
width = gr.Slider(
label="Width",
minimum=256,
maximum=1536,
step=64,
value=512
)
height = gr.Slider(
label="Height",
minimum=256,
maximum=1536,
step=64,
value=768
)
with gr.Group(elem_classes="parameter-box"):
gr.Markdown("### ๐ฒ Seed Settings")
with gr.Row():
randomize_seed = gr.Checkbox(
True,
label="Randomize seed"
)
seed = gr.Slider(
label="Seed",
minimum=0,
maximum=MAX_SEED,
step=1,
value=42
)
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
generate_button.click(
generate_fashion,
inputs=[prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale],
outputs=[result, seed]
)
app.queue()
app.launch() |