Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| # filepath: replace_hello_world.py | |
| import os | |
| import urllib.parse | |
| def extract_filename(url): | |
| parsed = urllib.parse.urlsplit(url) | |
| return os.path.basename(parsed.path) | |
| def replace_in_file(file_path, old_text, new_text): | |
| with open(file_path, 'r', encoding='utf8') as file: | |
| content = file.read() | |
| if old_text not in content: | |
| return | |
| updated_content = content.replace(old_text, new_text) | |
| with open(file_path, 'w', encoding='utf8') as file: | |
| file.write(updated_content) | |
| print(f"Updated: {file_path}") | |
| def main(): | |
| model_link = os.getenv("MODEL_DOWNLOAD_LINK") | |
| if not model_link: | |
| print("Error: MODEL_DOWNLOAD_LINK environment variable is not set.") | |
| return | |
| download_filename = extract_filename(model_link) | |
| print(f"Extracted filename: {download_filename}") | |
| # Recursively walk thru current directory | |
| for dirpath, _, filenames in os.walk(os.getcwd()): | |
| for filename in filenames: | |
| # Modify the following tuple to include any file extensions you wish to process | |
| if filename.endswith(('.html', '.ts', '.patch')): | |
| full_path = os.path.join(dirpath, filename) | |
| replace_in_file(full_path, "Hello World!", download_filename) | |
| if __name__ == '__main__': | |
| main() |