Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -153,44 +153,39 @@ DownLoad(r"https://civitai.com/api/download/models/39164",str(user_home / r"stab
|
|
| 153 |
os.environ["COMMANDLINE_ARGS"] = "--skip-torch-cuda-test --no-half --use-cpu all"
|
| 154 |
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
MODEL_DIR = "/home/user/stable-diffusion-webui/models/Stable-diffusion"
|
| 160 |
-
MODEL_PATH = os.path.join(MODEL_DIR,
|
| 161 |
|
| 162 |
-
# 環境変数から Hugging Face
|
| 163 |
hf_token = os.getenv("token")
|
| 164 |
if not hf_token:
|
| 165 |
print("Error: Hugging Face token not found.")
|
| 166 |
exit(1)
|
| 167 |
|
| 168 |
-
#
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
print(" sudo apt install git-lfs (Ubuntu/Debian)")
|
| 174 |
-
print(" brew install git-lfs (Mac)")
|
| 175 |
-
print(" choco install git-lfs (Windows)")
|
| 176 |
-
exit(1)
|
| 177 |
|
| 178 |
-
#
|
| 179 |
-
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
"
|
| 185 |
-
|
| 186 |
-
]
|
| 187 |
-
subprocess.run(" ".join(clone_cmd), shell=True, check=True)
|
| 188 |
-
|
| 189 |
-
# `git-lfs` で LFS ファイルを取得
|
| 190 |
-
print("Fetching model file using Git LFS...")
|
| 191 |
-
subprocess.run(["git", "lfs", "pull"], cwd=MODEL_DIR, check=True)
|
| 192 |
|
| 193 |
-
#
|
| 194 |
if os.path.exists(MODEL_PATH):
|
| 195 |
file_size = os.path.getsize(MODEL_PATH)
|
| 196 |
if file_size < 1000: # 1KB 未満なら異常
|
|
@@ -198,11 +193,13 @@ if os.path.exists(MODEL_PATH):
|
|
| 198 |
os.remove(MODEL_PATH)
|
| 199 |
exit(1)
|
| 200 |
else:
|
| 201 |
-
print(f"Download successful. File size: {file_size / (1024
|
| 202 |
else:
|
| 203 |
print("Error: Model file not found after download.")
|
| 204 |
exit(1)
|
| 205 |
|
|
|
|
|
|
|
| 206 |
|
| 207 |
print("Done\nStarting Webui...")
|
| 208 |
os.chdir(user_home / r"stable-diffusion-webui")
|
|
|
|
| 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")
|
| 168 |
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 |
+
# Hugging Face からファイルのみをダウンロード
|
| 179 |
+
print(f"Downloading {FILENAME} from {REPO_ID}...")
|
| 180 |
+
download_cmd = f"wget --header='Authorization: Bearer {hf_token}' -O {MODEL_PATH} https://huggingface.co/{REPO_ID}/resolve/main/{FILENAME}"
|
| 181 |
+
result = subprocess.run(download_cmd, shell=True, capture_output=True, text=True)
|
| 182 |
|
| 183 |
+
# ダウンロード結果をチェック
|
| 184 |
+
if result.returncode != 0:
|
| 185 |
+
print(f"Error downloading file: {result.stderr}")
|
| 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 未満なら異常
|
|
|
|
| 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")
|