DWizard commited on
Commit
58d59c0
·
1 Parent(s): 446f373

split task_cfg and launch_info

Browse files

Former-commit-id: 8901366529d43d9ffb6c520b38f9689929234058

Files changed (2) hide show
  1. configs/task_config.yaml +1 -1
  2. src/task.py +12 -9
configs/task_config.yaml CHANGED
@@ -6,5 +6,5 @@ output_type:
6
  video: False
7
  bilingal: False
8
  source_lang: EN
9
- target_lang: CN
10
  field: SC2
 
6
  video: False
7
  bilingal: False
8
  source_lang: EN
9
+ target_lang: ZH
10
  field: SC2
src/task.py CHANGED
@@ -64,15 +64,18 @@ class Task:
64
  with self.__status_lock:
65
  self.__status = new_status
66
 
67
- def __init__(self, task_id, task_local_dir, launch_info):
68
  self.__status_lock = threading.Lock()
69
  self.__status = TaskStatus.CREATED
70
  openai.api_key = getenv("OPENAI_API_KEY")
71
- self.launch_info = launch_info
72
  self.task_local_dir = task_local_dir
73
- self.model = launch_info["model"]
74
  self.gpu_status = 0
75
- self.output_type = launch_info["output_type"]
 
 
 
76
  self.task_id = task_id
77
  self.progress = NotImplemented
78
  self.SRT_Script = None
@@ -80,11 +83,11 @@ class Task:
80
 
81
 
82
  @staticmethod
83
- def fromYoutubeLink(youtube_url, task_id, launch_info):
84
  # convert to audio
85
  logging.info("Task Creation method: Youtube Link")
86
  local_dump = Path(launch_info['local_dump']) # should get from launch config
87
- return YoutubeTask(task_id, local_dump.joinpath(f"task_{task_id}"), launch_info, youtube_url)
88
 
89
  @staticmethod
90
  def fromAudioFile():
@@ -114,7 +117,7 @@ class Task:
114
  processed_srt_path_en = str(Path(self.task_local_dir).with_suffix('')) + '_processed.srt'
115
  self.SRT_Script.write_srt_file_src(processed_srt_path_en)
116
 
117
- if self.output_type == "ass":
118
  logging.info("write English .srt file to .ass")
119
  assSub_en = srt2ass(processed_srt_path_en)
120
  logging.info('ASS subtitle saved as: ' + assSub_en)
@@ -151,8 +154,8 @@ class Task:
151
  self.result = self.output_render()
152
 
153
  class YoutubeTask(Task):
154
- def __init__(self, task_id, task_local_dir, launch_info, youtube_url):
155
- super().__init__(task_id, task_local_dir, launch_info)
156
  self.youtube_url = youtube_url
157
 
158
  def run(self):
 
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
 
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():
 
117
  processed_srt_path_en = str(Path(self.task_local_dir).with_suffix('')) + '_processed.srt'
118
  self.SRT_Script.write_srt_file_src(processed_srt_path_en)
119
 
120
+ if self.output_type["subtitle"] == "ass":
121
  logging.info("write English .srt file to .ass")
122
  assSub_en = srt2ass(processed_srt_path_en)
123
  logging.info('ASS subtitle saved as: ' + assSub_en)
 
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):