Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
Restore Model.py
Go to the documentation of this file.
1
"""Restore the exact base model recorded in model-manifest.json; no audio is uploaded."""
2
import
hashlib
3
import
json
4
import
os
5
import
shutil
6
import
urllib.request
7
from
pathlib
import
Path
8
9
root = Path(__file__).resolve().parent
10
manifest = json.loads((root/
'model-manifest.json'
).read_text(encoding=
'utf-8'
))
11
target = root/
'models/nano'
12
target.mkdir(parents=
True
, exist_ok=
True
)
13
14
def
matches
(path, entry):
15
if
not
path.is_file()
or
path.stat().st_size != entry[
'bytes'
]:
16
return
False
17
with
path.open(
'rb'
)
as
stream:
18
return
hashlib.file_digest(stream,
'sha256'
).hexdigest() == entry[
'sha256'
]
19
20
for
name, entry
in
manifest[
'files'
].items():
21
if
Path(name).name != name:
22
raise
ValueError(
'Invalid filename in model manifest.'
)
23
output = target/name
24
if
matches
(output, entry):
25
print(f
'Already verified: {name}'
, flush=
True
)
26
continue
27
if
shutil.disk_usage(target).free < entry[
'bytes'
] + 64*1024*1024:
28
raise
RuntimeError(f
'Insufficient free disk space to restore {name}.'
)
29
url = f
"https://huggingface.co/{manifest['repository']}/resolve/{manifest['revision']}/{name}"
30
temporary = output.with_name(output.name+
'.download'
)
31
print(f
'Downloading {name}...'
, flush=
True
)
32
with
urllib.request.urlopen(url, timeout=120)
as
source, temporary.open(
'wb'
)
as
sink:
33
shutil.copyfileobj(source, sink, 1024*1024)
34
if
not
matches
(temporary, entry):
35
raise
RuntimeError(f
'Integrity check failed: {temporary}'
)
36
os.replace(temporary, output)
37
print(
'All model files are verified.'
, flush=
True
)
Restore Model.matches
matches(path, entry)
Definition
Restore Model.py:14
Sounds
Unused
Erin
VoiceClone
Restore Model.py
Generated on
for Rise by
1.18.0