Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,42 +149,60 @@ DownLoad(r"https://civitai.com/api/download/models/39885",str(user_home / r"stab
|
|
| 149 |
DownLoad(r"https://civitai.com/api/download/models/21065",str(user_home / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"LAS.safetensors")
|
| 150 |
DownLoad(r"https://civitai.com/api/download/models/39164",str(user_home / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"backlighting.safetensors")
|
| 151 |
|
|
|
|
|
|
|
| 152 |
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
-
# Hugging Face
|
| 156 |
hf_token = os.getenv("token")
|
| 157 |
if not hf_token:
|
| 158 |
print("Error: Hugging Face token not found.")
|
| 159 |
exit(1)
|
| 160 |
|
| 161 |
-
#
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
#
|
| 167 |
-
os.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
#
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
os.system(cmd)
|
| 173 |
|
| 174 |
-
#
|
| 175 |
-
if os.path.exists(
|
| 176 |
-
file_size = os.path.getsize(
|
| 177 |
if file_size < 1000: # 1KB 未満なら異常
|
| 178 |
-
print(f"Error: {
|
| 179 |
-
os.remove(
|
| 180 |
exit(1)
|
| 181 |
else:
|
| 182 |
-
print(f"Download successful. File size: {file_size}
|
| 183 |
else:
|
| 184 |
-
print("Error:
|
| 185 |
exit(1)
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
print("Done\nStarting Webui...")
|
| 190 |
os.chdir(user_home / r"stable-diffusion-webui")
|
|
|
|
| 149 |
DownLoad(r"https://civitai.com/api/download/models/21065",str(user_home / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"LAS.safetensors")
|
| 150 |
DownLoad(r"https://civitai.com/api/download/models/39164",str(user_home / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"backlighting.safetensors")
|
| 151 |
|
| 152 |
+
# CPUモード設定(Linux向け修正)
|
| 153 |
+
os.environ["COMMANDLINE_ARGS"] = "--skip-torch-cuda-test --no-half --use-cpu all"
|
| 154 |
|
| 155 |
|
| 156 |
+
# Hugging Face のリポジトリ情報
|
| 157 |
+
HF_REPO = "https://huggingface.co/black-forest-labs/FLUX.1-dev"
|
| 158 |
+
MODEL_NAME = "flux1-dev.safetensors"
|
| 159 |
+
MODEL_DIR = "/home/user/stable-diffusion-webui/models/Stable-diffusion"
|
| 160 |
+
MODEL_PATH = os.path.join(MODEL_DIR, MODEL_NAME)
|
| 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 |
+
# `git-lfs` がインストールされているか確認
|
| 169 |
+
try:
|
| 170 |
+
subprocess.run(["git", "lfs", "version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 171 |
+
except subprocess.CalledProcessError:
|
| 172 |
+
print("Error: Git LFS is not installed. Please install it using:")
|
| 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 |
+
# `git-lfs` を使ってモデルをダウンロード
|
| 179 |
+
if not os.path.exists(MODEL_DIR):
|
| 180 |
+
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 181 |
+
|
| 182 |
+
print("Cloning repository using Git LFS...")
|
| 183 |
+
clone_cmd = [
|
| 184 |
+
"GIT_LFS_SKIP_SMUDGE=1", # 最初のクローン時にダウンロードをスキップ
|
| 185 |
+
"git", "clone", HF_REPO, "--depth=1", "--filter=blob:none", MODEL_DIR
|
| 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 未満なら異常
|
| 197 |
+
print(f"Error: {MODEL_PATH} is too small ({file_size} bytes). Download failed.")
|
| 198 |
+
os.remove(MODEL_PATH)
|
| 199 |
exit(1)
|
| 200 |
else:
|
| 201 |
+
print(f"Download successful. File size: {file_size / (1024 * 1024 * 1024):.2f} GB.")
|
| 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")
|