jhj0517 commited on
Commit
c573a1a
·
1 Parent(s): 5633565

add output_dir

Browse files
modules/deepl_api.py CHANGED
@@ -82,11 +82,14 @@ DEEPL_AVAILABLE_SOURCE_LANGS = {
82
 
83
 
84
  class DeepLAPI:
85
- def __init__(self):
 
 
86
  self.api_interval = 1
87
  self.max_text_batch_size = 50
88
  self.available_target_langs = DEEPL_AVAILABLE_TARGET_LANGS
89
  self.available_source_langs = DEEPL_AVAILABLE_SOURCE_LANGS
 
90
 
91
  def translate_deepl(self,
92
  auth_key: str,
@@ -111,6 +114,7 @@ class DeepLAPI:
111
  Boolean value that is about pro user or not from gr.Checkbox().
112
  progress: gr.Progress
113
  Indicator to show progress directly in gradio.
 
114
  Returns
115
  ----------
116
  A List of
@@ -140,7 +144,7 @@ class DeepLAPI:
140
  timestamp = datetime.now().strftime("%m%d%H%M%S")
141
 
142
  file_name = file_name[:-9]
143
- output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}.srt")
144
  write_file(subtitle, output_path)
145
 
146
  elif file_ext == ".vtt":
@@ -160,7 +164,7 @@ class DeepLAPI:
160
  timestamp = datetime.now().strftime("%m%d%H%M%S")
161
 
162
  file_name = file_name[:-9]
163
- output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}.vtt")
164
 
165
  write_file(subtitle, output_path)
166
 
 
82
 
83
 
84
  class DeepLAPI:
85
+ def __init__(self,
86
+ output_dir: str
87
+ ):
88
  self.api_interval = 1
89
  self.max_text_batch_size = 50
90
  self.available_target_langs = DEEPL_AVAILABLE_TARGET_LANGS
91
  self.available_source_langs = DEEPL_AVAILABLE_SOURCE_LANGS
92
+ self.output_dir = output_dir
93
 
94
  def translate_deepl(self,
95
  auth_key: str,
 
114
  Boolean value that is about pro user or not from gr.Checkbox().
115
  progress: gr.Progress
116
  Indicator to show progress directly in gradio.
117
+
118
  Returns
119
  ----------
120
  A List of
 
144
  timestamp = datetime.now().strftime("%m%d%H%M%S")
145
 
146
  file_name = file_name[:-9]
147
+ output_path = os.path.join(self.output_dir, "translations", f"{file_name}-{timestamp}.srt")
148
  write_file(subtitle, output_path)
149
 
150
  elif file_ext == ".vtt":
 
164
  timestamp = datetime.now().strftime("%m%d%H%M%S")
165
 
166
  file_name = file_name[:-9]
167
+ output_path = os.path.join(self.output_dir, "translations", f"{file_name}-{timestamp}.vtt")
168
 
169
  write_file(subtitle, output_path)
170
 
modules/nllb_inference.py CHANGED
@@ -6,9 +6,13 @@ from modules.translation_base import TranslationBase
6
 
7
 
8
  class NLLBInference(TranslationBase):
9
- def __init__(self):
 
 
 
10
  super().__init__(
11
- model_dir=os.path.join("models", "NLLB")
 
12
  )
13
  self.tokenizer = None
14
  self.available_models = ["facebook/nllb-200-3.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-distilled-600M"]
 
6
 
7
 
8
  class NLLBInference(TranslationBase):
9
+ def __init__(self,
10
+ model_dir: str,
11
+ output_dir: str
12
+ ):
13
  super().__init__(
14
+ model_dir=model_dir,
15
+ output_dir=output_dir
16
  )
17
  self.tokenizer = None
18
  self.available_models = ["facebook/nllb-200-3.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-distilled-600M"]
modules/translation_base.py CHANGED
@@ -11,11 +11,14 @@ from modules.subtitle_manager import *
11
 
12
  class TranslationBase(ABC):
13
  def __init__(self,
14
- model_dir: str):
 
15
  super().__init__()
16
  self.model = None
17
  self.model_dir = model_dir
 
18
  os.makedirs(self.model_dir, exist_ok=True)
 
19
  self.current_model_size = None
20
  self.device = self.get_device()
21
 
@@ -102,9 +105,9 @@ class TranslationBase(ABC):
102
 
103
  timestamp = datetime.now().strftime("%m%d%H%M%S")
104
  if add_timestamp:
105
- output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}")
106
  else:
107
- output_path = os.path.join("outputs", "translations", f"{file_name}.vtt")
108
 
109
  write_file(subtitle, output_path)
110
  files_info[file_name] = subtitle
 
11
 
12
  class TranslationBase(ABC):
13
  def __init__(self,
14
+ model_dir: str,
15
+ output_dir: str):
16
  super().__init__()
17
  self.model = None
18
  self.model_dir = model_dir
19
+ self.output_dir = output_dir
20
  os.makedirs(self.model_dir, exist_ok=True)
21
+ os.makedirs(self.output_dir, exist_ok=True)
22
  self.current_model_size = None
23
  self.device = self.get_device()
24
 
 
105
 
106
  timestamp = datetime.now().strftime("%m%d%H%M%S")
107
  if add_timestamp:
108
+ output_path = os.path.join(self.output_dir, "translations", f"{file_name}-{timestamp}")
109
  else:
110
+ output_path = os.path.join(self.output_dir, "translations", f"{file_name}.vtt")
111
 
112
  write_file(subtitle, output_path)
113
  files_info[file_name] = subtitle