Spaces:
Sleeping
Sleeping
Download utils/check_pydantic_version.py from MachineLearningReply/search_mlReply: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/MachineLearningReply/search_mlReply/resolve/main/utils/check_pydantic_version.py
- Command line
-
hf download hf://spaces/MachineLearningReply/search_mlReply/utils/check_pydantic_version.py
-
curl -L -o check_pydantic_version.py https://huggingface.co/spaces/MachineLearningReply/search_mlReply/resolve/main/utils/check_pydantic_version.py
1.08 kB
| import pydantic | |
| import os | |
| import fileinput | |
| def replace_string_in_files(folder_path, old_str, new_str): | |
| for subdir, dirs, files in os.walk(folder_path): | |
| for file in files: | |
| file_path = os.path.join(subdir, file) | |
| # Check if the file is a text file (you can modify this condition based on your needs) | |
| if file.endswith(".txt") or file.endswith(".py"): | |
| # Open the file in place for editing | |
| with fileinput.FileInput(file_path, inplace=True) as f: | |
| for line in f: | |
| # Replace the old string with the new string | |
| print(line.replace(old_str, new_str), end='') | |
| def use_pydantic_v1(): | |
| module_file_path = pydantic.__file__ | |
| module_file_path = module_file_path.split('pydantic')[0] + 'haystack' | |
| with open(module_file_path+'/schema.py','r') as f: | |
| haystack_schema_file = f.read() | |
| if 'from pydantic.v1' not in haystack_schema_file: | |
| replace_string_in_files(module_file_path, 'from pydantic', 'from pydantic.v1') |