Download exp_code/1_benchmark/musubi-tuner/src/convert_json.py from SuperCS/useful_code: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/datasets/SuperCS/useful_code/resolve/aa8ee3caa0e01f55ccefdb2f4bbc59ede129fc4e/exp_code/1_benchmark/musubi-tuner/src/convert_json.py
- Command line
-
hf download hf://datasets/SuperCS/useful_code@aa8ee3caa0e01f55ccefdb2f4bbc59ede129fc4e/exp_code/1_benchmark/musubi-tuner/src/convert_json.py
-
curl -L -o convert_json.py https://huggingface.co/datasets/SuperCS/useful_code/resolve/aa8ee3caa0e01f55ccefdb2f4bbc59ede129fc4e/exp_code/1_benchmark/musubi-tuner/src/convert_json.py
1.12 kB
| import json | |
| def create_json_dataset(prompt_file, video_file, output_file): | |
| with open(prompt_file, 'r', encoding='utf-8') as f_prompt, \ | |
| open(video_file, 'r', encoding='utf-8') as f_video, \ | |
| open(output_file, 'w', encoding='utf-8') as f_out: | |
| for caption, video_path in zip(f_prompt, f_video): | |
| # 去除两端的空白字符和换行符 | |
| caption = caption.strip() | |
| video_path = video_path.strip() | |
| # 创建字典并转换为JSON字符串 | |
| data = { | |
| "video_path": video_path, | |
| "caption": caption | |
| } | |
| json_str = json.dumps(data) | |
| # 写入输出文件 | |
| f_out.write(json_str + '\n') | |
| # 使用示例 | |
| prompt_file = '/mnt/workspace/checkpoints/Wild-Heart/Disney-VideoGeneration-Dataset/prompt.txt' | |
| video_file = '/mnt/workspace/checkpoints/Wild-Heart/Disney-VideoGeneration-Dataset/videos.txt' | |
| output_file = 'caption_video.json' | |
| create_json_dataset(prompt_file, video_file, output_file) | |
| print(f"JSON文件已生成: {output_file}") |