Spaces:
Running
Running
Download modules/utilities/utils.py from NextGenTech/ngt-ai-platform: direct link, hf CLI and curl.
- Browser
- Download file 733 Bytes
-
https://huggingface.co/spaces/NextGenTech/ngt-ai-platform/resolve/refs%2Fpr%2F2/modules/utilities/utils.py
- Command line
-
hf download hf://spaces/NextGenTech/ngt-ai-platform@refs/pr/2/modules/utilities/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/NextGenTech/ngt-ai-platform/resolve/refs%2Fpr%2F2/modules/utilities/utils.py
733 Bytes
| import json | |
| from tensorflow.keras.preprocessing.text import Tokenizer | |
| from tensorflow.keras.preprocessing.text import tokenizer_from_json | |
| def allowed_model(filename): | |
| return '.' in filename and \ | |
| filename.rsplit('.', 1)[1].lower() in {'keras', 'h5'} | |
| def allowed_tokenizer(filename): | |
| return '.' in filename and \ | |
| filename.rsplit('.', 1)[1].lower() in {'json'} | |
| def load_doc(filename): | |
| # open the file as read only | |
| file = open(filename, 'r') | |
| # read all text | |
| text = file.read() | |
| # close the file | |
| file.close() | |
| return text | |
| def load_tokenizer(tokenizer_path): | |
| with open(tokenizer_path) as f: | |
| data = json.load(f) | |
| tokenizer = Tokenizer() | |
| tokenizer = tokenizer_from_json(data) | |
| return tokenizer |