soiz1 commited on
Commit
a385022
·
verified ·
1 Parent(s): c29ae9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -29
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
- # 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 未満なら異常
@@ -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 * 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")
 
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")