Download replace_url.py from XiaoHanYS/BuildDockerOn_virtaicloud: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/XiaoHanYS/BuildDockerOn_virtaicloud/resolve/main/replace_url.py
- Command line
-
hf download hf://datasets/XiaoHanYS/BuildDockerOn_virtaicloud/replace_url.py
-
curl -L -o replace_url.py https://huggingface.co/datasets/XiaoHanYS/BuildDockerOn_virtaicloud/resolve/main/replace_url.py
1.03 kB
| import os | |
| def replace_url_in_file(file_path, old_url, new_url): | |
| try: | |
| with open(file_path, 'r', encoding='utf-8') as file: | |
| filedata = file.read() | |
| filedata = filedata.replace(old_url, new_url) | |
| with open(file_path, 'w', encoding='utf-8') as file: | |
| file.write(filedata) | |
| except Exception as e: | |
| pass | |
| def replace_url_in_folder(folder_path, old_url, new_url): | |
| for root, dirs, files in os.walk(folder_path): | |
| for file in files: | |
| file_path = os.path.join(root, file) | |
| replace_url_in_file(file_path, old_url, new_url) | |
| folder_path = 'stable-diffusion-webui-forge/' # 替换为你的文件夹路径 | |
| old_hugging = 'huggingface.co' # 替换为你要替换的旧URL | |
| new_hugging = 'hf-mirror.com' # 替换为你要替换的新URL | |
| old_git = "https://github.com" | |
| new_git = "https://gh.con.sh/https://github.com" | |
| replace_url_in_folder(folder_path, old_hugging, new_hugging) | |
| replace_url_in_folder(folder_path, old_git, new_git) | |
| print("ALL DONE!") | |