DeeeeeeM commited on
Commit
5899607
·
1 Parent(s): 77b6231

added fixes for srt output

Browse files
Files changed (2) hide show
  1. .gitignore +2 -1
  2. app.py +8 -2
.gitignore CHANGED
@@ -1 +1,2 @@
1
- .gradio/
 
 
1
+ .gradio/
2
+ .vscode/
app.py CHANGED
@@ -25,12 +25,12 @@ def process_media(
25
  if model_type == "faster whisper":
26
  device = "cuda" if torch.cuda.is_available() else "cpu"
27
  model = stable_whisper.load_faster_whisper(model_size, device=device)
28
- result = model.transcribe(temp_path, language=source_lang, vad=True, regroup=False, no_speech_threshold=0.9, denoiser="demucs")
29
  else:
30
  device = "cuda" if torch.cuda.is_available() else "cpu"
31
  model = stable_whisper.load_model(model_size, device=device)
32
  result = model.transcribe(temp_path, language=source_lang, vad=True, regroup=False, no_speech_threshold=0.9, denoiser="demucs")
33
- #, batch_size=16
34
  #result.save_as_json(word_transcription_path)
35
 
36
  # ADVANCED SETTINGS #
@@ -131,6 +131,12 @@ def optimize_text(text, max_lines_per_segment, line_penalty, longest_line_char_p
131
 
132
  backtrack(0, 0, 0, [])
133
 
 
 
 
 
 
 
134
  optimized = '\n'.join(' '.join(words) for words in bestSplit)
135
  return optimized
136
 
 
25
  if model_type == "faster whisper":
26
  device = "cuda" if torch.cuda.is_available() else "cpu"
27
  model = stable_whisper.load_faster_whisper(model_size, device=device)
28
+ result = model.transcribe(temp_path, language=source_lang, vad=True, regroup=False,no_speech_threshold=0.9)
29
  else:
30
  device = "cuda" if torch.cuda.is_available() else "cpu"
31
  model = stable_whisper.load_model(model_size, device=device)
32
  result = model.transcribe(temp_path, language=source_lang, vad=True, regroup=False, no_speech_threshold=0.9, denoiser="demucs")
33
+ #, batch_size=16, denoiser="demucs"
34
  #result.save_as_json(word_transcription_path)
35
 
36
  # ADVANCED SETTINGS #
 
131
 
132
  backtrack(0, 0, 0, [])
133
 
134
+ if not bestSplit:
135
+ return text
136
+
137
+ if len(bestSplit) > max_lines_per_segment or any(len(line) == 1 for line in bestSplit):
138
+ return text
139
+
140
  optimized = '\n'.join(' '.join(words) for words in bestSplit)
141
  return optimized
142