Download code/dataset/utils.py from osamaifti/NEXTGPT: direct link, hf CLI and curl.
- Browser
- Download file 939 Bytes
-
https://huggingface.co/osamaifti/NEXTGPT/resolve/main/code/dataset/utils.py
- Command line
-
hf download hf://osamaifti/NEXTGPT/code/dataset/utils.py
-
curl -L -o utils.py https://huggingface.co/osamaifti/NEXTGPT/resolve/main/code/dataset/utils.py
939 Bytes
| from header import * | |
| import importlib | |
| def process_caption(caption): | |
| caption = re.sub( | |
| r"([\"()*#:;~])", | |
| " ", | |
| caption.lower(), | |
| ) | |
| caption = re.sub( | |
| r"\s{2,}", | |
| " ", | |
| caption, | |
| ) | |
| caption = caption.rstrip("\n") | |
| caption = caption.strip(" ") | |
| return caption | |
| def instantiate_from_config(config): | |
| if not "target" in config: | |
| if config == '__is_first_stage__': | |
| return None | |
| elif config == "__is_unconditional__": | |
| return None | |
| raise KeyError("Expected key `target` to instantiate.") | |
| return get_obj_from_str(config["target"])(**config.get("params", dict())) | |
| def get_obj_from_str(string, reload=False): | |
| module, cls = string.rsplit(".", 1) | |
| if reload: | |
| module_imp = importlib.import_module(module) | |
| importlib.reload(module_imp) | |
| return getattr(importlib.import_module(module, package=None), cls) | |