DWizard commited on
Commit
d581753
·
1 Parent(s): 7d9d086

finish todo in run.py refine task.py

Browse files

Former-commit-id: 2dc2a4f9cfea11c7457cb8a6e4a64487ec64fd0c

Files changed (2) hide show
  1. entries/run.py +4 -4
  2. src/task.py +14 -13
entries/run.py CHANGED
@@ -18,7 +18,7 @@ def parse_args():
18
  parser.add_argument("--srt_file", help="srt file input path here", default=None, type=str, required=False)
19
  parser.add_argument("--continue", help="task_id that need to continue", default=None, type=str, required=False) # need implement
20
  parser.add_argument("--launch_cfg", help="launch config path", default='./configs/local_launch.yaml', type=str, required=False)
21
- # task config
22
  args = parser.parse_args()
23
 
24
  return args
@@ -27,7 +27,7 @@ if __name__ == "__main__":
27
  # read args and configs
28
  args = parse_args()
29
  launch_cfg = load(open(args.launch_cfg), Loader=Loader)
30
- # TODO: task config
31
 
32
  # initialize dir
33
  local_dir = Path(launch_cfg['local_dump'])
@@ -49,12 +49,12 @@ if __name__ == "__main__":
49
  "{}/{}_{}.log".format(task_dir, f"task_{task_id}", datetime.now().strftime("%m%d%Y_%H%M%S")),
50
  'w', encoding='utf-8')])
51
 
52
- # TODO: write task info into log
53
 
54
  # Task create
55
  if args.link is not None:
56
  try:
57
- task = Task.fromYoutubeLink(args.link, task_id, launch_cfg)
58
  except:
59
  shutil.rmtree(task_dir)
60
  raise RuntimeError("failed to create task from youtube link")
 
18
  parser.add_argument("--srt_file", help="srt file input path here", default=None, type=str, required=False)
19
  parser.add_argument("--continue", help="task_id that need to continue", default=None, type=str, required=False) # need implement
20
  parser.add_argument("--launch_cfg", help="launch config path", default='./configs/local_launch.yaml', type=str, required=False)
21
+ parser.add_argument("--task_cfg", help="task config path", default='./config/task_config.yaml', type=str, required=False)
22
  args = parser.parse_args()
23
 
24
  return args
 
27
  # read args and configs
28
  args = parse_args()
29
  launch_cfg = load(open(args.launch_cfg), Loader=Loader)
30
+ task_cfg = load(open(args.task_cfg), Loader=Loader)
31
 
32
  # initialize dir
33
  local_dir = Path(launch_cfg['local_dump'])
 
49
  "{}/{}_{}.log".format(task_dir, f"task_{task_id}", datetime.now().strftime("%m%d%Y_%H%M%S")),
50
  'w', encoding='utf-8')])
51
 
52
+
53
 
54
  # Task create
55
  if args.link is not None:
56
  try:
57
+ task = Task.fromYoutubeLink(args.link, task_id, task_dir, task_cfg)
58
  except:
59
  shutil.rmtree(task_dir)
60
  raise RuntimeError("failed to create task from youtube link")
src/task.py CHANGED
@@ -64,30 +64,30 @@ class Task:
64
  with self.__status_lock:
65
  self.__status = new_status
66
 
67
- def __init__(self, task_id, task_local_dir, task_config):
68
  self.__status_lock = threading.Lock()
69
  self.__status = TaskStatus.CREATED
70
  openai.api_key = getenv("OPENAI_API_KEY")
71
- self.launch_info = task_config # do not use, just for fallback
72
  self.task_local_dir = task_local_dir
73
- self.model = task_config["model"]
74
  self.gpu_status = 0
75
- self.output_type = task_config["output_type"]
76
- self.target_lang = task_config["target_lang"]
77
- self.source_lang = task_config["source_lang"]
78
- self.field = task_config["field"]
79
  self.task_id = task_id
80
  self.progress = NotImplemented
81
  self.SRT_Script = None
82
  self.result = None
 
83
 
84
 
85
  @staticmethod
86
- def fromYoutubeLink(youtube_url, task_id, launch_info, task_config):
87
  # convert to audio
88
  logging.info("Task Creation method: Youtube Link")
89
- local_dump = Path(launch_info['local_dump']) # should get from launch config
90
- return YoutubeTask(task_id, local_dump.joinpath(f"task_{task_id}"), task_config, youtube_url)
91
 
92
  @staticmethod
93
  def fromAudioFile():
@@ -107,7 +107,8 @@ class Task:
107
  time.sleep(5)
108
  pass
109
 
110
- # Module 2: SRT preprocess: perform preprocess steps
 
111
  def preprocess(self):
112
  self.status = TaskStatus.PRE_PROCESSING
113
  logging.info("--------------------Start Preprocessing SRT class--------------------")
@@ -154,8 +155,8 @@ class Task:
154
  self.result = self.output_render()
155
 
156
  class YoutubeTask(Task):
157
- def __init__(self, task_id, task_local_dir, task_config, youtube_url):
158
- super().__init__(task_id, task_local_dir, task_config)
159
  self.youtube_url = youtube_url
160
 
161
  def run(self):
 
64
  with self.__status_lock:
65
  self.__status = new_status
66
 
67
+ def __init__(self, task_id, task_local_dir, task_cfg):
68
  self.__status_lock = threading.Lock()
69
  self.__status = TaskStatus.CREATED
70
  openai.api_key = getenv("OPENAI_API_KEY")
71
+ self.launch_info = task_cfg # do not use, just for fallback
72
  self.task_local_dir = task_local_dir
73
+ self.model = task_cfg["model"]
74
  self.gpu_status = 0
75
+ self.output_type = task_cfg["output_type"]
76
+ self.target_lang = task_cfg["target_lang"]
77
+ self.source_lang = task_cfg["source_lang"]
78
+ self.field = task_cfg["field"]
79
  self.task_id = task_id
80
  self.progress = NotImplemented
81
  self.SRT_Script = None
82
  self.result = None
83
+ logging.info(f"{self.source_lang} -> {self.target_lang} task in {self.field}\n Model: \t{self.model}\n subtitle_type: \t{self.output_type['subtitle']}\n video_ouput: \t{self.output_type['video']}\n bilingal_ouput: \t{self.output_type['bilingal']}")
84
 
85
 
86
  @staticmethod
87
+ def fromYoutubeLink(youtube_url, task_id, task_dir, task_cfg):
88
  # convert to audio
89
  logging.info("Task Creation method: Youtube Link")
90
+ return YoutubeTask(task_id, task_dir, task_cfg, youtube_url)
 
91
 
92
  @staticmethod
93
  def fromAudioFile():
 
107
  time.sleep(5)
108
  pass
109
 
110
+ # Module 2: SRT preprocess: perform preprocess steps
111
+ # TODO: multi-lang and multi-field support according to task_cfg
112
  def preprocess(self):
113
  self.status = TaskStatus.PRE_PROCESSING
114
  logging.info("--------------------Start Preprocessing SRT class--------------------")
 
155
  self.result = self.output_render()
156
 
157
  class YoutubeTask(Task):
158
+ def __init__(self, task_id, task_local_dir, task_cfg, youtube_url):
159
+ super().__init__(task_id, task_local_dir, task_cfg)
160
  self.youtube_url = youtube_url
161
 
162
  def run(self):