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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -19
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
- model_path = "/home/user/stable-diffusion-webui/models/Stable-diffusion/flux1-dev.safetensors"
163
- if os.path.exists(model_path):
164
- os.remove(model_path)
 
 
 
 
 
165
 
166
- # CPUモード設定(Linux向け修正)
167
- os.environ["COMMANDLINE_ARGS"] = "--skip-torch-cuda-test --no-half --use-cpu all"
 
 
 
 
 
 
 
 
168
 
169
- # wget でファイルをダウンロード
170
- cmd = f'wget --header="Authorization: Bearer {hf_token}" -O "{model_path}" "https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/flux1-dev.safetensors"'
171
- print(f"Executing command: {cmd}")
172
- os.system(cmd)
173
 
174
- # ファイルサイズチェック
175
- if os.path.exists(model_path):
176
- file_size = os.path.getsize(model_path)
177
  if file_size < 1000: # 1KB 未満なら異常
178
- print(f"Error: {model_path} is too small ({file_size} bytes). Download failed.")
179
- os.remove(model_path)
180
  exit(1)
181
  else:
182
- print(f"Download successful. File size: {file_size} bytes.")
183
  else:
184
- print("Error: File not found after download.")
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")