Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,16 +152,11 @@ DownLoad(r"https://civitai.com/api/download/models/39164",str(user_home / r"stab
|
|
| 152 |
# CPUモード設定(Linux向け修正)
|
| 153 |
os.environ["COMMANDLINE_ARGS"] = "--skip-torch-cuda-test --no-half --use-cpu all"
|
| 154 |
|
|
|
|
| 155 |
|
| 156 |
-
import os
|
| 157 |
-
import shutil
|
| 158 |
-
import subprocess
|
| 159 |
-
|
| 160 |
-
# Hugging Face からダウンロードするファイル情報
|
| 161 |
REPO_ID = "black-forest-labs/FLUX.1-dev"
|
| 162 |
FILENAME = "flux1-dev.safetensors"
|
| 163 |
MODEL_DIR = "/home/user/stable-diffusion-webui/models/Stable-diffusion"
|
| 164 |
-
MODEL_PATH = os.path.join(MODEL_DIR, FILENAME)
|
| 165 |
|
| 166 |
# 環境変数から Hugging Face トークンを取得
|
| 167 |
hf_token = os.getenv("token")
|
|
@@ -169,37 +164,22 @@ if not hf_token:
|
|
| 169 |
print("Error: Hugging Face token not found.")
|
| 170 |
exit(1)
|
| 171 |
|
| 172 |
-
#
|
| 173 |
-
if os.path.exists(MODEL_DIR):
|
| 174 |
-
print(f"Removing existing directory: {MODEL_DIR}")
|
| 175 |
-
shutil.rmtree(MODEL_DIR)
|
| 176 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 177 |
|
| 178 |
-
#
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
| 186 |
exit(1)
|
| 187 |
|
| 188 |
-
# ファイルサイズを確認
|
| 189 |
-
if os.path.exists(MODEL_PATH):
|
| 190 |
-
file_size = os.path.getsize(MODEL_PATH)
|
| 191 |
-
if file_size < 1000: # 1KB 未満なら異常
|
| 192 |
-
print(f"Error: {MODEL_PATH} is too small ({file_size} bytes). Download failed.")
|
| 193 |
-
os.remove(MODEL_PATH)
|
| 194 |
-
exit(1)
|
| 195 |
-
else:
|
| 196 |
-
print(f"Download successful. File size: {file_size / (1024 ** 3):.2f} GB")
|
| 197 |
-
else:
|
| 198 |
-
print("Error: Model file not found after download.")
|
| 199 |
-
exit(1)
|
| 200 |
-
|
| 201 |
-
print("Download completed successfully.")
|
| 202 |
-
|
| 203 |
|
| 204 |
print("Done\nStarting Webui...")
|
| 205 |
os.chdir(user_home / r"stable-diffusion-webui")
|
|
|
|
| 152 |
# CPUモード設定(Linux向け修正)
|
| 153 |
os.environ["COMMANDLINE_ARGS"] = "--skip-torch-cuda-test --no-half --use-cpu all"
|
| 154 |
|
| 155 |
+
from huggingface_hub import hf_hub_download
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
REPO_ID = "black-forest-labs/FLUX.1-dev"
|
| 158 |
FILENAME = "flux1-dev.safetensors"
|
| 159 |
MODEL_DIR = "/home/user/stable-diffusion-webui/models/Stable-diffusion"
|
|
|
|
| 160 |
|
| 161 |
# 環境変数から Hugging Face トークンを取得
|
| 162 |
hf_token = os.getenv("token")
|
|
|
|
| 164 |
print("Error: Hugging Face token not found.")
|
| 165 |
exit(1)
|
| 166 |
|
| 167 |
+
# モデルディレクトリ作成(削除は必要に応じて)
|
|
|
|
|
|
|
|
|
|
| 168 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 169 |
|
| 170 |
+
# ダウンロード実行
|
| 171 |
+
try:
|
| 172 |
+
model_path = hf_hub_download(
|
| 173 |
+
repo_id=REPO_ID,
|
| 174 |
+
filename=FILENAME,
|
| 175 |
+
local_dir=MODEL_DIR,
|
| 176 |
+
token=hf_token,
|
| 177 |
+
)
|
| 178 |
+
print(f"Download successful: {model_path}")
|
| 179 |
+
except Exception as e:
|
| 180 |
+
print(f"Error downloading model: {e}")
|
| 181 |
exit(1)
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
print("Done\nStarting Webui...")
|
| 185 |
os.chdir(user_home / r"stable-diffusion-webui")
|