File size: 1,086 Bytes
15f6380
 
 
 
 
dd1a82e
 
 
 
 
 
 
15f6380
 
dd1a82e
15f6380
 
dd1a82e
15f6380
 
 
 
dd1a82e
15f6380
 
 
dd1a82e
15f6380
dd1a82e
15f6380
 
 
 
 
 
 
 
 
 
 
 
 
 
dd1a82e
15f6380
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/python3 -i
# coding=utf-8

import os

try:
  from transformers.utils import cached_file
except:
  from transformers.file_utils import cached_path,hf_bucket_url
  cached_file=lambda x,y:cached_path(hf_bucket_url(x,y))

def download(rootdir,file,dir="."):
  import shutil
  t=os.path.join(dir,"filesize.txt")
  shutil.copy(cached_file(rootdir,os.path.dirname(file)+"/filesize.txt"),t)
  with open(t,"r") as f:
    r=f.read()
  f=os.path.basename(file)
  ft=0
  for t in r.split("\n"):
    s=t.split()
    if len(s)==2:
      if s[0]==f:
        ft=int(s[1])
  if ft==0:
    return
  shutil.copy(cached_file(rootdir,file),os.path.join(dir,f))

def checkdownload(rootdir,model,dir="."):
  while True:
    t=os.path.join(dir,"filesize.txt")
    with open(t,"r") as f:
      r=f.read()
    for t in r.split("\n"):
      s=t.split()
      if len(s)==2:
        f=os.path.join(dir,s[0])
        i=int(s[1])
        try:
          j=os.path.getsize(f)
        except:
          j=-1
        if i!=j:
          download(rootdir,model+s[0],dir)
          break
    else:
      return