Kohaku-Blueleaf commited on
Commit
2656dce
·
1 Parent(s): 424ca4c

update model download method

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import os
2
- os.system("pip install git+https://${GIT_USER}:${GIT_TOKEN}@github.com/KohakuBlueleaf/XUT")
3
  import random
4
  import json
5
  from pathlib import Path
@@ -9,6 +8,7 @@ import httpx
9
  if os.environ.get("IN_SPACES", None) is not None:
10
  in_spaces = True
11
  import spaces
 
12
  else:
13
  in_spaces = False
14
  import numpy as np
@@ -68,7 +68,7 @@ def download_model(url: str, filepath: str):
68
  print(f"Model already exists at {filepath}")
69
  return
70
 
71
- print(f"Downloading model from {url}...")
72
  Path(filepath).parent.mkdir(parents=True, exist_ok=True)
73
 
74
  with httpx.stream("GET", url, follow_redirects=True) as response:
@@ -168,8 +168,8 @@ vae_std = torch.tensor(vae.config.latents_std).view(1, -1, 1, 1).to(device)
168
 
169
 
170
  if not os.path.exists("./model/model.safetensors"):
171
- model_url = os.environ.get("MODEL_URL")
172
- download_model(model_url, "./model/model.safetensors")
173
 
174
  state_dict = load_file("./model/model.safetensors")
175
  model_sd = {k.replace("unet.", ""): v for k, v in state_dict.items() if k.startswith("unet.")}
 
1
  import os
 
2
  import random
3
  import json
4
  from pathlib import Path
 
8
  if os.environ.get("IN_SPACES", None) is not None:
9
  in_spaces = True
10
  import spaces
11
+ os.system("pip install git+https://${GIT_USER}:${GIT_TOKEN}@github.com/KohakuBlueleaf/XUT")
12
  else:
13
  in_spaces = False
14
  import numpy as np
 
68
  print(f"Model already exists at {filepath}")
69
  return
70
 
71
+ print(f"Downloading model...")
72
  Path(filepath).parent.mkdir(parents=True, exist_ok=True)
73
 
74
  with httpx.stream("GET", url, follow_redirects=True) as response:
 
168
 
169
 
170
  if not os.path.exists("./model/model.safetensors"):
171
+ model_file = os.environ.get("MODEL_FILE")
172
+ os.system(f"hfutils download -t model -r KBlueLeaf/XUT-demo -f {model_file} -o model/model.safetensors")
173
 
174
  state_dict = load_file("./model/model.safetensors")
175
  model_sd = {k.replace("unet.", ""): v for k, v in state_dict.items() if k.startswith("unet.")}
requirements.txt CHANGED
@@ -9,4 +9,5 @@ spaces
9
  gradio
10
  httpx
11
  einops
 
12
  https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.13-cu124/llama_cpp_python-0.3.13-cp310-cp310-linux_x86_64.whl
 
9
  gradio
10
  httpx
11
  einops
12
+ hfutils[transfer]
13
  https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.13-cu124/llama_cpp_python-0.3.13-cp310-cp310-linux_x86_64.whl