Spaces:
Running
Running
jhj0517
commited on
Commit
·
f94a0c1
1
Parent(s):
495939d
refactor without type hint
Browse files- modules/whisper/whisper_base.py +44 -44
modules/whisper/whisper_base.py
CHANGED
|
@@ -130,7 +130,8 @@ class WhisperBase(ABC):
|
|
| 130 |
files,
|
| 131 |
file_format,
|
| 132 |
add_timestamp,
|
| 133 |
-
|
|
|
|
| 134 |
):
|
| 135 |
"""
|
| 136 |
Write subtitle file from Files
|
|
@@ -155,49 +156,48 @@ class WhisperBase(ABC):
|
|
| 155 |
result_file_path:
|
| 156 |
Output file path to return to gr.Files()
|
| 157 |
"""
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
# self.remove_input_files([file.name for file in files])
|
| 201 |
|
| 202 |
@spaces.GPU(duration=120)
|
| 203 |
def transcribe_mic(self,
|
|
|
|
| 130 |
files,
|
| 131 |
file_format,
|
| 132 |
add_timestamp,
|
| 133 |
+
*whisper_params,
|
| 134 |
+
progress=gr.Progress(),
|
| 135 |
):
|
| 136 |
"""
|
| 137 |
Write subtitle file from Files
|
|
|
|
| 156 |
result_file_path:
|
| 157 |
Output file path to return to gr.Files()
|
| 158 |
"""
|
| 159 |
+
try:
|
| 160 |
+
files_info = {}
|
| 161 |
+
for file in files:
|
| 162 |
+
print("run started: ")
|
| 163 |
+
transcribed_segments, time_for_task = self.run(
|
| 164 |
+
file.name,
|
| 165 |
+
progress,
|
| 166 |
+
*whisper_params,
|
| 167 |
+
)
|
| 168 |
+
print("run finished: ")
|
| 169 |
+
|
| 170 |
+
file_name, file_ext = os.path.splitext(os.path.basename(file.name))
|
| 171 |
+
file_name = safe_filename(file_name)
|
| 172 |
+
subtitle, file_path = self.generate_and_write_file(
|
| 173 |
+
file_name=file_name,
|
| 174 |
+
transcribed_segments=transcribed_segments,
|
| 175 |
+
add_timestamp=add_timestamp,
|
| 176 |
+
file_format=file_format,
|
| 177 |
+
output_dir=self.output_dir
|
| 178 |
+
)
|
| 179 |
+
print("generated sub finished: ")
|
| 180 |
+
files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path}
|
| 181 |
+
|
| 182 |
+
total_result = ''
|
| 183 |
+
total_time = 0
|
| 184 |
+
for file_name, info in files_info.items():
|
| 185 |
+
total_result += '------------------------------------\n'
|
| 186 |
+
total_result += f'{file_name}\n\n'
|
| 187 |
+
total_result += f'{info["subtitle"]}'
|
| 188 |
+
total_time += info["time_for_task"]
|
| 189 |
+
|
| 190 |
+
result_str = f"Done in {self.format_time(total_time)}! Subtitle is in the outputs folder.\n\n{total_result}"
|
| 191 |
+
result_file_path = [info['path'] for info in files_info.values()]
|
| 192 |
+
|
| 193 |
+
return [result_str, result_file_path]
|
| 194 |
+
|
| 195 |
+
except Exception as e:
|
| 196 |
+
print(f"Error transcribing file: {e}")
|
| 197 |
+
finally:
|
| 198 |
+
self.release_cuda_memory()
|
| 199 |
+
if not files:
|
| 200 |
+
self.remove_input_files([file.name for file in files])
|
|
|
|
| 201 |
|
| 202 |
@spaces.GPU(duration=120)
|
| 203 |
def transcribe_mic(self,
|