Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,14 +39,37 @@ os.environ["TRANSFORMERS_CACHE"] = cache_path
|
|
| 39 |
os.environ["HF_HUB_CACHE"] = cache_path
|
| 40 |
os.environ["HF_HOME"] = cache_path
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# FLUX 모델 초기화
|
| 43 |
if not path.exists(cache_path):
|
| 44 |
os.makedirs(cache_path, exist_ok=True)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
pipe.
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# 이미지 생성 함수 추가
|
| 52 |
@spaces.GPU
|
|
|
|
| 39 |
os.environ["HF_HUB_CACHE"] = cache_path
|
| 40 |
os.environ["HF_HOME"] = cache_path
|
| 41 |
|
| 42 |
+
|
| 43 |
+
# Hugging Face 토큰 설정
|
| 44 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 45 |
+
if not HF_TOKEN:
|
| 46 |
+
print("Warning: HF_TOKEN not found in environment variables")
|
| 47 |
+
|
| 48 |
# FLUX 모델 초기화
|
| 49 |
if not path.exists(cache_path):
|
| 50 |
os.makedirs(cache_path, exist_ok=True)
|
| 51 |
|
| 52 |
+
try:
|
| 53 |
+
pipe = FluxPipeline.from_pretrained(
|
| 54 |
+
"black-forest-labs/FLUX.1-dev",
|
| 55 |
+
torch_dtype=torch.bfloat16,
|
| 56 |
+
use_auth_token=HF_TOKEN # Hugging Face 토큰 추가
|
| 57 |
+
)
|
| 58 |
+
pipe.load_lora_weights(
|
| 59 |
+
hf_hub_download(
|
| 60 |
+
"ByteDance/Hyper-SD",
|
| 61 |
+
"Hyper-FLUX.1-dev-8steps-lora.safetensors",
|
| 62 |
+
token=HF_TOKEN # Hugging Face 토큰 추가
|
| 63 |
+
)
|
| 64 |
+
)
|
| 65 |
+
pipe.fuse_lora(lora_scale=0.125)
|
| 66 |
+
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 67 |
+
print("Successfully initialized FLUX model with authentication")
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"Error initializing FLUX model: {str(e)}")
|
| 70 |
+
pipe = None
|
| 71 |
+
|
| 72 |
+
|
| 73 |
|
| 74 |
# 이미지 생성 함수 추가
|
| 75 |
@spaces.GPU
|