Spaces:
Running
Running
jhj0517
commited on
Commit
·
388653c
1
Parent(s):
d85434f
Fix output path for translation
Browse files
modules/translation/deepl_api.py
CHANGED
|
@@ -145,13 +145,6 @@ class DeepLAPI:
|
|
| 145 |
|
| 146 |
subtitle = get_serialized_srt(parsed_dicts)
|
| 147 |
|
| 148 |
-
if add_timestamp:
|
| 149 |
-
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
| 150 |
-
file_name += f"-{timestamp}"
|
| 151 |
-
|
| 152 |
-
output_path = os.path.join(self.output_dir, "", f"{file_name}.srt")
|
| 153 |
-
write_file(subtitle, output_path)
|
| 154 |
-
|
| 155 |
elif file_ext == ".vtt":
|
| 156 |
parsed_dicts = parse_vtt(file_path=file_path)
|
| 157 |
|
|
@@ -167,24 +160,24 @@ class DeepLAPI:
|
|
| 167 |
|
| 168 |
subtitle = get_serialized_vtt(parsed_dicts)
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
files_info[file_name] = {"subtitle": subtitle, "path": output_path}
|
|
|
|
| 178 |
total_result = ''
|
| 179 |
-
result_file_path = []
|
| 180 |
for file_name, info in files_info.items():
|
| 181 |
total_result += '------------------------------------\n'
|
| 182 |
total_result += f'{file_name}\n\n'
|
| 183 |
total_result += f'{info["subtitle"]}'
|
| 184 |
-
result_file_path.append(info["path"])
|
| 185 |
-
|
| 186 |
gr_str = f"Done! Subtitle is in the outputs/translation folder.\n\n{total_result}"
|
| 187 |
-
|
|
|
|
|
|
|
| 188 |
|
| 189 |
def request_deepl_translate(self,
|
| 190 |
auth_key: str,
|
|
|
|
| 145 |
|
| 146 |
subtitle = get_serialized_srt(parsed_dicts)
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
elif file_ext == ".vtt":
|
| 149 |
parsed_dicts = parse_vtt(file_path=file_path)
|
| 150 |
|
|
|
|
| 160 |
|
| 161 |
subtitle = get_serialized_vtt(parsed_dicts)
|
| 162 |
|
| 163 |
+
if add_timestamp:
|
| 164 |
+
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
| 165 |
+
file_name += f"-{timestamp}"
|
| 166 |
|
| 167 |
+
output_path = os.path.join(self.output_dir, f"{file_name}{file_ext}")
|
| 168 |
+
write_file(subtitle, output_path)
|
| 169 |
|
| 170 |
files_info[file_name] = {"subtitle": subtitle, "path": output_path}
|
| 171 |
+
|
| 172 |
total_result = ''
|
|
|
|
| 173 |
for file_name, info in files_info.items():
|
| 174 |
total_result += '------------------------------------\n'
|
| 175 |
total_result += f'{file_name}\n\n'
|
| 176 |
total_result += f'{info["subtitle"]}'
|
|
|
|
|
|
|
| 177 |
gr_str = f"Done! Subtitle is in the outputs/translation folder.\n\n{total_result}"
|
| 178 |
+
|
| 179 |
+
output_file_paths = [item["path"] for key, item in files_info.items()]
|
| 180 |
+
return [gr_str, output_file_paths]
|
| 181 |
|
| 182 |
def request_deepl_translate(self,
|
| 183 |
auth_key: str,
|
modules/translation/translation_base.py
CHANGED
|
@@ -93,12 +93,6 @@ class TranslationBase(ABC):
|
|
| 93 |
dic["sentence"] = translated_text
|
| 94 |
subtitle = get_serialized_srt(parsed_dicts)
|
| 95 |
|
| 96 |
-
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
| 97 |
-
if add_timestamp:
|
| 98 |
-
output_path = os.path.join("outputs", "", f"{file_name}-{timestamp}.srt")
|
| 99 |
-
else:
|
| 100 |
-
output_path = os.path.join("outputs", "", f"{file_name}.srt")
|
| 101 |
-
|
| 102 |
elif file_ext == ".vtt":
|
| 103 |
parsed_dicts = parse_vtt(file_path=file_path)
|
| 104 |
total_progress = len(parsed_dicts)
|
|
@@ -108,23 +102,25 @@ class TranslationBase(ABC):
|
|
| 108 |
dic["sentence"] = translated_text
|
| 109 |
subtitle = get_serialized_vtt(parsed_dicts)
|
| 110 |
|
|
|
|
| 111 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
| 112 |
-
|
| 113 |
-
output_path = os.path.join(self.output_dir, "", f"{file_name}-{timestamp}.vtt")
|
| 114 |
-
else:
|
| 115 |
-
output_path = os.path.join(self.output_dir, "", f"{file_name}.vtt")
|
| 116 |
|
|
|
|
| 117 |
write_file(subtitle, output_path)
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
total_result = ''
|
| 121 |
-
for file_name,
|
| 122 |
total_result += '------------------------------------\n'
|
| 123 |
total_result += f'{file_name}\n\n'
|
| 124 |
-
total_result += f'{subtitle}'
|
| 125 |
-
|
| 126 |
gr_str = f"Done! Subtitle is in the outputs/translation folder.\n\n{total_result}"
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
| 128 |
except Exception as e:
|
| 129 |
print(f"Error: {str(e)}")
|
| 130 |
finally:
|
|
|
|
| 93 |
dic["sentence"] = translated_text
|
| 94 |
subtitle = get_serialized_srt(parsed_dicts)
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
elif file_ext == ".vtt":
|
| 97 |
parsed_dicts = parse_vtt(file_path=file_path)
|
| 98 |
total_progress = len(parsed_dicts)
|
|
|
|
| 102 |
dic["sentence"] = translated_text
|
| 103 |
subtitle = get_serialized_vtt(parsed_dicts)
|
| 104 |
|
| 105 |
+
if add_timestamp:
|
| 106 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
| 107 |
+
file_name += f"-{timestamp}"
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
output_path = os.path.join(self.output_dir, f"{file_name}{file_ext}")
|
| 110 |
write_file(subtitle, output_path)
|
| 111 |
+
|
| 112 |
+
files_info[file_name] = {"subtitle": subtitle, "path": output_path}
|
| 113 |
|
| 114 |
total_result = ''
|
| 115 |
+
for file_name, info in files_info.items():
|
| 116 |
total_result += '------------------------------------\n'
|
| 117 |
total_result += f'{file_name}\n\n'
|
| 118 |
+
total_result += f'{info["subtitle"]}'
|
|
|
|
| 119 |
gr_str = f"Done! Subtitle is in the outputs/translation folder.\n\n{total_result}"
|
| 120 |
+
|
| 121 |
+
output_file_paths = [item["path"] for key, item in files_info.items()]
|
| 122 |
+
return [gr_str, output_file_paths]
|
| 123 |
+
|
| 124 |
except Exception as e:
|
| 125 |
print(f"Error: {str(e)}")
|
| 126 |
finally:
|