| import os |
|
|
|
|
| |
| script_dir = os.path.dirname(os.path.abspath(__file__)) |
|
|
| |
| model_dir = os.path.join(script_dir, '..', 'models') |
| markdown_file = os.path.join(script_dir, '..', 'README.md') |
|
|
| |
| begin_marker = "<!-- BEGIN MODEL LINKS -->" |
| end_marker = "<!-- END MODEL LINKS -->" |
|
|
| |
| links = [] |
| for file_name in os.listdir(model_dir): |
| if file_name.endswith(".json"): |
| base_name = os.path.splitext(file_name)[0] |
| link = f" - [{base_name}](https://openmodeldb.info/models/{base_name})" |
| links.append(link) |
|
|
| |
| with open(markdown_file, 'r') as file: |
| content = file.read() |
|
|
| |
| begin_idx = content.find(begin_marker) + len(begin_marker) |
| end_idx = content.find(end_marker) |
|
|
| if begin_idx != -1 and end_idx != -1: |
| |
| new_content = content[:begin_idx] + "\n" + "\n".join(links) + "\n" + content[end_idx:] |
| |
| |
| with open(markdown_file, 'w') as file: |
| file.write(new_content) |
| print("Markdown file has been updated.") |
| else: |
| print("Markers not found.") |