Download tools/load_file.py from dmfelder/DF_Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 526 Bytes
-
https://huggingface.co/spaces/dmfelder/DF_Final_Assignment_Template/resolve/main/tools/load_file.py
- Command line
-
hf download hf://spaces/dmfelder/DF_Final_Assignment_Template/tools/load_file.py
-
curl -L -o load_file.py https://huggingface.co/spaces/dmfelder/DF_Final_Assignment_Template/resolve/main/tools/load_file.py
526 Bytes
| import io | |
| from urllib.parse import urlparse | |
| import requests | |
| def load_file(path_or_url: str) -> io.BytesIO: | |
| if _is_url(path_or_url): | |
| response = requests.get(path_or_url) | |
| response.raise_for_status() | |
| return io.BytesIO(response.content) | |
| else: | |
| with open(path_or_url, 'rb') as f: | |
| return io.BytesIO(f.read()) | |
| def _is_url(path_or_url): | |
| try: | |
| result = urlparse(path_or_url) | |
| return result.scheme in ('http', 'https') | |
| except ValueError: | |
| return False |