tharms commited on
Commit
eef302c
·
1 Parent(s): 98e0e3d

added log output for custom launch

Browse files
Files changed (1) hide show
  1. modules/model_loader.py +43 -0
modules/model_loader.py CHANGED
@@ -12,7 +12,50 @@ from urllib.error import HTTPError, URLError
12
  from urllib.request import urlopen, Request
13
  from typing import Optional
14
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def load_file_from_url(
17
  url: str,
18
  *,
 
12
  from urllib.request import urlopen, Request
13
  from typing import Optional
14
 
15
+ class _Faketqdm: # type: ignore[no-redef]
16
 
17
+ def __init__(self, total=None, disable=False,
18
+ unit=None, *args, **kwargs):
19
+ self.total = total
20
+ self.disable = disable
21
+ self.n = 0
22
+ # Ignore all extra *args and **kwargs lest you want to reinvent tqdm
23
+
24
+ def update(self, n):
25
+ if self.disable:
26
+ return
27
+
28
+ self.n += n
29
+ if self.total is None:
30
+ sys.stderr.write(f"\r{self.n:.1f} bytes")
31
+ else:
32
+ sys.stderr.write(f"\r{100 * self.n / float(self.total):.1f}%")
33
+ sys.stderr.flush()
34
+
35
+ # Don't bother implementing; use real tqdm if you want
36
+ def set_description(self, *args, **kwargs):
37
+ pass
38
+
39
+ def write(self, s):
40
+ sys.stderr.write(f"{s}\n")
41
+
42
+ def close(self):
43
+ self.disable = True
44
+
45
+ def __enter__(self):
46
+ return self
47
+
48
+ def __exit__(self, exc_type, exc_val, exc_tb):
49
+ if self.disable:
50
+ return
51
+
52
+ sys.stderr.write('\n')
53
+
54
+ try:
55
+ from tqdm import tqdm # If tqdm is installed use it, otherwise use the fake wrapper
56
+ except ImportError:
57
+ tqdm = _Faketqdm
58
+
59
  def load_file_from_url(
60
  url: str,
61
  *,