Team Ai
Apppublic

rbantog/llama-cpp-server

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
4likes
replace_hw.py41 linesDownload Raw Back to root
1#!/usr/bin/env python32# filepath: replace_hello_world.py3 4import os5import urllib.parse6 7def extract_filename(url):8    parsed = urllib.parse.urlsplit(url)9    return os.path.basename(parsed.path)10 11def replace_in_file(file_path, old_text, new_text):12    with open(file_path, 'r', encoding='utf8') as file:13        content = file.read()14 15    if old_text not in content:16        return17 18    updated_content = content.replace(old_text, new_text)19    with open(file_path, 'w', encoding='utf8') as file:20        file.write(updated_content)21    print(f"Updated: {file_path}")22 23def main():24    model_link = os.getenv("MODEL_DOWNLOAD_LINK")25    if not model_link:26        print("Error: MODEL_DOWNLOAD_LINK environment variable is not set.")27        return28 29    download_filename = extract_filename(model_link)30    print(f"Extracted filename: {download_filename}")31 32    # Recursively walk thru current directory33    for dirpath, _, filenames in os.walk(os.getcwd()):34        for filename in filenames:35            # Modify the following tuple to include any file extensions you wish to process36            if filename.endswith(('.html', '.ts', '.patch')):37                full_path = os.path.join(dirpath, filename)38                replace_in_file(full_path, "Hello World!", download_filename)39 40if __name__ == '__main__':41    main()