Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import random
|
|
| 6 |
import numpy as np
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
# GPU 사용 가능 여부 확인
|
| 10 |
if torch.cuda.is_available():
|
| 11 |
device = "cuda"
|
| 12 |
print("GPU를 사용합니다")
|
|
@@ -14,20 +13,15 @@ else:
|
|
| 14 |
device = "cpu"
|
| 15 |
print("CPU를 사용합니다")
|
| 16 |
|
| 17 |
-
# HuggingFace 토큰 로그인
|
| 18 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 19 |
-
|
| 20 |
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
| 22 |
|
| 23 |
-
# 파이프라인 초기화 및 모델 다운로드
|
| 24 |
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 25 |
pipe.to(device)
|
| 26 |
|
| 27 |
-
# 이미지 생성 함수 정의
|
| 28 |
@spaces.GPU(duration=160)
|
| 29 |
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
|
| 30 |
-
# 시드가 0이거나 None이면 랜덤 시드 사용
|
| 31 |
if seed is None or seed == 0:
|
| 32 |
seed = random.randint(1, MAX_SEED)
|
| 33 |
|
|
@@ -46,31 +40,27 @@ def generate_image(prompt, num_inference_steps, height, width, guidance_scale, s
|
|
| 46 |
|
| 47 |
return output
|
| 48 |
|
| 49 |
-
# 랜덤 시드 생성 함수
|
| 50 |
def random_seed():
|
| 51 |
return random.randint(1, MAX_SEED)
|
| 52 |
|
| 53 |
def create_random_seed():
|
| 54 |
new_seed = random_seed()
|
| 55 |
-
return [gr.Number.update(value=new_seed), f
|
| 56 |
|
| 57 |
-
# 예제 프롬프트
|
| 58 |
examples = [
|
| 59 |
["A cat holding a sign that says hello world"],
|
| 60 |
["a tiny astronaut hatching from an egg on the moon"],
|
| 61 |
["An astronaut on mars in a futuristic cyborg suit"],
|
| 62 |
]
|
| 63 |
|
| 64 |
-
css =
|
| 65 |
.gradio-container {
|
| 66 |
max-width: 1400px !important;
|
| 67 |
margin: auto;
|
| 68 |
}
|
| 69 |
-
/* 이미지 크기 조정 */
|
| 70 |
.image-container img {
|
| 71 |
max-height: 600px !important;
|
| 72 |
}
|
| 73 |
-
/* 이미지 슬라이더 크기 조정 */
|
| 74 |
.image-slider {
|
| 75 |
height: 600px !important;
|
| 76 |
max-height: 600px !important;
|
|
@@ -148,20 +138,31 @@ h1 {
|
|
| 148 |
overflow: hidden;
|
| 149 |
border: 2px solid #F3F4F6;
|
| 150 |
}
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
}
|
| 157 |
-
|
|
|
|
| 158 |
transform: translateY(-1px);
|
| 159 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
}
|
| 161 |
-
"""
|
| 162 |
"""
|
| 163 |
|
| 164 |
-
# Gradio 인터페이스 생성
|
| 165 |
with gr.Blocks(
|
| 166 |
theme=gr.themes.Soft(
|
| 167 |
primary_hue=gr.themes.Color(
|
|
@@ -202,10 +203,11 @@ with gr.Blocks(
|
|
| 202 |
placeholder="고양이..."
|
| 203 |
)
|
| 204 |
run_button = gr.Button("생성하기", variant="primary")
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
| 209 |
|
| 210 |
with gr.Accordion("고급 설정", open=False):
|
| 211 |
with gr.Row():
|
|
@@ -266,10 +268,10 @@ with gr.Blocks(
|
|
| 266 |
minimum=0,
|
| 267 |
maximum=MAX_SEED,
|
| 268 |
step=1,
|
| 269 |
-
visible=False
|
| 270 |
)
|
| 271 |
-
seed_button = gr.Button(
|
| 272 |
-
seed_text = gr.Markdown(
|
| 273 |
|
| 274 |
num_images_per_prompt = gr.Slider(
|
| 275 |
label="프롬프트당 이미지 수",
|
|
@@ -303,15 +305,14 @@ with gr.Blocks(
|
|
| 303 |
outputs=[result],
|
| 304 |
)
|
| 305 |
|
| 306 |
-
# Footer at the bottom
|
| 307 |
gr.HTML(
|
| 308 |
"""
|
| 309 |
-
<div class=
|
| 310 |
-
<p style=
|
| 311 |
-
<a href=
|
| 312 |
끝장AI 방문하기
|
| 313 |
</a>
|
| 314 |
-
<p style=
|
| 315 |
© 2024 끝장AI. All rights reserved.
|
| 316 |
</p>
|
| 317 |
</div>
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import os
|
| 8 |
|
|
|
|
| 9 |
if torch.cuda.is_available():
|
| 10 |
device = "cuda"
|
| 11 |
print("GPU를 사용합니다")
|
|
|
|
| 13 |
device = "cpu"
|
| 14 |
print("CPU를 사용합니다")
|
| 15 |
|
|
|
|
| 16 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
| 17 |
MAX_SEED = np.iinfo(np.int32).max
|
| 18 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
| 19 |
|
|
|
|
| 20 |
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 21 |
pipe.to(device)
|
| 22 |
|
|
|
|
| 23 |
@spaces.GPU(duration=160)
|
| 24 |
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 25 |
if seed is None or seed == 0:
|
| 26 |
seed = random.randint(1, MAX_SEED)
|
| 27 |
|
|
|
|
| 40 |
|
| 41 |
return output
|
| 42 |
|
|
|
|
| 43 |
def random_seed():
|
| 44 |
return random.randint(1, MAX_SEED)
|
| 45 |
|
| 46 |
def create_random_seed():
|
| 47 |
new_seed = random_seed()
|
| 48 |
+
return [gr.Number.update(value=new_seed), f"현재 시드: {new_seed}"]
|
| 49 |
|
|
|
|
| 50 |
examples = [
|
| 51 |
["A cat holding a sign that says hello world"],
|
| 52 |
["a tiny astronaut hatching from an egg on the moon"],
|
| 53 |
["An astronaut on mars in a futuristic cyborg suit"],
|
| 54 |
]
|
| 55 |
|
| 56 |
+
css = """
|
| 57 |
.gradio-container {
|
| 58 |
max-width: 1400px !important;
|
| 59 |
margin: auto;
|
| 60 |
}
|
|
|
|
| 61 |
.image-container img {
|
| 62 |
max-height: 600px !important;
|
| 63 |
}
|
|
|
|
| 64 |
.image-slider {
|
| 65 |
height: 600px !important;
|
| 66 |
max-height: 600px !important;
|
|
|
|
| 138 |
overflow: hidden;
|
| 139 |
border: 2px solid #F3F4F6;
|
| 140 |
}
|
| 141 |
+
.seed-button {
|
| 142 |
+
background-color: #F3F4F6 !important;
|
| 143 |
+
color: #374151 !important;
|
| 144 |
+
border: 1px solid #E5E7EB !important;
|
| 145 |
+
border-radius: 8px !important;
|
| 146 |
+
padding: 8px 16px !important;
|
| 147 |
+
font-size: 0.9rem !important;
|
| 148 |
+
font-weight: 500 !important;
|
| 149 |
+
transition: all 0.2s ease-in-out !important;
|
| 150 |
}
|
| 151 |
+
.seed-button:hover {
|
| 152 |
+
background-color: #E5E7EB !important;
|
| 153 |
transform: translateY(-1px);
|
| 154 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
| 155 |
+
}
|
| 156 |
+
.seed-text {
|
| 157 |
+
font-family: 'Pretendard', sans-serif;
|
| 158 |
+
color: #4B5563;
|
| 159 |
+
font-size: 0.9rem;
|
| 160 |
+
margin: 0;
|
| 161 |
+
line-height: 2.5;
|
| 162 |
+
font-weight: 500;
|
| 163 |
}
|
|
|
|
| 164 |
"""
|
| 165 |
|
|
|
|
| 166 |
with gr.Blocks(
|
| 167 |
theme=gr.themes.Soft(
|
| 168 |
primary_hue=gr.themes.Color(
|
|
|
|
| 203 |
placeholder="고양이..."
|
| 204 |
)
|
| 205 |
run_button = gr.Button("생성하기", variant="primary")
|
| 206 |
+
result = gr.Gallery(
|
| 207 |
+
label="생성된 AI 이미지",
|
| 208 |
+
elem_id="gallery",
|
| 209 |
+
elem_classes="image-container"
|
| 210 |
+
)
|
| 211 |
|
| 212 |
with gr.Accordion("고급 설정", open=False):
|
| 213 |
with gr.Row():
|
|
|
|
| 268 |
minimum=0,
|
| 269 |
maximum=MAX_SEED,
|
| 270 |
step=1,
|
| 271 |
+
visible=False
|
| 272 |
)
|
| 273 |
+
seed_button = gr.Button("🔄 새로운 시드 생성", size="sm", elem_classes="seed-button")
|
| 274 |
+
seed_text = gr.Markdown("", elem_classes="seed-text")
|
| 275 |
|
| 276 |
num_images_per_prompt = gr.Slider(
|
| 277 |
label="프롬프트당 이미지 수",
|
|
|
|
| 305 |
outputs=[result],
|
| 306 |
)
|
| 307 |
|
|
|
|
| 308 |
gr.HTML(
|
| 309 |
"""
|
| 310 |
+
<div class="footer-content">
|
| 311 |
+
<p style="font-size: 1.1rem; font-weight: 500; color: #1F2937;">끝장AI가 제공하는 고급 AI 도구를 더 경험하고 싶으신가요?</p>
|
| 312 |
+
<a href="https://finalendai.com" target="_blank" class="visit-button">
|
| 313 |
끝장AI 방문하기
|
| 314 |
</a>
|
| 315 |
+
<p style="margin-top: 1.5rem; color: #6B7280; font-size: 0.9rem;">
|
| 316 |
© 2024 끝장AI. All rights reserved.
|
| 317 |
</p>
|
| 318 |
</div>
|