Spaces:
Paused
Paused
app
Browse files
app.py
CHANGED
|
@@ -55,7 +55,8 @@ def init_pipeline_if_needed():
|
|
| 55 |
global pipe
|
| 56 |
if pipe is not None:
|
| 57 |
return
|
| 58 |
-
|
|
|
|
| 59 |
if use_int8 or get_gpu_memory_gb() < 33:
|
| 60 |
transformer_model = FluxTransformer2DModel.from_pretrained(
|
| 61 |
"sayakpaul/flux.1-schell-int8wo-improved",
|
|
@@ -76,10 +77,13 @@ def init_pipeline_if_needed():
|
|
| 76 |
token=hf_token,
|
| 77 |
)
|
| 78 |
|
|
|
|
| 79 |
_pipe = _pipe.to("cuda")
|
|
|
|
| 80 |
_pipe.load_lora_weights(MODEL_PATH, adapter_name=ADAPTER_NAME)
|
| 81 |
_pipe.set_adapters([ADAPTER_NAME])
|
| 82 |
pipe = _pipe
|
|
|
|
| 83 |
|
| 84 |
def _to_pil_rgba(img: Any) -> Image.Image:
|
| 85 |
"""Convert various inputs to PIL RGBA image"""
|
|
@@ -454,6 +458,15 @@ def create_simple_app():
|
|
| 454 |
|
| 455 |
return app
|
| 456 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
if __name__ == "__main__":
|
| 458 |
app = create_simple_app()
|
| 459 |
app.launch(
|
|
|
|
| 55 |
global pipe
|
| 56 |
if pipe is not None:
|
| 57 |
return
|
| 58 |
+
|
| 59 |
+
print("🚀 Initializing pipeline...")
|
| 60 |
if use_int8 or get_gpu_memory_gb() < 33:
|
| 61 |
transformer_model = FluxTransformer2DModel.from_pretrained(
|
| 62 |
"sayakpaul/flux.1-schell-int8wo-improved",
|
|
|
|
| 77 |
token=hf_token,
|
| 78 |
)
|
| 79 |
|
| 80 |
+
print("📦 Loading model to CUDA...")
|
| 81 |
_pipe = _pipe.to("cuda")
|
| 82 |
+
print("🎨 Loading LoRA weights...")
|
| 83 |
_pipe.load_lora_weights(MODEL_PATH, adapter_name=ADAPTER_NAME)
|
| 84 |
_pipe.set_adapters([ADAPTER_NAME])
|
| 85 |
pipe = _pipe
|
| 86 |
+
print("✅ Pipeline initialized successfully!")
|
| 87 |
|
| 88 |
def _to_pil_rgba(img: Any) -> Image.Image:
|
| 89 |
"""Convert various inputs to PIL RGBA image"""
|
|
|
|
| 458 |
|
| 459 |
return app
|
| 460 |
|
| 461 |
+
# 在应用启动前预加载模型
|
| 462 |
+
print("=" * 60)
|
| 463 |
+
print("🔧 Pre-loading models on startup...")
|
| 464 |
+
print("=" * 60)
|
| 465 |
+
init_pipeline_if_needed()
|
| 466 |
+
print("=" * 60)
|
| 467 |
+
print("✨ All models loaded and ready!")
|
| 468 |
+
print("=" * 60)
|
| 469 |
+
|
| 470 |
if __name__ == "__main__":
|
| 471 |
app = create_simple_app()
|
| 472 |
app.launch(
|