Spaces:
Running on Zero
Running on Zero
Download src/misc/resume_ckpt.py from hugging-apps/codecsplat: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/hugging-apps/codecsplat/resolve/main/src/misc/resume_ckpt.py
- Command line
-
hf download hf://spaces/hugging-apps/codecsplat/src/misc/resume_ckpt.py
-
curl -L -o resume_ckpt.py https://huggingface.co/spaces/hugging-apps/codecsplat/resolve/main/src/misc/resume_ckpt.py
670 Bytes
| import os | |
| # Function to extract the step number from the filename | |
| def extract_step(file_name): | |
| step_str = file_name.split("-")[1].split("_")[1].replace(".ckpt", "") | |
| return int(step_str) | |
| def find_latest_ckpt(ckpt_dir): | |
| # List all files in the directory that end with .ckpt | |
| ckpt_files = [f for f in os.listdir(ckpt_dir) if f.endswith(".ckpt")] | |
| # Check if there are any .ckpt files in the directory | |
| if not ckpt_files: | |
| raise ValueError(f"No .ckpt files found in {ckpt_dir}.") | |
| else: | |
| # Find the file with the maximum step | |
| latest_ckpt_file = max(ckpt_files, key=extract_step) | |
| return ckpt_dir / latest_ckpt_file | |