| from pathlib import Path | |
| import tempfile | |
| import gdown | |
| import requests | |
| def download_file(url: str, output: str = None) -> str: | |
| if not output: | |
| with tempfile.NamedTemporaryFile(delete=False) as tmp: | |
| output = tmp.name | |
| # if Path(output).exists(): | |
| # return output | |
| if 'drive.google.com' in url: | |
| gdown.download(url, output=output, fuzzy=True) | |
| return output | |
| res = requests.get(url, stream=True) | |
| res.raise_for_status() | |
| with open(output, 'wb') as f: | |
| for chunk in res.iter_content(chunk_size=8192): | |
| f.write(chunk) | |
| return output |