1
0
Fork 0

fix(api): restore python 3.8 compatibility (#146)

This commit is contained in:
Sean Sube 2023-02-14 21:23:16 -06:00
parent 4d0cd2e981
commit 3e5edb1c39
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 10 additions and 2 deletions

View File

@ -17,6 +17,7 @@ from .utils import (
ConversionContext, ConversionContext,
download_progress, download_progress,
model_formats_original, model_formats_original,
remove_prefix,
source_format, source_format,
tuple_to_correction, tuple_to_correction,
tuple_to_diffusion, tuple_to_diffusion,
@ -157,14 +158,14 @@ def fetch_model(
for proto in model_sources: for proto in model_sources:
api_name, api_root = model_sources.get(proto) api_name, api_root = model_sources.get(proto)
if source.startswith(proto): if source.startswith(proto):
api_source = api_root % (source.removeprefix(proto)) api_source = api_root % (remove_prefix(source, proto))
logger.info( logger.info(
"Downloading model from %s: %s -> %s", api_name, api_source, cache_name "Downloading model from %s: %s -> %s", api_name, api_source, cache_name
) )
return download_progress([(api_source, cache_name)]) return download_progress([(api_source, cache_name)])
if source.startswith(model_source_huggingface): if source.startswith(model_source_huggingface):
hub_source = source.removeprefix(model_source_huggingface) hub_source = remove_prefix(source, model_source_huggingface)
logger.info("Downloading model from Huggingface Hub: %s", hub_source) logger.info("Downloading model from Huggingface Hub: %s", hub_source)
# from_pretrained has a bunch of useful logic that snapshot_download by itself down not # from_pretrained has a bunch of useful logic that snapshot_download by itself down not
return hub_source return hub_source

View File

@ -192,3 +192,10 @@ safe_chars = "._-"
def sanitize_name(name): def sanitize_name(name):
return "".join(x for x in name if (x.isalnum() or x in safe_chars)) return "".join(x for x in name if (x.isalnum() or x in safe_chars))
def remove_prefix(name, prefix):
if name.startswith(prefix):
return name[len(prefix) :]
return name