Skip to content

Commit

Permalink
fix(api): restore python 3.8 compatibility (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 15, 2023
1 parent 4d0cd2e commit 3e5edb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/onnx_web/convert/__main__.py
Expand Up @@ -17,6 +17,7 @@
ConversionContext,
download_progress,
model_formats_original,
remove_prefix,
source_format,
tuple_to_correction,
tuple_to_diffusion,
Expand Down Expand Up @@ -157,14 +158,14 @@ def fetch_model(
for proto in model_sources:
api_name, api_root = model_sources.get(proto)
if source.startswith(proto):
api_source = api_root % (source.removeprefix(proto))
api_source = api_root % (remove_prefix(source, proto))
logger.info(
"Downloading model from %s: %s -> %s", api_name, api_source, cache_name
)
return download_progress([(api_source, cache_name)])

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)
# from_pretrained has a bunch of useful logic that snapshot_download by itself down not
return hub_source
Expand Down
7 changes: 7 additions & 0 deletions api/onnx_web/convert/utils.py
Expand Up @@ -192,3 +192,10 @@ def load_yaml(file: str) -> str:

def sanitize_name(name):
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

0 comments on commit 3e5edb1

Please sign in to comment.