ffreemt commited on
Commit
42f7557
1 Parent(s): e433d54

Update aria2c download

Browse files
Files changed (2) hide show
  1. app.py +24 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -11,8 +11,9 @@ import pynvml
11
  from ctransformers import AutoModelForCausalLM
12
  from gradio.themes.base import Base
13
  from gradio.themes.utils import colors, fonts, sizes
14
- from huggingface_hub import hf_hub_download # snapshot_download,
15
  from loguru import logger
 
16
 
17
  os.environ["TZ"] = "Asia/Shanghai"
18
  try:
@@ -31,7 +32,9 @@ logger.debug("Start dl")
31
  for idx in range(5):
32
  logger.debug(f"attempt {idx + 1}")
33
  try:
34
- model_path = hf_hub_download(repo_id=repo_id, filename=filename, revision="main")
 
 
35
  break
36
  except Exception as exc:
37
  logger.error(f"failed to download {filename}: {exc}")
@@ -45,6 +48,25 @@ else:
45
 
46
  logger.debug(f"Done dl, {model_ready=}")
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
49
  # model = AutoModelForCausalLM.from_pretrained("TheBloke/openbuddy-mistral-7B-v13-GGUF", model_file="openbuddy-mistral-7b-v13.Q4_K_S.gguf", model_type="mistral", gpu_layers=0)
50
 
 
11
  from ctransformers import AutoModelForCausalLM
12
  from gradio.themes.base import Base
13
  from gradio.themes.utils import colors, fonts, sizes
14
+ from huggingface_hub import hf_hub_download, hf_hub_url # snapshot_download,
15
  from loguru import logger
16
+ from python_run_cmd import run_cmd
17
 
18
  os.environ["TZ"] = "Asia/Shanghai"
19
  try:
 
32
  for idx in range(5):
33
  logger.debug(f"attempt {idx + 1}")
34
  try:
35
+ model_path = hf_hub_download(
36
+ repo_id=repo_id, filename=filename, revision="main"
37
+ )
38
  break
39
  except Exception as exc:
40
  logger.error(f"failed to download {filename}: {exc}")
 
48
 
49
  logger.debug(f"Done dl, {model_ready=}")
50
 
51
+ if not model_ready: # try aria2c
52
+ logger.debug("Try aria2c...")
53
+ url = hf_hub_url(
54
+ repo_id,
55
+ filename,
56
+ # revision="ggmlv3",
57
+ )
58
+ logger.debug(f"{url=}")
59
+ ret = run_cmd("apt update && apt install aria2 -y", mute_stdout=False)
60
+ logger.debug(ret)
61
+
62
+ ret1 = run_cmd(f"aria2c -c -o {filename} {url}", mute_stdout=False)
63
+ logger.debug(ret1)
64
+ model_path = f"./{filename}"
65
+
66
+ # both successful
67
+ if not ret.returncode and not ret1.returncode:
68
+ model_ready = True
69
+
70
  # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
71
  # model = AutoModelForCausalLM.from_pretrained("TheBloke/openbuddy-mistral-7B-v13-GGUF", model_file="openbuddy-mistral-7b-v13.Q4_K_S.gguf", model_type="mistral", gpu_layers=0)
72
 
requirements.txt CHANGED
@@ -2,4 +2,5 @@ ctransformers
2
  # gradio
3
  huggingface-hub
4
  loguru
5
- pynvml
 
 
2
  # gradio
3
  huggingface-hub
4
  loguru
5
+ pynvml
6
+ python-run-cmd