Spaces:
Runtime error
Runtime error
File size: 8,093 Bytes
75b503f 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 8ab6152 7d81189 6c1f991 8ab6152 6c1f991 5f0a393 6c1f991 b2f236e 8ab6152 b2f236e 8ab6152 b2f236e 8ab6152 b2f236e 8ab6152 3fdbbb9 b2f236e 3fdbbb9 b2f236e 3fdbbb9 5f0a393 b2f236e 5f0a393 b2f236e 5f0a393 896c87c 343f950 b2f236e 896c87c b2f236e 896c87c b2f236e 5f0a393 896c87c b2f236e 5f0a393 b2f236e 8ab6152 3fdbbb9 8ab6152 6c1f991 8ab6152 5f0a393 b2f236e 8ab6152 b2f236e 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 8ab6152 6c1f991 90741b0 6c1f991 |
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 |
import spaces
import torch
from diffusers import FluxPipeline
import gradio as gr
import random
import numpy as np
import os
# GPU 사용 가능 여부 확인
if torch.cuda.is_available():
device = "cuda"
print("GPU를 사용합니다")
else:
device = "cpu"
print("CPU를 사용합니다")
# HuggingFace 토큰 로그인
HF_TOKEN = os.getenv("HF_TOKEN")
MAX_SEED = np.iinfo(np.int32).max
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
# 파이프라인 초기화 및 모델 다운로드
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
pipe.to(device)
# 이미지 생성 함수 정의
@spaces.GPU(duration=160)
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
if seed == 0:
seed = random.randint(1, MAX_SEED)
generator = torch.Generator().manual_seed(seed)
with torch.inference_mode():
output = pipe(
prompt=prompt,
num_inference_steps=num_inference_steps,
height=height,
width=width,
guidance_scale=guidance_scale,
generator=generator,
num_images_per_prompt=num_images_per_prompt
).images
return output
# 예제 프롬프트
examples = [
["A cat holding a sign that says hello world"],
["a tiny astronaut hatching from an egg on the moon"],
["An astronaut on mars in a futuristic cyborg suit"],
]
css = '''
.gradio-container {
max-width: 1400px !important;
margin: auto;
}
/* 이미지 크기 조정 */
.image-container img {
max-height: 600px !important;
}
/* 이미지 슬라이더 크기 조정 */
.image-slider {
height: 600px !important;
max-height: 600px !important;
}
h1 {
text-align: center;
font-family: 'Pretendard', sans-serif;
color: #EA580C;
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 1.5rem;
text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.subtitle {
text-align: center;
color: #4B5563;
font-size: 1.1rem;
margin-bottom: 2rem;
font-family: 'Pretendard', sans-serif;
}
.gr-button-primary {
background-color: #F97316 !important;
border: none !important;
box-shadow: 0 2px 4px rgba(234, 88, 12, 0.2) !important;
}
.gr-button-primary:hover {
background-color: #EA580C !important;
transform: translateY(-1px);
box-shadow: 0 4px 6px rgba(234, 88, 12, 0.25) !important;
}
.footer-content {
text-align: center;
margin-top: 3rem;
padding: 2rem;
background: linear-gradient(to bottom, #FFF7ED, white);
border-radius: 12px;
font-family: 'Pretendard', sans-serif;
}
.footer-content a {
color: #EA580C;
text-decoration: none;
font-weight: 500;
transition: all 0.2s;
}
.footer-content a:hover {
color: #C2410C;
}
.visit-button {
background-color: #EA580C;
color: white !important;
padding: 12px 24px;
border-radius: 8px;
font-weight: 600;
text-decoration: none;
display: inline-block;
transition: all 0.3s;
margin-top: 1rem;
box-shadow: 0 2px 4px rgba(234, 88, 12, 0.2);
font-size: 1.1rem;
}
.visit-button:hover {
background-color: #C2410C;
transform: translateY(-2px);
box-shadow: 0 4px 6px rgba(234, 88, 12, 0.25);
color: white !important;
}
.container-wrapper {
background: white;
border-radius: 16px;
padding: 2rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}
.image-container {
border-radius: 12px;
overflow: hidden;
border: 2px solid #F3F4F6;
}
'''
# Gradio 인터페이스 생성
with gr.Blocks(
theme=gr.themes.Soft(
primary_hue=gr.themes.Color(
c50="#FFF7ED",
c100="#FFEDD5",
c200="#FED7AA",
c300="#FDBA74",
c400="#FB923C",
c500="#F97316",
c600="#EA580C",
c700="#C2410C",
c800="#9A3412",
c900="#7C2D12",
c950="#431407",
),
secondary_hue="zinc",
neutral_hue="zinc",
font=("Pretendard", "sans-serif")
),
css=css
) as demo:
with gr.Row():
with gr.Column():
gr.HTML(
"""
<h1>끝장AI FLUX.1 이미지 생성기</h1>
<div class="subtitle">
강력한 AI 기술로 당신의 상상을 현실로 만들어보세요
</div>
"""
)
with gr.Group(elem_classes="container-wrapper"):
with gr.Column():
prompt = gr.Textbox(
label="프롬프트",
info="원하는 이미지를 설명해주세요",
placeholder="고양이..."
)
run_button = gr.Button("생성하기", variant="primary")
result = gr.Gallery(
label="생성된 AI 이미지",
elem_id="gallery"
)
with gr.Accordion("고급 설정", open=False):
with gr.Row():
num_inference_steps = gr.Slider(
label="추론 단계 수",
info="이미지의 디노이징 단계 수입니다. 더 많은 단계는 더 높은 품질의 이미지를 생성하지만 시간이 더 걸립니다",
minimum=1,
maximum=50,
value=25,
step=1
)
guidance_scale = gr.Slider(
label="가이던스 스케일",
info="텍스트 프롬프트를 얼마나 충실히 따를지 제어합니다. 높은 값은 입력 텍스트에 더 가깝게 생성됩니다",
minimum=0.0,
maximum=7.0,
value=3.5,
step=0.1
)
with gr.Row():
width = gr.Slider(
label="너비",
info="이미지의 너비",
minimum=256,
maximum=1024,
step=32,
value=1024
)
height = gr.Slider(
label="높이",
info="이미지의 높이",
minimum=256,
maximum=1024,
step=32,
value=1024
)
with gr.Row():
seed = gr.Slider(
value=42,
minimum=0,
maximum=MAX_SEED,
step=1,
label="시드",
info="생성 과정의 시작점입니다. 0을 입력하면 랜덤한 시드가 사용됩니다"
)
num_images_per_prompt = gr.Slider(
label="프롬프트당 이미지 수",
info="설정된 값으로 생성할 이미지의 수",
minimum=1,
maximum=4,
step=1,
value=2
)
gr.Examples(
examples=examples,
fn=generate_image,
inputs=[prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt],
outputs=[result],
cache_examples=CACHE_EXAMPLES
)
gr.on(
triggers=[
prompt.submit,
run_button.click,
],
fn=generate_image,
inputs=[prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt],
outputs=[result],
)
# Footer at the bottom
gr.HTML(
"""
<div class='footer-content'>
<p style='font-size: 1.1rem; font-weight: 500; color: #1F2937;'>끝장AI가 제공하는 고급 AI 도구를 더 경험하고 싶으신가요?</p>
<a href='https://finalendai.com' target='_blank' class='visit-button' style='color: white !important;'>
끝장AI 방문하기
</a>
<p style='margin-top: 1.5rem; color: #6B7280; font-size: 0.9rem;'>
© 2024 끝장AI. All rights reserved.
</p>
</div>
"""
)
demo.queue().launch(share=False) |