path_config.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import os
  2. from pathlib import Path
  3. from typing import Union, Dict
  4. class PathConfig:
  5. """文件路径配置类"""
  6. def __init__(self, base_dir: Union[str, Path] = None):
  7. # 设置基础目录,默认为当前工作目录
  8. self.base_dir = Path(base_dir or os.getcwd())
  9. # 定义各类文件的相对路径
  10. self.paths = {
  11. 'audio_json': 'data/audio_json',
  12. 'output_filter_1': 'output/filter_1',
  13. 'output_filter_2': 'output/filter_2',
  14. 'output_filter_3': 'output/filter_3',
  15. 'output_filter_4': 'output/filter_4',
  16. 'frame_for_show': 'data/key_frame/for_show',
  17. 'caption_for_show': 'data/img_caption/for_show',
  18. 'aide_video': 'data/aide_video',
  19. 'sub_video': 'data/sub_video',
  20. 'exclude_word_json': 'config/exclude_word.json',
  21. 'include_word_json': 'config/include_word.json',
  22. 'Megrez-3B-Omni': '/data/data/luosy/models/Megrez-3B-Omni'
  23. }
  24. # 确保所有必要的目录存在
  25. self._ensure_directories()
  26. def _ensure_directories(self):
  27. """确保所有必要的目录存在"""
  28. for path_key, path in self.paths.items():
  29. full_path = self.base_dir / path
  30. if path.endswith('.json'):
  31. # 对于json文件,只创建其父目录
  32. full_path.parent.mkdir(parents=True, exist_ok=True)
  33. else:
  34. # 对于目录,直接创建
  35. full_path.mkdir(parents=True, exist_ok=True)
  36. def get_path(self, path_key: str) -> Path:
  37. """获取指定类型的完整路径"""
  38. if path_key not in self.paths:
  39. raise KeyError(f"未知的路径类型: {path_key}")
  40. return self.base_dir / self.paths[path_key]
  41. if __name__ == "__main__":
  42. # 创建全局路径配置实例
  43. path_config = PathConfig()
  44. audio_name = Path("data/raw_video/test_video.flv").stem + ".json"
  45. audio_path = path_config.get_path('audio_json') / audio_name
  46. print((audio_path))